Skip to content

Instantly share code, notes, and snippets.

@selcukusta
Created January 20, 2018 22:57
Show Gist options
  • Select an option

  • Save selcukusta/6c5fb9820824c52ed169be5d0e827b0a to your computer and use it in GitHub Desktop.

Select an option

Save selcukusta/6c5fb9820824c52ed169be5d0e827b0a to your computer and use it in GitHub Desktop.
public static class MessagingFunction
{
[FunctionName("MessagingFunction")]
public static async Task<object> Run([HttpTrigger(WebHookType = "")]HttpRequestMessage req, TraceWriter log)
{
string jsonContent = await req.Content.ReadAsStringAsync();
var payload = PayloadHelper.GetPayload(WebUtility.UrlDecode(jsonContent));
if (string.IsNullOrWhiteSpace(payload))
{
return req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Invalid payload format" });
}
var payloadObject = JObject.Parse(payload);
var selectedValue = payloadObject["actions"][0].Value<bool>("value");
var userName = payloadObject.SelectToken("user.name").Value<string>();
RedisCacheProvider cacheProvider = new RedisCacheProvider();
var currentLunch = cacheProvider.Get<IList<LunchMember>>("lunch", () => { return new List<LunchMember>(); });
currentLunch.Add(new LunchMember { Name = userName, IsAccepted = selectedValue });
cacheProvider.Set<IList<LunchMember>>("lunch", currentLunch);
return req.CreateResponse(HttpStatusCode.OK, new
{
text = selectedValue ? ":yum: *Ağzının tadını biliyorsun!*" : ":weary: *E ne yapalım, bir sonraki sefere artık!*"
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment