Exemple #1
0
        private async Task React(BotReaction reaction, ResponseContext context)
        {
            string chatHubID = null;

            if (reaction == null)
            {
                return;
            }

            if (reaction.ChatHub != null)
            {
                chatHubID = reaction.ChatHub.ID;
            }
            else if (context != null && context.Message.ChatHub != null)
            {
                chatHubID = context.Message.ChatHub.ID;
            }

            if (chatHubID == null)
            {
                throw new ArgumentException($"When calling the {nameof(Say)}() method, the {nameof(reaction)} parameter must have its {nameof(reaction.ChatHub)} property set.");
            }

            var client = new NoobWebClient();
            var values = new List <string>()
            {
                "token", SlackKey,
                "channel", chatHubID,
                "name", reaction.Name,
                "timestamp", reaction.Timestamp,
                "file_comment", reaction.File_Comment,
                "file", reaction.File
            };

            foreach (KeyValuePair <string, string> kv in reaction.Custom_Attibs)
            {
                values.Add(kv.Key);
                values.Add(kv.Value);
            }
            /** END CUSTOM ATTRIBS *************************************************/

            await client.DownloadString(
                "https://slack.com/api/reactions.add",
                RequestMethod.Post,
                values.ToArray()
                );
        }
Exemple #2
0
 /// <summary>
 /// Allows you to programmatically operate the bot. The bot will post the passed reaction in whichever "chat hub" (DM, channel, or group) the message specifies.
 /// </summary>
 /// <param name="message">The reaction you want the bot to post in Slack.</param>
 public async Task React(BotReaction reaction)
 {
     await React(reaction, null);
 }