From 4e24e96dabc342b614cf8515fd205f394499be6c Mon Sep 17 00:00:00 2001 From: TheDanniCraft Date: Sun, 19 May 2024 21:14:13 +0200 Subject: [PATCH] [discord] thread/forum channel support (#4099) --- server/notification-providers/discord.js | 23 +++++++++--- src/components/notifications/Discord.vue | 46 ++++++++++++++++++++++++ src/lang/en.json | 9 +++++ 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index f24d4725..129e334b 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -13,6 +13,10 @@ class Discord extends NotificationProvider { try { const discordDisplayName = notification.discordUsername || "Uptime Kuma"; + const webhookUrl = new URL(notification.discordWebhookUrl); + if (notification.discordChannelType === "postToThread") { + webhookUrl.searchParams.append("thread_id", notification.threadId); + } // If heartbeatJSON is null, assume we're testing. if (heartbeatJSON == null) { @@ -20,7 +24,12 @@ class Discord extends NotificationProvider { username: discordDisplayName, content: msg, }; - await axios.post(notification.discordWebhookUrl, discordtestdata); + + if (notification.discordChannelType === "createNewForumPost") { + discordtestdata.thread_name = notification.postName; + } + + await axios.post(webhookUrl.toString(), discordtestdata); return okMsg; } @@ -72,12 +81,14 @@ class Discord extends NotificationProvider { ], }], }; - + if (notification.discordChannelType === "createNewForumPost") { + discorddowndata.thread_name = notification.postName; + } if (notification.discordPrefixMessage) { discorddowndata.content = notification.discordPrefixMessage; } - await axios.post(notification.discordWebhookUrl, discorddowndata); + await axios.post(webhookUrl.toString(), discorddowndata); return okMsg; } else if (heartbeatJSON["status"] === UP) { @@ -108,11 +119,15 @@ class Discord extends NotificationProvider { }], }; + if (notification.discordChannelType === "createNewForumPost") { + discordupdata.thread_name = notification.postName; + } + if (notification.discordPrefixMessage) { discordupdata.content = notification.discordPrefixMessage; } - await axios.post(notification.discordWebhookUrl, discordupdata); + await axios.post(webhookUrl.toString(), discordupdata); return okMsg; } } catch (error) { diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue index 99389d29..5d8334f5 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -16,4 +16,50 @@ + +
+ + +
+ +
+
+ + +
+ {{ $t("whatHappensAtForumPost", { option: $t("postToExistingThread") }) }} +
+
+
+
+
+ + + +
+
+ diff --git a/src/lang/en.json b/src/lang/en.json index d4a0997c..2c6e7887 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -527,6 +527,15 @@ "Bot Display Name": "Bot Display Name", "Prefix Custom Message": "Prefix Custom Message", "Hello @everyone is...": "Hello {'@'}everyone is…", + "Select message type": "Select message type", + "Send to channel": "Send to channel", + "Create new forum post": "Create new forum post", + "postToExistingThread": "Post to existing thread / forum post", + "forumPostName": "Forum post name", + "threadForumPostID": "Thread / Forum post ID", + "e.g. {discordThreadID}": "e.g. {discordThreadID}", + "whatHappensAtForumPost": "Create a new forum post. This does NOT post messages in existing post. To post in existing post use \"{option}\"", + "wayToGetDiscordThreadId": "Getting a thread / forum post id is similar to getting a channel id. Read more about how to get ids {0}", "wayToGetTeamsURL": "You can learn how to create a webhook URL {0}.", "wayToGetZohoCliqURL": "You can learn how to create a webhook URL {0}.", "needSignalAPI": "You need to have a signal client with REST API.",