From dab089086c6bed06d41dba01d203b7e65e3c6339 Mon Sep 17 00:00:00 2001 From: "Pargorn.Ru" Date: Fri, 17 Jan 2025 17:05:18 +0700 Subject: [PATCH 01/11] Add OneChat notification provider --- package-lock.json | 4 +- server/notification-providers/onechat.js | 70 ++++++++++++++++++++++++ server/notification.js | 2 + src/components/NotificationDialog.vue | 1 + src/components/notifications/OneChat.vue | 48 ++++++++++++++++ src/components/notifications/index.js | 2 + 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 server/notification-providers/onechat.js create mode 100644 src/components/notifications/OneChat.vue diff --git a/package-lock.json b/package-lock.json index 8d3f58b4d..ccf1a628c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "uptime-kuma", - "version": "2.0.0-beta.0", + "version": "2.0.0-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "uptime-kuma", - "version": "2.0.0-beta.0", + "version": "2.0.0-beta.1", "license": "MIT", "dependencies": { "@grpc/grpc-js": "~1.8.22", diff --git a/server/notification-providers/onechat.js b/server/notification-providers/onechat.js new file mode 100644 index 000000000..86d926085 --- /dev/null +++ b/server/notification-providers/onechat.js @@ -0,0 +1,70 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { DOWN, UP } = require("../../src/util"); + +class OneChat extends NotificationProvider { + name = "OneChat"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + const url = "https://chat-api.one.th/message/api/v1/push_message"; + + try { + const config = { + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + notification.accessToken, + }, + }; + // Send a test message if the monitor is null + if (heartbeatJSON == null) { + const testMessage = { + to: notification.recieverId, + bot_id: notification.botId, + type: "text", + message: "Test Successful!", + }; + await axios.post(url, testMessage, config); + } else if (heartbeatJSON["status"] === DOWN) { + const downMessage = { + to: notification.recieverId, + bot_id: notification.botId, + type: "text", + message: + `UptimeKuma Alert:\n[🔴 Down]\n` + + `Name: ${monitorJSON["name"]}\n` + + `${heartbeatJSON["msg"]}\n` + + `Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, + }; + await axios.post(url, downMessage, config); + } else if (heartbeatJSON["status"] === UP) { + const upMessage = { + to: notification.recieverId, + bot_id: notification.botId, + type: "text", + message: + `UptimeKuma Alert:\n[✅ Up]\n` + + `Name: ${monitorJSON["name"]}\n` + + `${heartbeatJSON["msg"]}\n` + + `Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, + }; + await axios.post(url, upMessage, config); + } + + return okMsg; + } catch (error) { + // Handle errors and throw a descriptive message + if (error.response) { + const errorMessage = error.response.data?.message || "Unknown API error occurred."; + throw new Error(`OneChat API Error: ${errorMessage}`); + } else { + throw new Error(`Network or unexpected error: ${error.message}`); + } + } + } +} + +module.exports = OneChat; \ No newline at end of file diff --git a/server/notification.js b/server/notification.js index e7977eb4a..aed083470 100644 --- a/server/notification.js +++ b/server/notification.js @@ -30,6 +30,7 @@ const Mattermost = require("./notification-providers/mattermost"); const Nostr = require("./notification-providers/nostr"); const Ntfy = require("./notification-providers/ntfy"); const Octopush = require("./notification-providers/octopush"); +const OneChat = require("./notification-providers/onechat"); const OneBot = require("./notification-providers/onebot"); const Opsgenie = require("./notification-providers/opsgenie"); const PagerDuty = require("./notification-providers/pagerduty"); @@ -116,6 +117,7 @@ class Notification { new Nostr(), new Ntfy(), new Octopush(), + new OneChat(), new OneBot(), new Onesender(), new Opsgenie(), diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index f6d728029..6a206699f 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -135,6 +135,7 @@ export default { "nostr": "Nostr", "ntfy": "Ntfy", "octopush": "Octopush", + "OneChat": "OneChat", "OneBot": "OneBot", "Onesender": "Onesender", "Opsgenie": "Opsgenie", diff --git a/src/components/notifications/OneChat.vue b/src/components/notifications/OneChat.vue new file mode 100644 index 000000000..93457f6a9 --- /dev/null +++ b/src/components/notifications/OneChat.vue @@ -0,0 +1,48 @@ + \ No newline at end of file diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index efa2af5c4..5330fa9ff 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -29,6 +29,7 @@ import Mattermost from "./Mattermost.vue"; import Nostr from "./Nostr.vue"; import Ntfy from "./Ntfy.vue"; import Octopush from "./Octopush.vue"; +import OneChat from "./OneChat.vue"; import OneBot from "./OneBot.vue"; import Onesender from "./Onesender.vue"; import Opsgenie from "./Opsgenie.vue"; @@ -103,6 +104,7 @@ const NotificationFormList = { "nostr": Nostr, "ntfy": Ntfy, "octopush": Octopush, + "OneChat": OneChat, "OneBot": OneBot, "Onesender": Onesender, "Opsgenie": Opsgenie, From ef9b6d2be8a6d9ef71790edb30bbbf8133d7bc92 Mon Sep 17 00:00:00 2001 From: "Pargorn.Ru" Date: Fri, 17 Jan 2025 19:47:10 +0700 Subject: [PATCH 02/11] fix ESLint issues in OneChat.js --- server/notification-providers/onechat.js | 40 +++++++++++++++++------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/server/notification-providers/onechat.js b/server/notification-providers/onechat.js index 86d926085..e2f170049 100644 --- a/server/notification-providers/onechat.js +++ b/server/notification-providers/onechat.js @@ -34,10 +34,17 @@ class OneChat extends NotificationProvider { bot_id: notification.botId, type: "text", message: - `UptimeKuma Alert:\n[🔴 Down]\n` + - `Name: ${monitorJSON["name"]}\n` + - `${heartbeatJSON["msg"]}\n` + - `Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, + "UptimeKuma Alert:\n" + + "[🔴 Down]\n" + + "Name: " + + monitorJSON["name"] + + "\n" + + heartbeatJSON["msg"] + + "\n" + + "Time (" + + heartbeatJSON["timezone"] + + "): " + + heartbeatJSON["localDateTime"], }; await axios.post(url, downMessage, config); } else if (heartbeatJSON["status"] === UP) { @@ -46,10 +53,17 @@ class OneChat extends NotificationProvider { bot_id: notification.botId, type: "text", message: - `UptimeKuma Alert:\n[✅ Up]\n` + - `Name: ${monitorJSON["name"]}\n` + - `${heartbeatJSON["msg"]}\n` + - `Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, + "UptimeKuma Alert:\n" + + "[🟢 Up]\n" + + "Name: " + + monitorJSON["name"] + + "\n" + + heartbeatJSON["msg"] + + "\n" + + "Time (" + + heartbeatJSON["timezone"] + + "): " + + heartbeatJSON["localDateTime"], }; await axios.post(url, upMessage, config); } @@ -58,13 +72,17 @@ class OneChat extends NotificationProvider { } catch (error) { // Handle errors and throw a descriptive message if (error.response) { - const errorMessage = error.response.data?.message || "Unknown API error occurred."; + const errorMessage = + error.response.data?.message || + "Unknown API error occurred."; throw new Error(`OneChat API Error: ${errorMessage}`); } else { - throw new Error(`Network or unexpected error: ${error.message}`); + throw new Error( + `Network or unexpected error: ${error.message}` + ); } } } } -module.exports = OneChat; \ No newline at end of file +module.exports = OneChat; From b3d149b70121626aa288982d3cf35a757fff41cf Mon Sep 17 00:00:00 2001 From: "Pargorn.Ru" Date: Fri, 17 Jan 2025 19:47:37 +0700 Subject: [PATCH 03/11] add English translations for OneChat Notification Provider --- src/lang/en.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lang/en.json b/src/lang/en.json index e215f1031..991b122e5 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1051,5 +1051,8 @@ "RabbitMQ Password": "RabbitMQ Password", "rabbitmqHelpText": "To use the monitor, you will need to enable the Management Plugin in your RabbitMQ setup. For more information, please consult the {rabitmq_documentation}.", "SendGrid API Key": "SendGrid API Key", - "Separate multiple email addresses with commas": "Separate multiple email addresses with commas" + "Separate multiple email addresses with commas": "Separate multiple email addresses with commas", + "OneChatAccessToken": "OneChat Access Token", + "OneChatUserIdOrGroupId": "OneChat User ID or Group ID", + "OneChatBotId": "OneChat Bot ID" } From b3e5d5ee8d95e0a93dd62d5a956a2b3c65398cee Mon Sep 17 00:00:00 2001 From: "Pargorn.Ru" Date: Fri, 17 Jan 2025 19:58:02 +0700 Subject: [PATCH 04/11] fix missing newline at end of OneChat.vue --- src/components/notifications/OneChat.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/notifications/OneChat.vue b/src/components/notifications/OneChat.vue index 93457f6a9..e503fb1d8 100644 --- a/src/components/notifications/OneChat.vue +++ b/src/components/notifications/OneChat.vue @@ -45,4 +45,4 @@ /> - \ No newline at end of file + From f0eaa46a022d7e66fdbf0c56d95455c44ec49b31 Mon Sep 17 00:00:00 2001 From: "Pargorn.Ru" Date: Fri, 17 Jan 2025 20:11:09 +0700 Subject: [PATCH 05/11] add link to OneChat documentation in OneChat.vue --- src/components/notifications/OneChat.vue | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/notifications/OneChat.vue b/src/components/notifications/OneChat.vue index e503fb1d8..c0e08d472 100644 --- a/src/components/notifications/OneChat.vue +++ b/src/components/notifications/OneChat.vue @@ -44,5 +44,12 @@ required /> + + + From 28f4fb233fff18c5e089c3cf46175bd9e9c51831 Mon Sep 17 00:00:00 2001 From: "Pargorn.Ru" Date: Sat, 25 Jan 2025 15:39:32 +0700 Subject: [PATCH 06/11] remove comments --- server/notification-providers/onechat.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/notification-providers/onechat.js b/server/notification-providers/onechat.js index e2f170049..463ef9786 100644 --- a/server/notification-providers/onechat.js +++ b/server/notification-providers/onechat.js @@ -19,7 +19,6 @@ class OneChat extends NotificationProvider { Authorization: "Bearer " + notification.accessToken, }, }; - // Send a test message if the monitor is null if (heartbeatJSON == null) { const testMessage = { to: notification.recieverId, From 89a2ae8e91af0f5a9caabaad6d7ff6915e59ce29 Mon Sep 17 00:00:00 2001 From: Pargorn Ruasijan Date: Sat, 25 Jan 2025 15:50:57 +0700 Subject: [PATCH 07/11] Update server/notification-providers/onechat.js Co-authored-by: Frank Elsinga --- server/notification-providers/onechat.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/server/notification-providers/onechat.js b/server/notification-providers/onechat.js index 463ef9786..0c675b961 100644 --- a/server/notification-providers/onechat.js +++ b/server/notification-providers/onechat.js @@ -33,17 +33,11 @@ class OneChat extends NotificationProvider { bot_id: notification.botId, type: "text", message: - "UptimeKuma Alert:\n" + - "[🔴 Down]\n" + - "Name: " + - monitorJSON["name"] + - "\n" + - heartbeatJSON["msg"] + - "\n" + - "Time (" + - heartbeatJSON["timezone"] + - "): " + - heartbeatJSON["localDateTime"], + `UptimeKuma Alert: +[🔴 Down] +Name: ${monitorJSON["name"]} +${heartbeatJSON["msg"]} +Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, }; await axios.post(url, downMessage, config); } else if (heartbeatJSON["status"] === UP) { From e3aaceef3f0b9d56475abe103e97a40907f5fa18 Mon Sep 17 00:00:00 2001 From: Pargorn Ruasijan Date: Sat, 25 Jan 2025 15:58:30 +0700 Subject: [PATCH 08/11] Update server/notification-providers/onechat.js Co-authored-by: Frank Elsinga --- server/notification-providers/onechat.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/server/notification-providers/onechat.js b/server/notification-providers/onechat.js index 0c675b961..b2d361f09 100644 --- a/server/notification-providers/onechat.js +++ b/server/notification-providers/onechat.js @@ -46,17 +46,11 @@ Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, bot_id: notification.botId, type: "text", message: - "UptimeKuma Alert:\n" + - "[🟢 Up]\n" + - "Name: " + - monitorJSON["name"] + - "\n" + - heartbeatJSON["msg"] + - "\n" + - "Time (" + - heartbeatJSON["timezone"] + - "): " + - heartbeatJSON["localDateTime"], + `UptimeKuma Alert: +[🟢 Up] +Name: ${monitorJSON["name"]} +${heartbeatJSON["msg"]} +Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, }; await axios.post(url, upMessage, config); } From 46e3daef26289d32a9c87c217306b12079531607 Mon Sep 17 00:00:00 2001 From: Pargorn Ruasijan Date: Sat, 25 Jan 2025 15:58:40 +0700 Subject: [PATCH 09/11] Update server/notification-providers/onechat.js Co-authored-by: Frank Elsinga --- server/notification-providers/onechat.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/notification-providers/onechat.js b/server/notification-providers/onechat.js index b2d361f09..2d6ea1d5b 100644 --- a/server/notification-providers/onechat.js +++ b/server/notification-providers/onechat.js @@ -64,9 +64,7 @@ Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, "Unknown API error occurred."; throw new Error(`OneChat API Error: ${errorMessage}`); } else { - throw new Error( - `Network or unexpected error: ${error.message}` - ); + this.throwGeneralAxiosError(error); } } } From 401d74caccdefc9a5372cb83bd3d4de3e358c263 Mon Sep 17 00:00:00 2001 From: "Pargorn.Ru" Date: Sat, 25 Jan 2025 16:28:34 +0700 Subject: [PATCH 10/11] Use HiddenInput for secret values and clarify Access Token --- src/components/notifications/OneChat.vue | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/notifications/OneChat.vue b/src/components/notifications/OneChat.vue index c0e08d472..6cee9c3a8 100644 --- a/src/components/notifications/OneChat.vue +++ b/src/components/notifications/OneChat.vue @@ -3,15 +3,13 @@
- + :required="true" +

{{ $t("OneChatAccessToken") }}

@@ -53,3 +51,13 @@
+ + \ No newline at end of file From 19d19cab9899e4af5c579c3cbd7841bbf2d0d457 Mon Sep 17 00:00:00 2001 From: "Pargorn.Ru" Date: Sat, 25 Jan 2025 16:33:02 +0700 Subject: [PATCH 11/11] fix ESLint issues in OneChat.vue --- src/components/notifications/OneChat.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/notifications/OneChat.vue b/src/components/notifications/OneChat.vue index 6cee9c3a8..b954d338b 100644 --- a/src/components/notifications/OneChat.vue +++ b/src/components/notifications/OneChat.vue @@ -9,6 +9,7 @@ id="onechat-access-token" v-model="$parent.notification.accessToken" :required="true" + >

{{ $t("OneChatAccessToken") }}

@@ -60,4 +61,4 @@ export default { HiddenInput, }, }; - \ No newline at end of file +