示例#1
0
        public void Pingbot_Alert_Website_Up_Example()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message
            {
                Username    = "******",
                IconUrl     = "https://a.slack-edge.com/7f1a0/plugins/pingdom/assets/service_36.png",
                Attachments = new List <Attachment>
                {
                    new Attachment
                    {
                        Color    = "good",
                        Fallback = "Google is up (Incident #12345)",
                        Fields   = new List <Field>
                        {
                            new Field
                            {
                                Title = "Google is up (Incident #12345)",
                                Value =
                                    "<https://google.com> • <https://my.pingbot.com/reports/responsetime#check=12345|View details>"
                            }
                        }
                    }
                }
            };

            var response = client.Send(message);

            Assert.AreEqual("ok", response.Result);
        }
示例#2
0
        public async Task GetStanLee(SlackCommandRequest slackCommandRequest)
        {
            var client  = new SbmClient(slackCommandRequest.ResponseUrl);
            var message = new Message
            {
                UnfurlLinks = false,
                UnfurlMedia = false,
                Text        = slackCommandRequest.Text switch
                {
                    "help" => BuildHelpText(slackCommandRequest.UserName),
                    "support" => "Sure, if you want to reach out go to https://stanleebot.com/Support",
                    _ => "Unfortunately, I only know how to respond to help and support right now."
                }
            };

            message.SetResponseType(ResponseType.Ephemeral);
            var response = await client.SendAsync(message).ConfigureAwait(false);

            if (response == "ok")
            {
                _logger.LogInformation("GetStanLee: Responded to {MessageText} and sent message {@Message}", slackCommandRequest.Text, message);
            }
            else
            {
                _logger.LogError("GetStanLee: Tried responding to {MessageText} but received an error sending {@Message}", slackCommandRequest.Text, message);
            }
        }
示例#3
0
        public async Task Pingbot_Alert_Website_Down_Example_Async()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message
            {
                Username    = "******",
                IconUrl     = "https://a.slack-edge.com/7f1a0/plugins/pingdom/assets/service_36.png",
                Attachments = new List <Attachment>
                {
                    new Attachment
                    {
                        Color    = "danger",
                        Fallback = "Google is down (Incident #12345)",
                        Fields   = new List <Field>
                        {
                            new Field
                            {
                                Title = "Google is down (Incident #12345)",
                                Value =
                                    "<https://google.com> • <https://my.pingbot.com/reports/responsetime#check=12345|View details>"
                            }
                        }
                    }
                }
            };

            var response = await client.SendAsync(message).ConfigureAwait(false);

            Assert.AreEqual("ok", response);
        }
示例#4
0
        public static void SendMessage(GithubPullRequestReview pr)
        {
            var    WebHookUrl = Consts.SLACK_HOOK_URL;
            var    client     = new SbmClient(WebHookUrl);
            var    message    = new Message($"<!here> {pr.Sender.Login} {pr.Action} a Pull request on {pr.Repository.Name}");
            string color;

            switch (pr.Action)
            {
            case PullRequestAction.Closed:
                color = Consts.GREEN;
                break;

            case PullRequestAction.Edited:
                color = Consts.ORANGE;
                break;

            default:
                color = Consts.YELLOW;
                break;
            }

            message.AddAttachment(new Attachment()

                                  .AddField("Pull request info", $"<{pr.PullRequest.HtmlUrl}|{pr.PullRequest.Title} (#{pr.Number})>")
                                  .AddField("Description", pr.PullRequest.Body)
                                  .AddField("Commits", pr.PullRequest.Commits.ToString(), true)
                                  .AddField("Changed files", pr.PullRequest.ChangedFiles.ToString(), true)
                                  .AddField("User", $"<{pr.Sender.HtmlUrl.ToString()}|{pr.Sender.Login}>", true)
                                  .SetThumbUrl(pr.PullRequest.User.AvatarUrl.ToString())
                                  .SetColor(color)
                                  );

            client.Send(message);
        }
示例#5
0
        public void Initialize()
        {
            try
            {
                var client = new SbmClient(WebConfigurationManager.AppSettings["SlackBotMessagesWebHookUrl"]);

                var message = new Message
                {
                    Username    = "******",
                    IconEmoji   = ":robot_face:",
                    Attachments = new System.Collections.Generic.List <Attachment>
                    {
                        new Attachment
                        {
                            Fallback = "Umbraco Essential started",
                            Color    = "good",
                            Fields   = new System.Collections.Generic.List <Field>
                            {
                                new Field
                                {
                                    Value = "Umbraco Essential started"
                                }
                            }
                        }
                    }
                };

                client.Send(message);
            }
            catch (Exception ex)
            {
                Current.Logger.Error(typeof(ApplicationComponent), ex, "Unable to send Slack message");
                throw ex;
            }
        }
示例#6
0
        public void Initialize()
        {
            try
            {
                var client = new SbmClient(WebConfigurationManager.AppSettings["SlackBotMessagesWebHookUrl"]);

                var message = new Message
                {
                    Username    = "******",
                    IconEmoji   = ":robot_face:",
                    Attachments = new List <Attachment>()
                    {
                        new Attachment()
                        {
                            Fallback = "Clean Blog Website Started",
                            Color    = "good",
                            Fields   = new List <Field>()
                            {
                                new Field()
                                {
                                    Value = "Clean Blog Website Started"
                                }
                            }
                        }
                    }
                };

                client.Send(message);
            }
            catch (Exception ex)
            {
                Current.Logger.Error(typeof(ApplicationComponent), ex, "Unable to send slack message to notify site starting up.");
            }
        }
 public void sendTopic(SlackMessageModel messageObj)
 {
     if (string.IsNullOrEmpty(messageObj.channel))
     {
         messageObj.channel = this.slackChannel;
     }
     try
     {
         SbmClient  mclient    = new SbmClient(messageObj.channel);
         Message    objMessage = new Message(messageObj.title);
         Attachment attachment = new Attachment()
         {
             Color = messageObj.color
         };
         messageObj.attachments.ForEach(item => {
             attachment.AddField(item.itemTitle, item.itemValue, item.isShort);
         });
         objMessage.AddAttachment(attachment);
         mclient.Send(objMessage);
     }
     catch (Exception e)
     {
         logger.Error(e.Message);
         logger.Trace(e.StackTrace);
         throw;
     }
 }
示例#8
0
        public async Task Notification_To_Everyone_Async()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message("<!everyone> this is cool");

            var response = await client.SendAsync(message).ConfigureAwait(false);

            Assert.AreEqual("ok", response);
        }
示例#9
0
        public void Notification_To_Everyone()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message("<!everyone> this is cool");

            var response = client.Send(message);

            Assert.AreEqual("ok", response.Result);
        }
示例#10
0
        private void btn_s(object sender, EventArgs e)
        {
            var client = new SbmClient("https://hooks.slack.com/services/xxxxxxxxxxxxx/xxxxxxxxxx/xxxxxxxxxxxxxx");

            SlackBotMessages.Models.Message p = new SlackBotMessages.Models.Message(tx.Text);
            p.Username  = "******";
            p.Channel   = "random";
            p.IconEmoji = ":eggplant:";
            client.Send(p);
        }
示例#11
0
        public async Task GetMarvel(SlackCommandRequest slackCommandRequest)
        {
            var marvelGoogleCx = _appSettings.GoogleCustomSearch.MarvelCx;
            var gsr            = await _googleSearchService.GetResponse(slackCommandRequest.Text, marvelGoogleCx);

            if (gsr != null)
            {
                var client  = new SbmClient(slackCommandRequest.ResponseUrl);
                var message = new Message();

                var gsrMetaTags = gsr.Items.ElementAtOrDefault(0)?.PageMap.MetaTags.ElementAtOrDefault(0) ?? new GoogleSearchResponse.MetaTag();

                var snippet = gsrMetaTags.OgDescription;
                if (snippet.IsNullOrWhiteSpace())
                {
                    snippet = gsr.Items.ElementAtOrDefault(0)?.Snippet.CleanString() ?? string.Empty;
                }

                var title = gsr.Items.ElementAtOrDefault(0)?.Title.Split("|").ElementAtOrDefault(0)?.Trim();

                var website = gsrMetaTags.OgUrl;
                if (website.IsNullOrWhiteSpace())
                {
                    website = gsr.Items.ElementAtOrDefault(0)?.Link;
                }

                var attachment = new Attachment()
                {
                    Fallback = snippet,
                    Pretext  = $"Excelsior! I found {title} :star-struck:!"
                }
                .AddField("Name", title, true)
                .AddField("Website", website, true)
                .AddField("Bio", snippet)
                .SetImage(gsr.Items[0].PageMap.CseImage[0].Src)
                .SetColor(Color.Green);

                message.SetResponseType(ResponseType.InChannel);
                message.AddAttachment(attachment);
                var response = await client.SendAsync(message).ConfigureAwait(false);

                if (response == "ok")
                {
                    _logger.LogInformation("GetMarvel: Sent message {@Message}", message);
                }
                else
                {
                    _logger.LogError("GetMarvel: Error sending {@Message}", message);
                }
            }
            else
            {
                _logger.LogError("GetMarvel: GetGoogleSearchSlackResponseJson is null. {@SlackCommandRequest}", slackCommandRequest);
            }
        }
示例#12
0
        public async Task Response_In_Ephemeral_Async()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message("This is an ephemeral response type.");

            message.SetResponseType(ResponseType.ephemeral);
            var response = await client.SendAsync(message);

            Assert.AreEqual("ok", response);
        }
示例#13
0
        public void Response_In_Ephemeral()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message("This is an ephemeral response type.");

            message.SetResponseType(ResponseType.ephemeral);
            var response = client.Send(message);

            Assert.AreEqual("ok", response.Result);
        }
        public CS_EventsListener(HttpContext context, WebSocket socket)
        {
            webSocket = socket;
            wsContext = context;

            string slackWebHookUrl = Environment.GetEnvironmentVariable("SLACK_WEBHOOK_URL")
                                     ?? throw new ArgumentNullException("slackWebHookUrl", "EnvironmentVariable 'SLACK_WEBHOOK_URL' doesn't set!");

            slackClient  = new SbmClient(slackWebHookUrl);
            messageQueue = new BlockingCollection <CommandBase>();
            tokenSource  = new CancellationTokenSource();
        }
示例#15
0
        public void Initialize()
        {
            var client = new SbmClient(WebConfigurationManager.AppSettings["SlackBokMessagesWebHookUrl"]);

            var message = new Message
            {
                Username  = "******",
                Text      = "Hello from an Alien",
                IconEmoji = Emoji.Alien
            };

            client.Send(message);
        }
示例#16
0
        protected override void OnApplicationError(object sender, EventArgs evargs)
        {
            var request = HttpContext.Current.Request;
            var error   = HttpContext.Current.Server.GetLastError();

            try
            {
                var client = new SbmClient(WebConfigurationManager.AppSettings["SlackBotMessagesWebHookUrl"]);

                var message = new Message
                {
                    Username    = "******",
                    IconEmoji   = ":robot_face:",
                    Attachments = new System.Collections.Generic.List <Attachment>
                    {
                        new Attachment
                        {
                            Fallback = error.Message,
                            Color    = "danger",
                            Fields   = new System.Collections.Generic.List <Field>
                            {
                                new Field
                                {
                                    Title = Emoji.Warning + " Error",
                                    Value = error.Message
                                },
                                new Field
                                {
                                    Title = "Stack Trace",
                                    Value = error.StackTrace
                                },
                                new Field
                                {
                                    Title = "Url",
                                    Value = request.Url.GetLeftPart(UriPartial.Authority) + request.Url
                                }
                            }
                        }
                    }
                };

                client.Send(message);
            }
            catch (Exception ex)
            {
                Current.Logger.Error(typeof(CustomGlobal), ex, "Unable to send slack notification");
            }

            base.OnApplicationError(sender, evargs);
        }
示例#17
0
        protected override void OnApplicationError(object sender, EventArgs e)
        {
            var request = HttpContext.Current.Request;
            var error   = HttpContext.Current.Server.GetLastError();

            try
            {
                var url    = request.Url.GetLeftPart(UriPartial.Authority) + request.Url;
                var client = new SbmClient(WebConfigurationManager.AppSettings["SlackBotMessagesWebHookUrl"]);

                var message = new Message
                {
                    Username    = "******",
                    IconEmoji   = ":robot_face:",
                    Attachments = new List <Attachment>()
                    {
                        new Attachment()
                        {
                            Fallback = error.Message,
                            Color    = "danger",
                            Fields   = new List <Field>()
                            {
                                new Field()
                                {
                                    Title = Emoji.Warning + " Error",
                                    Value = error.Message
                                },
                                new Field()
                                {
                                    Title = "Stack Trace",
                                    Value = error.StackTrace
                                },
                                new Field()
                                {
                                    Title = "Url",
                                    Value = url
                                }
                            }
                        }
                    }
                };

                client.Send(message);
            }
            catch (Exception ex)
            {
                Current.Logger.Error(typeof(CustomGlobal), ex, "Unable to send slack message to notify unhandled exception");
            }
        }
示例#18
0
        public static void SendMessage(GithubPullRequestComment comment)
        {
            var webhookUrl = Consts.SLACK_HOOK_URL;
            var client     = new SbmClient(webhookUrl);

            var message = new Message($"<!here> <{comment.Comment.User.HtmlUrl}|{comment.Comment.User.Login}> commented on <{comment.PullRequest.HtmlUrl}|{comment.PullRequest.Title}>");

            message.AddAttachment(new Attachment()
                                  .SetPretext($">{comment.Comment.Body}\n\n```{comment.Comment.DiffHunk}```")
                                  .SetFooter(comment.Comment.Path, comment.Comment.User.AvatarUrl.ToString(), comment.Comment.CreatedAt.UtcDateTime)
                                  );


            client.Send(message);
        }
示例#19
0
        public async Task Custom_Icon_Url_Example_Async()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message
            {
                Username = "******",
                Text     = "Hello from Paul",
                IconUrl  = "https://s3-us-west-2.amazonaws.com/slack-files2/bot_icons/2019-06-17/669285832007_48.png"
            };

            var response = await client.SendAsync(message).ConfigureAwait(false);

            Assert.AreEqual("ok", response);
        }
示例#20
0
        public void Emoji_Icon_Example()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message
            {
                Username  = "******",
                Text      = "Hello from an Alien",
                IconEmoji = Emoji.Alien
            };

            var response = client.Send(message);

            Assert.AreEqual("ok", response.Result);
        }
示例#21
0
        public async Task Emoji_Icon_Example_Async()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message
            {
                Username  = "******",
                Text      = "Hello from an Alien",
                IconEmoji = Emoji.Alien
            };

            var response = await client.SendAsync(message).ConfigureAwait(false);

            Assert.AreEqual("ok", response);
        }
示例#22
0
        public static async Task SlackNotify(string webHookUrl, string message, AppSettingsHelper appSettings)
        {
            try
            {
                var client = new SbmClient(webHookUrl);

                var slmessage = new Message(message).SetUserWithEmoji("Alert", Emoji.Loudspeaker);

                await client.Send(slmessage);
            }
            catch
            {
                throw new Exception("Slack notification failed. Please try again.");
            }
        }
示例#23
0
        public void Custom_Icon_Url_Example()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message
            {
                Username = "******",
                Text     = "Hello from Paul",
                IconUrl  = "https://s3-us-west-2.amazonaws.com/slack-files2/bot_icons/2019-06-17/669285832007_48.png"
            };

            var response = client.Send(message);

            Assert.AreEqual("ok", response.Result);
        }
示例#24
0
        public static void SendMessageSlack(string username, string text, string token1, string token2, string token3)
        {
            var WebHookUrl = $"https://hooks.slack.com/services/{token1}/{token2}/{token3}";

            var client = new SbmClient(WebHookUrl);

            var message = new Message("New trial")
                          .SetUserWithEmoji("Website", Emoji.Loudspeaker);

            message.AddAttachment(new SlackBotMessages.Models.Attachment()
                                  .AddField("Name", username, true)
                                  .SetColor("#f96332")
                                  );

            client.Send(message);
        }
示例#25
0
        private void SendMessage(string message, string userName)
        {
            var webHookUrl = _configuration["webhookUrl"];
            var client     = new SbmClient(webHookUrl);

            var messageRequest = new Message($"Dear {userName}, {message}")
                                 .SetUserWithEmoji("Website", Emoji.Loudspeaker);

            messageRequest.AddAttachment(new Attachment()
                                         .AddField("Team", "Wages Clerk", true)
                                         .AddField("Company", "Ready tech", true)
                                         .AddField("Email", "*****@*****.**", true)
                                         .SetColor("#f96332")
                                         );
            client.Send(messageRequest);
        }
示例#26
0
        static void Main(string[] args)
        {
            var client = new SbmClient("https://hooks.slack.com/services/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");

            var message = new Message
            {
                //{ Console.WriteLine("Enter integer") },
                Username = Console.ReadLine(),
                //Text = Console.ReadLine(),
                Text      = Console.ReadLine(),
                IconEmoji = Emoji.Alien,
            };

            client.Send(message);

            //SBMClient client = new SBMClient("https://hooks.slack.com/services/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");
        }
示例#27
0
        public void Pingbot_Alert_Website_Up_Fluent_Example()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message().SetUserWithIconUrl("Pingbot",
                                                           "https://a.slack-edge.com/7f1a0/plugins/pingdom/assets/service_36.png")
                          .AddAttachment(
                new Attachment("Google is up (Incident #12345)")
                .SetColor(Color.Green)
                .AddField("Google is up (Incident #12345)",
                          "<https://google.com> • <https://my.pingbot.com/reports/responsetime#check=12345|View details>")
                );

            var response = client.Send(message);

            Assert.AreEqual("ok", response.Result);
        }
示例#28
0
        public async Task Pingbot_Alert_Website_Down_Fluent_Example_Async()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message().SetUserWithIconUrl("Pingbot",
                                                           "https://a.slack-edge.com/7f1a0/plugins/pingdom/assets/service_36.png")
                          .AddAttachment(
                new Attachment("Google is down (Incident #12345)")
                .SetColor(Color.Red)
                .AddField("Google is down (Incident #12345)",
                          "<https://google.com> • <https://my.pingbot.com/reports/responsetime#check=12345|View details>")
                );

            var response = await client.SendAsync(message).ConfigureAwait(false);

            Assert.AreEqual("ok", response);
        }
示例#29
0
        /// <summary>
        ///     A simple example of a message which looks like it has been send by an alien
        /// </summary>

        public SetUp()
        {
            var client = new SbmClient(WebHookUrl);

            num = 1;
            var message = new Message
            {
                Username  = "******",
                Text      = $"Need support. Test {num}",
                IconEmoji = Emoji.AlarmClock,
            };

            //or send it fully async like this:
            //await client.SendAsync(mesdsage).ConfigureAwait(false);
            Console.ReadKey();

            client.Send(message);
        } // end of SetUp
        internal static void SendSlackNotification(string heading, string userName, string interest, string content)
        {
            var WebHookUrl = "https://hooks.slack.com/services/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";

            var client = new SbmClient(WebHookUrl);

            var message = new Message(heading)
                          .SetUserWithEmoji("Website", Emoji.Loudspeaker);

            message.AddAttachment(new Attachment()
                                  .AddField("User Name", userName, true)
                                  .AddField("Interest", interest, true)
                                  .AddField("Content", content, true)
                                  .SetColor("#f96332")
                                  );

            client.Send(message);
        }