From 59e70cb7635e6986be3ded4ec5bc8f21432b72c5 Mon Sep 17 00:00:00 2001 From: Daan Meijer Date: Tue, 8 Oct 2024 12:09:58 +0200 Subject: [PATCH] [slack] allow the user to choose the message format to send (#5167) Co-authored-by: Louis Lam Co-authored-by: Frank Elsinga --- server/notification-providers/slack.js | 13 +++++++++---- src/components/notifications/Slack.vue | 6 ++++++ src/lang/en.json | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/server/notification-providers/slack.js b/server/notification-providers/slack.js index 98ed1a90..77264205 100644 --- a/server/notification-providers/slack.js +++ b/server/notification-providers/slack.js @@ -139,17 +139,22 @@ class Slack extends NotificationProvider { const title = "Uptime Kuma Alert"; let data = { - "text": `${title}\n${msg}`, "channel": notification.slackchannel, "username": notification.slackusername, "icon_emoji": notification.slackiconemo, - "attachments": [ + "attachments": [], + }; + + if (notification.slackrichmessage) { + data.attachments.push( { "color": (heartbeatJSON["status"] === UP) ? "#2eb886" : "#e01e5a", "blocks": Slack.buildBlocks(baseURL, monitorJSON, heartbeatJSON, title, msg), } - ] - }; + ); + } else { + data.text = `${title}\n${msg}`; + } if (notification.slackbutton) { await Slack.deprecateURL(notification.slackbutton); diff --git a/src/components/notifications/Slack.vue b/src/components/notifications/Slack.vue index dead709c..dc07bf37 100644 --- a/src/components/notifications/Slack.vue +++ b/src/components/notifications/Slack.vue @@ -9,6 +9,12 @@ + +
+ + +
+
*{{ $t("Required") }} diff --git a/src/lang/en.json b/src/lang/en.json index 3a4ca715..968a3d9f 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -895,6 +895,8 @@ "cacheBusterParamDescription": "Randomly generated parameter to skip caches.", "gamedigGuessPort": "Gamedig: Guess Port", "gamedigGuessPortDescription": "The port used by Valve Server Query Protocol may be different from the client port. Try this if the monitor cannot connect to your server.", + "Message format": "Message format", + "Send rich messages": "Send rich messages", "Bitrix24 Webhook URL": "Bitrix24 Webhook URL", "wayToGetBitrix24Webhook": "You can create a webhook by following the steps at {0}", "bitrix24SupportUserID": "Enter your user ID in Bitrix24. You can find out the ID from the link by going to the user's profile.",