예제 #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 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;
            }
        }
예제 #3
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.");
            }
        }
예제 #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 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;
     }
 }
예제 #6
0
 /// <summary>
 /// request for robotic support function
 /// </summary>
 public void RoboticSupportRequest(string robSupportText, string webHookRobotSup)
 {
     message = new Message
     {
         Text = robSupportText
     };
     WebHookRobotSupport = webHookRobotSup;
     SetupClients();
     clientRobotSupport.Send(message);
 } // end of RoboticSupportReques method
예제 #7
0
        } // end of RoboticSupportReques method

        /// <summary>
        /// request for R4 support function
        /// </summary>
        public void R4Request(string r4SupportText, string webHookR4Sup)
        {
            message = new Message
            {
                Text = r4SupportText
            };
            WebHookR4Support = webHookR4Sup;
            SetupClients();
            clientR4Support.Send(message);
        } // end of R4Request method
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
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");
            }
        }
예제 #14
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.");
            }
        }
예제 #15
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);
        }
예제 #16
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);
        }
예제 #17
0
 public void Log(LogField logField, string msg)
 {
     if (logField == LogField.web)
     {
         webSlackBotClient.Send(FormatMessage(msg));
     }
     if (logField == LogField.server)
     {
         serverSlackBotClient.Send(FormatMessage(msg));
     }
     if (logField == LogField.userArticles)
     {
         userArticlesSlackBotClient.Send(FormatMessage(msg));
     }
 }
예제 #18
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);
        }
예제 #19
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);
        }
예제 #20
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);
        }
예제 #21
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);
        }
예제 #22
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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");
        }
예제 #23
0
파일: SetUp.cs 프로젝트: 0000duck/Projects
        /// <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);
        }
예제 #25
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public string FunctionHandler(string reminder, ILambdaContext context)
        {
            var WebHookUrl  = "https://hooks.slack.com/services/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";
            var client      = new SbmClient(WebHookUrl);
            var staffList   = "Ryan Meria,Michael Williams,Rui Chapouto,Jack Kuang,Tin Hoang,Josh Deng";
            var shuffleList = staffList.Split(',').ToList().OrderBy(a => Guid.NewGuid()).ToList();
            var dateToday   = System.DateTime.Now.Date.ToString("MM/dd/yyyy");
            var teamID      = "4226";

            AttandanceRecordList attandanceRecordList = GetAttandanceList(dateToday, teamID);

            var dayOffList = "";
            var index      = 1;

            if (attandanceRecordList.data != null)
            {
                foreach (var item in attandanceRecordList.data)
                {
                    if ((item.duration.ToLower() == "full day" && item.reason.ToLower() != "tech investigation") || item.duration.ToLower() == "7.5 hours")
                    {
                        dayOffList += item.name;
                        if (index < attandanceRecordList.data.Count())
                        {
                            dayOffList += (", ");
                        }
                    }
                    index++;
                }
            }
            var shuffleListNoDayOff = shuffleList.Except(dayOffList.Replace(", ", ",").Split(',').ToList()).ToList();

            reminder = reminder ?? "@channel Please don't forget to update your remaining points on the card that you are working on.";

            var message = new Message(System.DateTime.Now.Date.ToString("MMMM dd"));

            message.AddAttachment(new Attachment()
                                  .AddField("Day-off Today:", dayOffList, true)
                                  .AddField("Standup Order", shuffleListNoDayOff != null ? String.Join(", ", shuffleListNoDayOff) : "", true)
                                  .AddField("Reminder", reminder)
                                  );

            client.Send(message);
            return(reminder);
        }
예제 #26
0
        public void Short_Fields_Example()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message();

            message.AddAttachment(new Attachment()
                                  .AddField("Lorem", "Ipsum Dolor", true)
                                  .AddField("Sit", "Amet", true)
                                  .AddField("Consectetur", "Adipiscing elit", true)
                                  .AddField("Eiusmod", "Tempor incididunt", true)
                                  .AddField("A love story",
                                            "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Fames ac turpis egestas integer eget aliquet nibh praesent tristique. Ac feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper. Ultrices tincidunt arcu non sodales neque sodales. Ac auctor augue mauris augue neque gravida in fermentum et. Facilisi nullam vehicula ipsum a. Ac turpis egestas integer eget aliquet nibh praesent tristique. Vitae ultricies leo integer malesuada nunc vel risus commodo. Justo nec ultrices dui sapien eget mi proin sed. At auctor urna nunc id cursus metus aliquam eleifend. Purus sit amet luctus venenatis. Cursus in hac habitasse platea dictumst quisque. Pharetra sit amet aliquam id diam. In vitae turpis massa sed. Massa massa ultricies mi quis.")
                                  );

            var response = client.Send(message);

            Assert.AreEqual("ok", response.Result);
        }
예제 #27
0
        /// <summary>
        ///     Send Shuffle list along with attandance summary and reminder message to slack channel
        /// </summary>

        public IHttpActionResult Shuffle()
        {
            var WebHookUrl  = WebConfigurationManager.AppSettings["WebHookUrlProd"];
            var client      = new SbmClient(WebHookUrl);
            var staffList   = WebConfigurationManager.AppSettings["StaffList"];
            var shuffleList = staffList.Split(',').ToList().OrderBy(a => Guid.NewGuid()).ToList();
            var dateToday   = System.DateTime.Now.Date.ToString("MM/dd/yyyy");
            var teamID      = "4226";

            AttandanceRecordList attandanceRecordList = GetAttandanceList(dateToday, teamID);

            var dayOffList = "";
            var index      = 1;

            if (attandanceRecordList.data != null)
            {
                foreach (var item in attandanceRecordList.data)
                {
                    if ((item.duration.ToLower() == "full day" && item.reason.ToLower() != "tech investigation") || item.duration.ToLower() == "7.5 hours")
                    {
                        dayOffList += item.name;
                        if (index < attandanceRecordList.data.Count())
                        {
                            dayOffList += (", ");
                        }
                    }
                    index++;
                }
            }
            var shuffleListNoDayOff = shuffleList.Except(dayOffList.Replace(", ", ",").Split(',').ToList()).ToList();
            var reminder            = "@channel Please don't forget to update your remaining points on the card that you are working on.";

            var message = new Message(System.DateTime.Now.Date.ToString("MMMM dd"));

            message.AddAttachment(new Attachment()
                                  .AddField("Day-off Today:", dayOffList, true)
                                  .AddField("Standup Order", shuffleListNoDayOff != null? String.Join(", ", shuffleListNoDayOff) : "", true)
                                  .AddField("Reminder", reminder)
                                  );

            client.Send(message);
            return(Ok());
        }
예제 #28
0
        public void Article_Link_Example()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message("https://dev.to/")
                          .SetUserWithIconUrl("Slack Bot Messages", "https://codeshare.co.uk/media/1505/sbmlogo.jpg")
                          .AddAttachment(
                new Attachment("Sorting the tools")
                .SetAuthor("dev.to",
                           authorIcon:
                           "https://slack-imgs.com/?c=1&o1=wi32.he32.si&url=https%3A%2F%2Fpracticaldev-herokuapp-com.freetls.fastly.net%2Fassets%2Fapple-icon-e9a036e0385d6e1e4ddef50be5e583800c0b5ca325d4998a640c38602d23b26c.png")
                .SetColor("#DDDDDD")
                .AddField("The DEV Community", "Where programmers share ideas and help each other grow.")
                .SetImage("https://thepracticaldev.s3.amazonaws.com/i/6hqmcjaxbgbon8ydw93z.png")
                );

            var response = client.Send(message);

            Assert.AreEqual("ok", response.Result);
        }
예제 #29
0
        public void Thumb_Example()
        {
            var client = new SbmClient(WebHookUrl);

            var message = new Message()
                          .SetChannel("general")
                          .SetUserWithIconUrl("SlackBotMessages", "https://codeshare.co.uk/media/1505/sbmlogo.jpg")
                          .AddAttachment(
                new Attachment("Lorem ipsum dolor sit amet ...")
                .SetColor("#0000ff")
                .AddField("A love story with a thumbnail",
                          "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Fames ac turpis egestas integer eget aliquet nibh praesent tristique. Ac feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper. Ultrices tincidunt arcu non sodales neque sodales. Ac auctor augue mauris augue neque gravida in fermentum et. Facilisi nullam vehicula ipsum a. Ac turpis egestas integer eget aliquet nibh praesent tristique. Vitae ultricies leo integer malesuada nunc vel risus commodo. Justo nec ultrices dui sapien eget mi proin sed. At auctor urna nunc id cursus metus aliquam eleifend. Purus sit amet luctus venenatis. Cursus in hac habitasse platea dictumst quisque. Pharetra sit amet aliquam id diam. In vitae turpis massa sed. Massa massa ultricies mi quis.")
                .SetThumbUrl(
                    "https://s3-us-west-2.amazonaws.com/slack-files2/bot_icons/2019-06-19/658365479699_48.png")
                );

            var response = client.Send(message);

            Assert.AreEqual("ok", response.Result);
        }
예제 #30
0
        public static void SendMessage(TravisCiWebhook build)
        {
            var    buildStatus = "👷🏼‍♂️🛠" + (build.Status == TravisCIBuildStatus.SUCCESS ? "✅" : "❌");
            string color       = build.Status == TravisCIBuildStatus.SUCCESS ? Consts.GREEN : Consts.RED;
            string buildType   = "";
            string prnumber    = "";

            switch (build.Type)
            {
            case TravisCIBuildType.API:
                buildType = "api";
                break;

            case TravisCIBuildType.CRON:
                buildType = "cron";
                break;

            case TravisCIBuildType.PULL_REQUEST:
                buildType = "pull request";
                prnumber  = $" (#{build.PullRequestNumber})";
                break;

            case TravisCIBuildType.PUSH:
                buildType = "push";
                break;
            }

            var WebHookUrl = Consts.SLACK_HOOK_URL;
            var client     = new SbmClient(WebHookUrl);
            var message    = new Message($"<!here> {buildStatus}  {build.AuthorName}'s <{build.BuildUrl}|{buildType}{prnumber}> {build.ResultMessage.ToLower()} ");

            message.AddAttachment(new Attachment()
                                  .SetColor(color)
                                  .AddField("Started at", build.StartedAt.UtcDateTime.ToString(), true)
                                  .AddField("Total build time", $"{build.Duration} seconds", true)
                                  .AddField("Build number", build.Number, true)
                                  .AddField("Compare", $"<{build.CompareUrl}|{build.Commit.Substring(0, 7)}>", true)
                                  );

            client.Send(message);
        }