From 19799e5d9d44a89275d3aa5d6cd098ef3aa966da Mon Sep 17 00:00:00 2001 From: Stephen Papierski Date: Tue, 28 Nov 2023 12:46:43 -0700 Subject: [PATCH] Add slack support for SLOW/NOMINAL notification cards --- server/notification-providers/slack.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/server/notification-providers/slack.js b/server/notification-providers/slack.js index d512a7cd8..f343280d6 100644 --- a/server/notification-providers/slack.js +++ b/server/notification-providers/slack.js @@ -1,11 +1,12 @@ const NotificationProvider = require("./notification-provider"); const axios = require("axios"); const { setSettings, setting } = require("../util-server"); -const { getMonitorRelativeURL, UP } = require("../../src/util"); +const { getMonitorRelativeURL, UP, DOWN, NOMINAL, SLOW } = require("../../src/util"); class Slack extends NotificationProvider { name = "slack"; + supportSlowNotifications = true; /** * Deprecated property notification.slackbutton @@ -50,6 +51,23 @@ class Slack extends NotificationProvider { } const textMsg = "Uptime Kuma Alert"; + + let color; + switch(heartbeatJSON["status"]) { + case UP: + case NOMINAL: + color = "#2eb886"; + break; + case SLOW: + color = "#ffc107"; + break; + case DOWN: + color = "#e01e5a" + break; + default: + color = "#0dcaf0"; + } + let data = { "text": `${textMsg}\n${msg}`, "channel": notification.slackchannel, @@ -57,7 +75,7 @@ class Slack extends NotificationProvider { "icon_emoji": notification.slackiconemo, "attachments": [ { - "color": (heartbeatJSON["status"] === UP) ? "#2eb886" : "#e01e5a", + "color": color, "blocks": [ { "type": "header",