From f117342deb22951a1e19b8aff463c4174f251d8b Mon Sep 17 00:00:00 2001 From: TheDanniCraft Date: Fri, 24 Nov 2023 14:07:14 +0100 Subject: [PATCH 1/7] =?UTF-8?q?=E2=9C=A8=20Modified=20discord=20notificati?= =?UTF-8?q?on=20provider=20-=20Added=20support=20for=20thread=20channels?= =?UTF-8?q?=20-=20Added=20support=20for=20forum=20channels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/notification-providers/discord.js | 19 ++++++++++++--- src/components/notifications/Discord.vue | 30 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index f24cd616..e0798831 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -14,6 +14,9 @@ class Discord extends NotificationProvider { try { const discordDisplayName = notification.discordUsername || "Uptime Kuma"; + var threadQuery = ""; + + if (notification.discordChannelType == "postToThread") threadQuery = "?thread_id=" + notification.threadId; // If heartbeatJSON is null, assume we're testing. if (heartbeatJSON == null) { @@ -21,7 +24,10 @@ 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(notification.discordWebhookUrl + threadQuery, discordtestdata); return okMsg; } @@ -47,6 +53,11 @@ class Discord extends NotificationProvider { // If heartbeatJSON is not null, we go into the normal alerting loop. if (heartbeatJSON["status"] === DOWN) { + const discordDisplayName = notification.discordUsername || "Uptime Kuma"; + var threadQuery = ""; + + if (notification.discordChannelType == "postToThread") threadQuery = "?thread_id=" + notification.threadId; + let discorddowndata = { username: discordDisplayName, embeds: [{ @@ -73,7 +84,7 @@ class Discord extends NotificationProvider { ], }], }; - + if (notification.discordChannelType == "createNewForumPost") discorddowndata.thread_name = notification.postName; if (notification.discordPrefixMessage) { discorddowndata.content = notification.discordPrefixMessage; } @@ -109,11 +120,13 @@ 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(notification.discordWebhookUrl + threadQuery, discordupdata); return okMsg; } } catch (error) { diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue index 99389d29..6e251d66 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -16,4 +16,34 @@ + +
+ +
+ +
+ +
+
+ + +
+
+
+
+ + +
+
+ \ No newline at end of file From 4dc74c42ea8decef8af4f4ee3a7a48a4bbebd897 Mon Sep 17 00:00:00 2001 From: TheDanniCraft Date: Fri, 24 Nov 2023 14:33:13 +0100 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=9A=A8Fixed=20linter=20warns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/notification-providers/discord.js | 26 ++++++++++++++++-------- src/components/notifications/Discord.vue | 8 ++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index e0798831..a2b42319 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -14,9 +14,11 @@ class Discord extends NotificationProvider { try { const discordDisplayName = notification.discordUsername || "Uptime Kuma"; - var threadQuery = ""; + let threadQuery = ""; - if (notification.discordChannelType == "postToThread") threadQuery = "?thread_id=" + notification.threadId; + if (notification.discordChannelType === "postToThread") { + threadQuery = "?thread_id=" + notification.threadId; + } // If heartbeatJSON is null, assume we're testing. if (heartbeatJSON == null) { @@ -25,7 +27,9 @@ class Discord extends NotificationProvider { content: msg, }; - if (notification.discordChannelType == "createNewForumPost") discordtestdata.thread_name = notification.postName; + if (notification.discordChannelType === "createNewForumPost") { + discordtestdata.thread_name = notification.postName; + } await axios.post(notification.discordWebhookUrl + threadQuery, discordtestdata); return okMsg; @@ -54,9 +58,11 @@ class Discord extends NotificationProvider { // If heartbeatJSON is not null, we go into the normal alerting loop. if (heartbeatJSON["status"] === DOWN) { const discordDisplayName = notification.discordUsername || "Uptime Kuma"; - var threadQuery = ""; + let threadQuery = ""; - if (notification.discordChannelType == "postToThread") threadQuery = "?thread_id=" + notification.threadId; + if (notification.discordChannelType === "postToThread") { + threadQuery = "?thread_id=" + notification.threadId; + } let discorddowndata = { username: discordDisplayName, @@ -84,12 +90,14 @@ class Discord extends NotificationProvider { ], }], }; - if (notification.discordChannelType == "createNewForumPost") discorddowndata.thread_name = notification.postName; + 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(notification.discordWebhookUrl + threadQuery, discorddowndata); return okMsg; } else if (heartbeatJSON["status"] === UP) { @@ -120,7 +128,9 @@ class Discord extends NotificationProvider { }], }; - if (notification.discordChannelType == "createNewForumPost") discordupdata.thread_name = notification.postName; + if (notification.discordChannelType === "createNewForumPost") { + discordupdata.thread_name = notification.postName; + } if (notification.discordPrefixMessage) { discordupdata.content = notification.discordPrefixMessage; diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue index 6e251d66..2ceaaec6 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -20,7 +20,7 @@

- @@ -42,8 +42,8 @@ \ No newline at end of file +}; + From fd45ef2d7abccd0ab6d44f62fd9917b56b74613e Mon Sep 17 00:00:00 2001 From: TheDanniCraft Date: Fri, 24 Nov 2023 15:22:40 +0100 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20Default=20value=20was?= =?UTF-8?q?=20always=20used?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/notifications/Discord.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue index 2ceaaec6..96a8b34b 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -43,7 +43,9 @@ From 5a1aefff360a39f53242ffd68ac96b1c2346ab68 Mon Sep 17 00:00:00 2001 From: TheDanniCraft Date: Sat, 25 Nov 2023 02:14:18 +0100 Subject: [PATCH 4/7] =?UTF-8?q?=E2=9C=A8=20=F0=9F=8C=90=20Made=20changes?= =?UTF-8?q?=20based=20on=20reviewers=20suggestions=20-=20Added=20translati?= =?UTF-8?q?ons=20-=20Removed=20unnecessary=20placeholder=20-=20Changed=20p?= =?UTF-8?q?laceholder=20for=20thread=20id=20-=20Added=20helptext=20for=20h?= =?UTF-8?q?ow=20to=20obtain=20thread=20/=20post=20id=20-=20Clarified=20wha?= =?UTF-8?q?t=20happens=20at=20"Create=20new=20forum=20post"=20-=20Renamed?= =?UTF-8?q?=20"Normal"=20to=20"Send=20to=20channel"=20-=20Removed=20unnece?= =?UTF-8?q?ssary=20double=20declaration=20of=20threadQuery=20-=20Instead?= =?UTF-8?q?=20of=20appending=20string,=20append=20via=20URL=20object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/notification-providers/discord.js | 16 +++++----------- src/components/notifications/Discord.vue | 22 ++++++++++++++++------ src/lang/en.json | 9 +++++++++ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index a2b42319..c5343bdd 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -14,10 +14,9 @@ class Discord extends NotificationProvider { try { const discordDisplayName = notification.discordUsername || "Uptime Kuma"; - let threadQuery = ""; - + const webhookUrl = new URL(notification.discordWebhookUrl); if (notification.discordChannelType === "postToThread") { - threadQuery = "?thread_id=" + notification.threadId; + webhookUrl.searchParams.append("thread_id", notification.threadId); } // If heartbeatJSON is null, assume we're testing. @@ -31,7 +30,7 @@ class Discord extends NotificationProvider { discordtestdata.thread_name = notification.postName; } - await axios.post(notification.discordWebhookUrl + threadQuery, discordtestdata); + await axios.post(webhookUrl.toString(), discordtestdata); return okMsg; } @@ -58,11 +57,6 @@ class Discord extends NotificationProvider { // If heartbeatJSON is not null, we go into the normal alerting loop. if (heartbeatJSON["status"] === DOWN) { const discordDisplayName = notification.discordUsername || "Uptime Kuma"; - let threadQuery = ""; - - if (notification.discordChannelType === "postToThread") { - threadQuery = "?thread_id=" + notification.threadId; - } let discorddowndata = { username: discordDisplayName, @@ -97,7 +91,7 @@ class Discord extends NotificationProvider { discorddowndata.content = notification.discordPrefixMessage; } - await axios.post(notification.discordWebhookUrl + threadQuery, discorddowndata); + await axios.post(webhookUrl.toString(), discorddowndata); return okMsg; } else if (heartbeatJSON["status"] === UP) { @@ -136,7 +130,7 @@ class Discord extends NotificationProvider { discordupdata.content = notification.discordPrefixMessage; } - await axios.post(notification.discordWebhookUrl + threadQuery, 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 96a8b34b..3c5ab763 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -21,22 +21,32 @@
- + +
+ {{ $t("whatHappensAtForumPost") }}"{{ $t("Post to existing thread / forum post") }}" +
- - + + +
+ {{ $t("wayToGetDiscordThreadId") }} + {{ $t("here") }} +
@@ -44,7 +54,7 @@ export default { mounted() { if (!this.$parent.notification.discordChannelType) { - this.$parent.notification.discordChannelType = "normal"; + this.$parent.notification.discordChannelType = "channel"; } } }; diff --git a/src/lang/en.json b/src/lang/en.json index 806d6fbd..bda78fa2 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -517,6 +517,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", + "Post to existing thread / forum post": "Post to existing thread / forum post", + "Forum post name": "Forum post name", + "Thread / Forum post ID": "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 ", + "wayToGetDiscordThreadId": "Getting a thread / forum post id is simmilar to getting a channel id. Read more about how to get ids ", "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.", From 10d4d44907014fcaf5e435c91a5120863f8b5700 Mon Sep 17 00:00:00 2001 From: TheDanniCraft Date: Sun, 26 Nov 2023 05:16:02 +0100 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=8C=90=20Adjusted=20code=20to=20make?= =?UTF-8?q?=20translation=20easier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/notification-providers/discord.js | 2 -- src/components/notifications/Discord.vue | 15 ++++++++++----- src/lang/en.json | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index c5343bdd..27ac9064 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -56,8 +56,6 @@ class Discord extends NotificationProvider { // If heartbeatJSON is not null, we go into the normal alerting loop. if (heartbeatJSON["status"] === DOWN) { - const discordDisplayName = notification.discordUsername || "Uptime Kuma"; - let discorddowndata = { username: discordDisplayName, embeds: [{ diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue index 3c5ab763..c28831f6 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -23,25 +23,30 @@
- +
- {{ $t("whatHappensAtForumPost") }}"{{ $t("Post to existing thread / forum post") }}" + + ""
- +
- {{ $t("wayToGetDiscordThreadId") }} + Date: Sun, 26 Nov 2023 16:38:29 +0100 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=8C=90=20Adjusted=20code=20for=20bett?= =?UTF-8?q?er=20translation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/notifications/Discord.vue | 18 +++++++++--------- src/lang/en.json | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue index c28831f6..dc8bc004 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -30,27 +30,27 @@
- - "" + {{ $t("whatHappensAtForumPost", { option: $t("postToExistingThread") }) }}
diff --git a/src/lang/en.json b/src/lang/en.json index ca85d917..7f8f370e 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -524,8 +524,8 @@ "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 ", - "wayToGetDiscordThreadId": "Getting a thread / forum post id is simmilar to getting a channel id. Read more about how to get ids ", + "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 simmilar 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.", From ae23ccf0d85caf9118443dc4e31750287e414043 Mon Sep 17 00:00:00 2001 From: TheDanniCraft Date: Sun, 26 Nov 2023 21:16:40 +0100 Subject: [PATCH 7/7] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fixed=20typo,=20remove?= =?UTF-8?q?d=20unnecessary
?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/notifications/Discord.vue | 1 - src/lang/en.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue index dc8bc004..5d8334f5 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -19,7 +19,6 @@
-