Esempio n. 1
0
        /// <summary>
        /// Handles interactive messages. Used for button presses on previews.
        /// </summary>
        /// <param name="interactiveMessage"></param>
        /// <returns></returns>
        public async Task HandleInteractive(InteractiveMessage interactiveMessage)
        {
            if (Slack.ValidInteractiveMessage(interactiveMessage))
            {
                var action = interactiveMessage.Actions[0];

                var slackUser = await Slack.GetUser(interactiveMessage.User.Id);

                if (action.Name == "post")
                {
                    await Slack.PostMessage(new ChatMessage
                    {
                        Channel  = interactiveMessage.Channel.Id,
                        Username = slackUser.Profile.DisplayName,
                        Text     = action.Value,
                        IconUrl  = slackUser.Profile.ImageOriginal,
                        User     = interactiveMessage.User.Id,
                    });
                }
                else if (action.Name == "random")
                {
                    var url = await ImageSearch(action.Value, true);
                    await SendGif(interactiveMessage.Channel.Id,
                                  slackUser.Profile.DisplayName,
                                  slackUser.Profile.ImageOriginal,
                                  slackUser.Id,
                                  action.Value,
                                  url);
                }

                await Slack.DeleteResponse(interactiveMessage.ResponseUrl.ToString());
            }
        }