public static void SlackSend(string message, bool simonOnly = false)
        {
            // credentials
            string _channel;
            string _token;

            if (simonOnly)
            {
                _channel = SlackCredentials.ChannelSimon;
                _token   = SlackCredentials.TokenSimonLegacy;
            }
            else
            {
                _channel = SlackCredentials.ChannelTiffinTime;
                _token   = SlackCredentials.TokenLocalMenuApp;
            }

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

            if (!response.Ok)
            {
                throw new ArgumentException($"Slack error: {response.Error}");
            }
        }
示例#2
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            SlackClientAPI client = new SlackClientAPI();

            Arguments p = new Arguments();

            p.Channel     = txtChannel.Text;
            p.As_User     = chkAsUser.Checked ? "true" : "false";
            p.Username    = txtUsername.Text;
            p.Text        = txtData.Text;
            p.Token       = txtToken.Text;
            p.UnfurlLinks = chkUnfurlLinks.Checked ? "true" : "false";
            p.UnfurlMedia = chkUnfurlMedia.Checked ? "true" : "false";
            if (IsValidUri(txtIcon.Text, false))
            {
                p.IconUrl = txtIcon.Text;
                this.Icon = GetIconFromUrl(txtIcon.Text);
            }

            //Attachment a = new Attachment();
            //a.Fallback = "some text";
            //a.Pretext = "some other text";
            //a.Color = "danger";

            //AttachmentFields af = new AttachmentFields();
            //af.Title = "Field 1";
            //af.Value = "Value 1";
            //af.Short = true;
            //a.Fields.Add(af);

            //AttachmentFields af2 = new AttachmentFields();
            //af2.Title = "Field 2";
            //af2.Value = "Value 2";
            //af2.Short = true;
            //a.Fields.Add(af2);

            //p.Attachments.Add(a);

            Response r = client.PostMessage(p);

            if (!r.Ok)
            {
                txtResponse.Text = r.Error;
            }
            else
            {
                txtResponse.Text = "ok";
            }
        }
示例#3
0
        private static void SlackWriteMessage(string message)
        {
            var client = new SlackClientAPI();
            var token  = ConfigurationManager.AppSettings.Get("SlackApiToken");

            // Slack message formatting here: https://api.slack.com/docs/message-formatting
            // Example: argument parse: full or none
            var p = new Arguments
            {
                Channel  = ConfigurationManager.AppSettings.Get("SlackChannel"),
                Username = ConfigurationManager.AppSettings.Get("SlackUsername"),
                Text     = message,
                Token    = token,
                Parse    = "none"
            };

            var r = client.PostMessage(p);

            if (!r.Ok)
            {
                Console.Write("Error: {0}", r.Error);
                //Console.Read();
            }
        }