예제 #1
0
        public async Task <Tuple <bool, string> > SendMessage(SlackMessage message)
        {
            try
            {
                SlackAPI.SlackMessage slackMessage = new SlackAPI.SlackMessage
                {
                    Username = message.Username,
                    Channel  = message.Channel,
                    Text     = message.Message
                };

                if (!string.IsNullOrWhiteSpace(message.Emoji) && Enum.TryParse(message.Emoji, out SlackAPI.Emoji emoji))
                {
                    slackMessage.IconEmoji = emoji;
                }

                SlackAPI.SlackClient slackClient = new SlackAPI.SlackClient(message.WebHookURL);
                bool sendResult = await slackClient.PostAsync(slackMessage);

                return(new Tuple <bool, string>(sendResult, null));
            }
            catch (Exception ex)
            {
                return(new Tuple <bool, string>(false, $"Failed to send message to slack ({ex.Message})."));
            }
        }
예제 #2
0
        public IActionResult SendMessageToSlack(string message)
        {
            var slackTask = _slackClient.PostAsync(new SlackMessage()
            {
                // Text = message,
                Blocks = new List <Block>()
                {
                    new Slack.Webhooks.Blocks.Image
                    {
                        AltText  = "Sexy Skyline",
                        ImageUrl = "https://placekitten.com/500/500",
                        Title    = new Slack.Webhooks.Elements.TextObject("Hello, this is text")
                    }
                }
            });

            return(new JsonResult(new { Success = true }));
        }