Beispiel #1
0
        public void Post([FromBody] JToken body)
        {
            try
            {
                _writer.Write(body.ToString());

                Rootobject obj = JsonConvert.DeserializeObject <Rootobject>(body.ToString());

                if (!IsNullOrEmpty(obj.entry))
                {
                    var entry = obj.entry[0];
                    if (!IsNullOrEmpty(entry.messaging))
                    {
                        var messaging = entry.messaging[0];

                        if (messaging.message != null)
                        {
                            foreach (var attachment in messaging.message.attachments)
                            {
                                if (attachment.type == "image")
                                {
                                    _photosAwaitingCategorization.Add(messaging.sender.id, attachment.payload.url);

                                    SendMessageToUser(messaging.sender.id, "Is that an image of a meal, or your stool?");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Unknown error occurred in WebHook!", ex);
            }
        }
Beispiel #2
0
        public string Post([FromBody] JToken body)
        {
            try
            {
                if (body["challenge"] != null)
                {
                    return(body["challenge"].ToString());
                }

                var pp = JsonConvert.SerializeObject(body, Formatting.Indented,
                                                     new JsonConverter[] { new StringEnumConverter() });
                _writer.Write(pp);

                var root = JsonConvert.DeserializeObject <App.SlackEntities.Rootobject>(body.ToString());
                if (root.type == "event_callback" && root._event?.type == "message")
                {
                    var e = root._event;
                    _dialogManager.HandleMessage("slack", e.username, e.text, (response) => {
                        SendMessage(root.token, e.channel, response);
                    }, e.file?.permalink);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Unknown error occurred in WebHook!", ex);
            }

            return(string.Empty);
        }
Beispiel #3
0
 public void Post([FromBody] object value)
 {
     Writer.Write(value.ToString());
 }