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,