private async Task PostMessageToSlackAsync(string text) { try { string jsonBody = new SlackMessageBody { username = SlackSenderName, text = text, icon_emoji = SlackSenderEmoji }.ToJson(); using (var webClient = _webClientFactory()) { var username = Settings.GetSetting("General.WebhookAlternativeCredentials.UserName"); var pass = Settings.GetSetting("General.WebhookAlternativeCredentials.EncryptedPassword"); if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(pass)) { webClient.Credentials = new NetworkCredential(username, new Encryption().Decrypt(pass, NotificationHelper.NotificationCategoryHelper)); } await webClient.UploadStringAsync(SlackUri, HttpMethod.Post, jsonBody, CancellationToken.None); } } catch (Exception ex) { Log.To.Main.AddException("Error when posting to Slack.", ex); } }
public async Task PostMessageToSlackAsync(string text) { try { string jsonBody = new SlackMessageBody { username = "******", text = text, icon_emoji = ":alien:" }.ToJson(); using (var webClient = new HttpClient()) { await webClient.PostAsync("https://hooks.slack.com/services/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", new StringContent(jsonBody), CancellationToken.None); } } catch (Exception ex) { // Log.To.Main.AddException("Error when posting to Slack.", ex); } }