From 00f733d35280dab78d124b52abdc4edd7cc0fddc Mon Sep 17 00:00:00 2001 From: duane Date: Mon, 17 Apr 2023 12:49:15 -0500 Subject: [PATCH] Adds ability to notify channel when Slack webhook triggered - Adds field to toggle channel mentions on/off for Slack integration - Adds special mention for @channel when enabled Reference: [Slack docs](https://api.slack.com/reference/surfaces/formatting#special-mentions) --- server/notification-providers/slack.js | 12 ++++++++---- src/components/notifications/Slack.vue | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/server/notification-providers/slack.js b/server/notification-providers/slack.js index da89f0f7..f4a72b03 100644 --- a/server/notification-providers/slack.js +++ b/server/notification-providers/slack.js @@ -27,10 +27,14 @@ class Slack extends NotificationProvider { async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { let okMsg = "Sent Successfully."; + const finalMsg = notification.slackchannelmention + ? `${msg} ` + : msg; + try { if (heartbeatJSON == null) { let data = { - "text": msg, + "text": finalMsg, "channel": notification.slackchannel, "username": notification.slackusername, "icon_emoji": notification.slackiconemo, @@ -42,7 +46,7 @@ class Slack extends NotificationProvider { const time = heartbeatJSON["time"]; const textMsg = "Uptime Kuma Alert"; let data = { - "text": `${textMsg}\n${msg}`, + "text": `${textMsg}\n${finalMsg}`, "channel": notification.slackchannel, "username": notification.slackusername, "icon_emoji": notification.slackiconemo, @@ -54,14 +58,14 @@ class Slack extends NotificationProvider { "type": "header", "text": { "type": "plain_text", - "text": "Uptime Kuma Alert", + "text": textMsg, }, }, { "type": "section", "fields": [{ "type": "mrkdwn", - "text": "*Message*\n" + msg, + "text": "*Message*\n" + finalMsg, }, { "type": "mrkdwn", diff --git a/src/components/notifications/Slack.vue b/src/components/notifications/Slack.vue index 6d220caa..34ef5feb 100644 --- a/src/components/notifications/Slack.vue +++ b/src/components/notifications/Slack.vue @@ -24,5 +24,11 @@ https://www.webfx.com/tools/emoji-cheat-sheet/ + +
+ + +
+