Created
January 20, 2018 22:57
-
-
Save selcukusta/6c5fb9820824c52ed169be5d0e827b0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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