diff --git a/server/notification-providers/onechat.js b/server/notification-providers/onechat.js new file mode 100644 index 000000000..2d6ea1d5b --- /dev/null +++ b/server/notification-providers/onechat.js @@ -0,0 +1,73 @@ +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, + }, + }; + 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: +[🔴 Down] +Name: ${monitorJSON["name"]} +${heartbeatJSON["msg"]} +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: +[🟢 Up] +Name: ${monitorJSON["name"]} +${heartbeatJSON["msg"]} +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 { + this.throwGeneralAxiosError(error); + } + } + } +} + +module.exports = OneChat; 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..b954d338b --- /dev/null +++ b/src/components/notifications/OneChat.vue @@ -0,0 +1,64 @@ + + + + + + OneChat Access Token* + + + + + {{ $t("OneChatAccessToken") }} + + + + + + + {{ $t("OneChatUserIdOrGroupId") }}* + + + + + + + + {{ $t("OneChatBotId") }}* + + + + + + + + https://chat-develop.one.th/docs + + + + + + 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, 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" }
{{ $t("OneChatAccessToken") }}