Example #1
0
        public static void SendResultsToChannel(string meatOption, string vegOption, string imageUrl)
        {
            Credentials cred     = new Credentials();
            string      _channel = cred.channel;
            string      _token   = cred.token;

            // constuct message format
            AttachmentFields afMeat = new AttachmentFields()
            {
                Title = "Meat",
                Value = meatOption
            };
            AttachmentFields afVeg = new AttachmentFields()
            {
                Title = "Veggie",
                Value = vegOption
            };
            Attachment a = new Attachment()
            {
                Pretext  = "This week's menu:",
                Fallback = $"TiffinTime menu this week: Meaty - {meatOption}. Veggie - {vegOption}.",
                Fields   = { afMeat, afVeg },
                ImageUrl = "https:" + imageUrl,
                Footer   = "Vote below!"
            };
            Arguments p = new Arguments()
            {
                Channel     = _channel,
                Attachments = { a }
            };

            // send
            var slack    = new SlackClientAPI(_token);
            var response = slack.PostMessage("chat.postMessage", p);

            // send reactions (for voting)
            if (response.Ok)
            {
                slack.PostMessage("reactions.add", new Arguments()
                {
                    Name      = "cut_of_meat",
                    Channel   = _channel,
                    Timestamp = response.TimeStamp
                });

                slack.PostMessage("reactions.add", new Arguments()
                {
                    Name      = "green_salad",
                    Channel   = _channel,
                    Timestamp = response.TimeStamp
                });
            }
        }
Example #2
0
        public static void SendErrorToSimonOnly(string message)
        {
            Credentials cred     = new Credentials(dmSimonOnly: true);
            string      _channel = cred.channel;
            string      _token   = cred.token;

            // send
            var slack    = new SlackClientAPI(_token);
            var response = slack.PostMessage("chat.postMessage", new Arguments()
            {
                Channel = _channel,
                Text    = message
            });
        }