コード例 #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
ファイル: SlackClient.cs プロジェクト: Pipding/Sculpt
        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));
        }
コード例 #3
0
 public TestController(
     ILogger <TestController> logger,
     SlackClient slackClient,
     StockPickingService stockPickingService)
 {
     _logger              = logger;
     _slackClient         = slackClient;
     _stockPickingService = stockPickingService;
 }
コード例 #4
0
ファイル: XkcdService.cs プロジェクト: Smartrak/slacker-xkcd
        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"]);
        }
コード例 #5
0
		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);
		}
コード例 #6
0
ファイル: Program.cs プロジェクト: kawa-xxx/Slack2FAChecker
		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);
		}
コード例 #7
0
 public SlackClientAdapter(Webhooks.SlackClient slackClient)
 {
     _slackClient = slackClient;
 }
コード例 #8
0
 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}");
         }
     }
 }
コード例 #9
0
 public SlackProvider(string webhook)
 {
     _slackClient = new Slack.Webhooks.SlackClient(webhook);
 }
コード例 #10
0
 /// <summary>
 /// Serialize SlackMessage to a JSON string
 /// </summary>
 /// <returns>JSON formatted string</returns>
 public string AsJson()
 {
     return(SlackClient.SerializeObject(this));
 }
コード例 #11
0
 public SlackClientAdapter(Webhooks.SlackClient slackClient)
 {
     _slackClient = slackClient;
 }