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}).")); } }
public static bool PostMessage(string webhook, string message, IEnumerable <string> channels) { var client = new Webhooks.SlackClient(webhook); var msg = ConvertToSlackMessage(message); return(client.PostToChannels(msg, channels)); }
public TestController( ILogger <TestController> logger, SlackClient slackClient, StockPickingService stockPickingService) { _logger = logger; _slackClient = slackClient; _stockPickingService = stockPickingService; }
public XkcdService() { var pollFrequency = ConfigurationManager.AppSettings["poll-frequency"]; _interval = new TimeSpan(0, 15, 0); if (pollFrequency != null && TimeSpan.TryParse(pollFrequency, out _interval)) { Console.WriteLine("using poll frequency " + pollFrequency); } _client = new SlackClient(ConfigurationManager.AppSettings["slack-webhook-url"]); }
private void SlackPost(string message) { var client = new SlackClient(ConfigurationManager.AppSettings["SlackWebHookUrl"]); var slackMessage = new SlackMessage { Channel = "#test", Text = message, IconEmoji = Emoji.Octocat, Username = "******" }; client.Post(slackMessage); }
private void SlackPost(string message) { var client = new SlackClient(ConfigurationManager.AppSettings["SlackWebHookUrl"]); var channel = ConfigurationManager.AppSettings["PostChannel"]; var slackMessage = new SlackMessage { Channel = channel, Text = message, IconEmoji = ":slack:", Username = "******" }; client.Post(slackMessage); }
public SlackClientAdapter(Webhooks.SlackClient slackClient) { _slackClient = slackClient; }
private void SendError(bool logToSlack, string package, string exception) { Trace.TraceError("Unable to create package {0}, {1}", package, exception); if (logToSlack && _slackUrl!=null) { try { var slackClient = new SlackClient(_slackUrl); var slackMessage = new SlackMessage { Channel = _slackChannel, Text = $"*Upload for {package} failed*\n{exception}", Username = _slackUsername }; slackClient.Post(slackMessage); } catch (Exception slackException) { Trace.TraceError($"Unable to send message to slack {slackException.Message}"); } } }
public SlackProvider(string webhook) { _slackClient = new Slack.Webhooks.SlackClient(webhook); }
/// <summary> /// Serialize SlackMessage to a JSON string /// </summary> /// <returns>JSON formatted string</returns> public string AsJson() { return(SlackClient.SerializeObject(this)); }