From 65c97bfad2ef6c5cc5ea851242809591c976b771 Mon Sep 17 00:00:00 2001
From: Moqavem
Date: Tue, 26 Nov 2024 22:32:48 +0330
Subject: [PATCH 1/5] Add Bale notification provider
---
server/notification-providers/bale.js | 31 ++++++
server/notification.js | 40 +++++---
src/components/NotificationDialog.vue | 1 +
src/components/notifications/Bale.vue | 95 ++++++++++++++++++
src/components/notifications/index.js | 138 +++++++++++++-------------
src/lang/en.json | 3 +
6 files changed, 225 insertions(+), 83 deletions(-)
create mode 100644 server/notification-providers/bale.js
create mode 100644 src/components/notifications/Bale.vue
diff --git a/server/notification-providers/bale.js b/server/notification-providers/bale.js
new file mode 100644
index 000000000..46d234c73
--- /dev/null
+++ b/server/notification-providers/bale.js
@@ -0,0 +1,31 @@
+const NotificationProvider = require("./notification-provider");
+const axios = require("axios");
+
+class Bale extends NotificationProvider {
+ name = "bale";
+
+ /**
+ * @inheritdoc
+ */
+ async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
+ const okMsg = "Sent Successfully.";
+ const url = "https://tapi.bale.ai";
+
+ try {
+ await axios.post(
+ `${url}/bot${notification.baleBotToken}/sendMessage`,
+ { chat_id: notification.baleChatID, text: msg },
+ {
+ headers: {
+ "content-type": "application/json",
+ },
+ }
+ );
+ return okMsg;
+ } catch (error) {
+ this.throwGeneralAxiosError(error);
+ }
+ }
+}
+
+module.exports = Bale;
diff --git a/server/notification.js b/server/notification.js
index e7977eb4a..28496f9ae 100644
--- a/server/notification.js
+++ b/server/notification.js
@@ -4,6 +4,7 @@ const Alerta = require("./notification-providers/alerta");
const AlertNow = require("./notification-providers/alertnow");
const AliyunSms = require("./notification-providers/aliyun-sms");
const Apprise = require("./notification-providers/apprise");
+const Bale = require("./notification-providers/bale");
const Bark = require("./notification-providers/bark");
const Bitrix24 = require("./notification-providers/bitrix24");
const ClickSendSMS = require("./notification-providers/clicksendsms");
@@ -71,7 +72,6 @@ const Wpush = require("./notification-providers/wpush");
const SendGrid = require("./notification-providers/send-grid");
class Notification {
-
providerList = {};
/**
@@ -90,6 +90,7 @@ class Notification {
new AlertNow(),
new AliyunSms(),
new Apprise(),
+ new Bale(),
new Bark(),
new Bitrix24(),
new ClickSendSMS(),
@@ -154,10 +155,10 @@ class Notification {
new GtxMessaging(),
new Cellsynt(),
new Wpush(),
- new SendGrid()
+ new SendGrid(),
];
for (let item of list) {
- if (! item.name) {
+ if (!item.name) {
throw new Error("Notification provider without name");
}
@@ -177,9 +178,19 @@ class Notification {
* @returns {Promise} Successful msg
* @throws Error with fail msg
*/
- static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
+ static async send(
+ notification,
+ msg,
+ monitorJSON = null,
+ heartbeatJSON = null
+ ) {
if (this.providerList[notification.type]) {
- return this.providerList[notification.type].send(notification, msg, monitorJSON, heartbeatJSON);
+ return this.providerList[notification.type].send(
+ notification,
+ msg,
+ monitorJSON,
+ heartbeatJSON
+ );
} else {
throw new Error("Notification type is not supported");
}
@@ -201,10 +212,9 @@ class Notification {
userID,
]);
- if (! bean) {
+ if (!bean) {
throw new Error("notification not found");
}
-
} else {
bean = R.dispense("notification");
}
@@ -234,7 +244,7 @@ class Notification {
userID,
]);
- if (! bean) {
+ if (!bean) {
throw new Error("notification not found");
}
@@ -250,7 +260,6 @@ class Notification {
let exists = commandExistsSync("apprise");
return exists;
}
-
}
/**
@@ -261,16 +270,17 @@ class Notification {
*/
async function applyNotificationEveryMonitor(notificationID, userID) {
let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [
- userID
+ userID,
]);
for (let i = 0; i < monitors.length; i++) {
- let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [
- monitors[i].id,
- notificationID,
- ]);
+ let checkNotification = await R.findOne(
+ "monitor_notification",
+ " monitor_id = ? AND notification_id = ? ",
+ [monitors[i].id, notificationID]
+ );
- if (! checkNotification) {
+ if (!checkNotification) {
let relation = R.dispense("monitor_notification");
relation.monitor_id = monitors[i].id;
relation.notification_id = notificationID;
diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue
index f6d728029..307b09910 100644
--- a/src/components/NotificationDialog.vue
+++ b/src/components/NotificationDialog.vue
@@ -113,6 +113,7 @@ export default {
"alerta": "Alerta",
"AlertNow": "AlertNow",
"apprise": this.$t("apprise"),
+ "bale": "Bale",
"Bark": "Bark",
"Bitrix24": "Bitrix24",
"clicksendsms": "ClickSend SMS",
diff --git a/src/components/notifications/Bale.vue b/src/components/notifications/Bale.vue
new file mode 100644
index 000000000..032743da5
--- /dev/null
+++ b/src/components/notifications/Bale.vue
@@ -0,0 +1,95 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js
index efa2af5c4..d2e2364eb 100644
--- a/src/components/notifications/index.js
+++ b/src/components/notifications/index.js
@@ -2,6 +2,7 @@ import Alerta from "./Alerta.vue";
import AlertNow from "./AlertNow.vue";
import AliyunSMS from "./AliyunSms.vue";
import Apprise from "./Apprise.vue";
+import Bale from "./Bale.vue";
import Bark from "./Bark.vue";
import Bitrix24 from "./Bitrix24.vue";
import ClickSendSMS from "./ClickSendSMS.vue";
@@ -73,75 +74,76 @@ import SendGrid from "./SendGrid.vue";
* @type { Record }
*/
const NotificationFormList = {
- "alerta": Alerta,
- "AlertNow": AlertNow,
- "AliyunSMS": AliyunSMS,
- "apprise": Apprise,
- "Bark": Bark,
- "Bitrix24": Bitrix24,
- "clicksendsms": ClickSendSMS,
- "CallMeBot": CallMeBot,
- "smsc": SMSC,
- "DingDing": DingDing,
- "discord": Discord,
- "Elks": Elks,
- "Feishu": Feishu,
- "FreeMobile": FreeMobile,
- "GoogleChat": GoogleChat,
- "gorush": Gorush,
- "gotify": Gotify,
- "GrafanaOncall": GrafanaOncall,
- "HomeAssistant": HomeAssistant,
- "HeiiOnCall": HeiiOnCall,
- "Keep": Keep,
- "Kook": Kook,
- "line": Line,
- "LineNotify": LineNotify,
- "lunasea": LunaSea,
- "matrix": Matrix,
- "mattermost": Mattermost,
- "nostr": Nostr,
- "ntfy": Ntfy,
- "octopush": Octopush,
- "OneBot": OneBot,
- "Onesender": Onesender,
- "Opsgenie": Opsgenie,
- "PagerDuty": PagerDuty,
- "FlashDuty": FlashDuty,
- "PagerTree": PagerTree,
- "promosms": PromoSMS,
- "pushbullet": Pushbullet,
- "PushByTechulus": TechulusPush,
- "PushDeer": PushDeer,
- "pushover": Pushover,
- "pushy": Pushy,
+ alerta: Alerta,
+ AlertNow: AlertNow,
+ AliyunSMS: AliyunSMS,
+ apprise: Apprise,
+ bale: Bale,
+ Bark: Bark,
+ Bitrix24: Bitrix24,
+ clicksendsms: ClickSendSMS,
+ CallMeBot: CallMeBot,
+ smsc: SMSC,
+ DingDing: DingDing,
+ discord: Discord,
+ Elks: Elks,
+ Feishu: Feishu,
+ FreeMobile: FreeMobile,
+ GoogleChat: GoogleChat,
+ gorush: Gorush,
+ gotify: Gotify,
+ GrafanaOncall: GrafanaOncall,
+ HomeAssistant: HomeAssistant,
+ HeiiOnCall: HeiiOnCall,
+ Keep: Keep,
+ Kook: Kook,
+ line: Line,
+ LineNotify: LineNotify,
+ lunasea: LunaSea,
+ matrix: Matrix,
+ mattermost: Mattermost,
+ nostr: Nostr,
+ ntfy: Ntfy,
+ octopush: Octopush,
+ OneBot: OneBot,
+ Onesender: Onesender,
+ Opsgenie: Opsgenie,
+ PagerDuty: PagerDuty,
+ FlashDuty: FlashDuty,
+ PagerTree: PagerTree,
+ promosms: PromoSMS,
+ pushbullet: Pushbullet,
+ PushByTechulus: TechulusPush,
+ PushDeer: PushDeer,
+ pushover: Pushover,
+ pushy: Pushy,
"rocket.chat": RocketChat,
- "serwersms": SerwerSMS,
- "signal": Signal,
- "SIGNL4": SIGNL4,
- "SMSManager": SMSManager,
- "SMSPartner": SMSPartner,
- "slack": Slack,
- "squadcast": Squadcast,
- "SMSEagle": SMSEagle,
- "smtp": STMP,
- "stackfield": Stackfield,
- "teams": Teams,
- "telegram": Telegram,
- "threema": Threema,
- "twilio": Twilio,
- "Splunk": Splunk,
- "webhook": Webhook,
- "WeCom": WeCom,
- "GoAlert": GoAlert,
- "ServerChan": ServerChan,
- "ZohoCliq": ZohoCliq,
- "SevenIO": SevenIO,
- "whapi": Whapi,
- "gtxmessaging": GtxMessaging,
- "Cellsynt": Cellsynt,
- "WPush": WPush,
- "SendGrid": SendGrid,
+ serwersms: SerwerSMS,
+ signal: Signal,
+ SIGNL4: SIGNL4,
+ SMSManager: SMSManager,
+ SMSPartner: SMSPartner,
+ slack: Slack,
+ squadcast: Squadcast,
+ SMSEagle: SMSEagle,
+ smtp: STMP,
+ stackfield: Stackfield,
+ teams: Teams,
+ telegram: Telegram,
+ threema: Threema,
+ twilio: Twilio,
+ Splunk: Splunk,
+ webhook: Webhook,
+ WeCom: WeCom,
+ GoAlert: GoAlert,
+ ServerChan: ServerChan,
+ ZohoCliq: ZohoCliq,
+ SevenIO: SevenIO,
+ whapi: Whapi,
+ gtxmessaging: GtxMessaging,
+ Cellsynt: Cellsynt,
+ WPush: WPush,
+ SendGrid: SendGrid,
};
export default NotificationFormList;
diff --git a/src/lang/en.json b/src/lang/en.json
index e215f1031..b19a187ee 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -429,6 +429,9 @@
"trustProxyDescription": "Trust 'X-Forwarded-*' headers. If you want to get the correct client IP and your Uptime Kuma is behind a proxy such as Nginx or Apache, you should enable this.",
"wayToGetLineNotifyToken": "You can get an access token from {0}",
"Examples": "Examples",
+ "supportBaleChatID": "Support Direct Chat / Group / Channel's Chat ID",
+ "wayToGetBaleChatID": "You can get your chat ID by sending a message to the bot and going to this URL to view the chat_id:",
+ "wayToGetBaleToken": "You can get a token from {0}.",
"Home Assistant URL": "Home Assistant URL",
"Long-Lived Access Token": "Long-Lived Access Token",
"Long-Lived Access Token can be created by clicking on your profile name (bottom left) and scrolling to the bottom then click Create Token. ": "Long-Lived Access Token can be created by clicking on your profile name (bottom left) and scrolling to the bottom then click Create Token. ",
From 80caa6df46afe3bfe3c5113024d773e4d338a3bb Mon Sep 17 00:00:00 2001
From: Moqavem
Date: Tue, 26 Nov 2024 22:58:47 +0330
Subject: [PATCH 2/5] Update bale.js
---
server/notification-providers/bale.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/server/notification-providers/bale.js b/server/notification-providers/bale.js
index 46d234c73..28c03c7d1 100644
--- a/server/notification-providers/bale.js
+++ b/server/notification-providers/bale.js
@@ -14,7 +14,10 @@ class Bale extends NotificationProvider {
try {
await axios.post(
`${url}/bot${notification.baleBotToken}/sendMessage`,
- { chat_id: notification.baleChatID, text: msg },
+ {
+ chat_id: notification.baleChatID,
+ text: msg
+ },
{
headers: {
"content-type": "application/json",
From 62537cfad0c31bff03064a9482cd704220e55cde Mon Sep 17 00:00:00 2001
From: Moqavem
Date: Tue, 26 Nov 2024 23:01:31 +0330
Subject: [PATCH 3/5] Update bale.js
---
server/notification-providers/bale.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/server/notification-providers/bale.js b/server/notification-providers/bale.js
index 28c03c7d1..4b06ab27b 100644
--- a/server/notification-providers/bale.js
+++ b/server/notification-providers/bale.js
@@ -14,9 +14,9 @@ class Bale extends NotificationProvider {
try {
await axios.post(
`${url}/bot${notification.baleBotToken}/sendMessage`,
- {
- chat_id: notification.baleChatID,
- text: msg
+ {
+ chat_id: notification.baleChatID,
+ text: msg
},
{
headers: {
From dcff9d31b63c93fbbe2abc07963d41c6f8a2864f Mon Sep 17 00:00:00 2001
From: Moqavem
Date: Tue, 26 Nov 2024 23:06:02 +0330
Subject: [PATCH 4/5] Update notification.js
---
server/notification.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/server/notification.js b/server/notification.js
index 28496f9ae..7a1fd4ab6 100644
--- a/server/notification.js
+++ b/server/notification.js
@@ -277,7 +277,7 @@ async function applyNotificationEveryMonitor(notificationID, userID) {
let checkNotification = await R.findOne(
"monitor_notification",
" monitor_id = ? AND notification_id = ? ",
- [monitors[i].id, notificationID]
+ [ monitors[i].id, notificationID ]
);
if (!checkNotification) {
From 8cea234fabfea342c6cec4a7f4eb11b66dacc561 Mon Sep 17 00:00:00 2001
From: Moqavem
Date: Tue, 26 Nov 2024 23:07:02 +0330
Subject: [PATCH 5/5] Update Bale.vue
---
src/components/notifications/Bale.vue | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/components/notifications/Bale.vue b/src/components/notifications/Bale.vue
index 032743da5..ea69e21b1 100644
--- a/src/components/notifications/Bale.vue
+++ b/src/components/notifications/Bale.vue
@@ -28,9 +28,7 @@
{{ baleGetUpdatesURL("masked") }}
-
-