From 822ce5384b1c138ccea7a20112363358cdb67083 Mon Sep 17 00:00:00 2001 From: Edoardo Ridolfi <32812884+edo2313@users.noreply.github.com> Date: Wed, 3 Apr 2024 02:22:01 +0200 Subject: [PATCH] Add support for Whapi notification provider (#4323) Co-authored-by: Frank Elsinga --- server/notification-providers/whapi.js | 39 ++++++++++++++++++++++++++ server/notification.js | 2 ++ src/components/NotificationDialog.vue | 3 +- src/components/notifications/Whapi.vue | 33 ++++++++++++++++++++++ src/components/notifications/index.js | 2 ++ src/lang/en.json | 4 +++ 6 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 server/notification-providers/whapi.js create mode 100644 src/components/notifications/Whapi.vue diff --git a/server/notification-providers/whapi.js b/server/notification-providers/whapi.js new file mode 100644 index 000000000..70e0fbb4c --- /dev/null +++ b/server/notification-providers/whapi.js @@ -0,0 +1,39 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class Whapi extends NotificationProvider { + name = "whapi"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + + try { + const config = { + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + "Authorization": "Bearer " + notification.whapiAuthToken, + } + }; + + let data = { + "to": notification.whapiRecipient, + "body": msg, + }; + + let url = (notification.whapiApiUrl || "https://gate.whapi.cloud/").replace(/\/+$/, "") + "/messages/text"; + + await axios.post(url, data, config); + + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } + +} + +module.exports = Whapi; diff --git a/server/notification.js b/server/notification.js index 6f1c35d18..f5a952061 100644 --- a/server/notification.js +++ b/server/notification.js @@ -56,6 +56,7 @@ const GoAlert = require("./notification-providers/goalert"); const SMSManager = require("./notification-providers/smsmanager"); const ServerChan = require("./notification-providers/serverchan"); const ZohoCliq = require("./notification-providers/zoho-cliq"); +const Whapi = require("./notification-providers/whapi"); const GtxMessaging = require("./notification-providers/gtx-messaging"); const Cellsynt = require("./notification-providers/cellsynt"); @@ -131,6 +132,7 @@ class Notification { new WeCom(), new GoAlert(), new ZohoCliq(), + new Whapi(), new GtxMessaging(), new Cellsynt(), ]; diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 6538f4eaa..f57e0628a 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -154,8 +154,9 @@ export default { "webhook": "Webhook", "GoAlert": "GoAlert", "ZohoCliq": "ZohoCliq", + "whapi": "WhatsApp (Whapi)", "gtxmessaging": "GtxMessaging", - "Cellsynt": "Cellsynt" + "Cellsynt": "Cellsynt", }; // Put notifications here if it's not supported in most regions or its documentation is not in English diff --git a/src/components/notifications/Whapi.vue b/src/components/notifications/Whapi.vue new file mode 100644 index 000000000..4c92ad2c3 --- /dev/null +++ b/src/components/notifications/Whapi.vue @@ -0,0 +1,33 @@ + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 821652e24..458322384 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -55,6 +55,7 @@ import WeCom from "./WeCom.vue"; import GoAlert from "./GoAlert.vue"; import ZohoCliq from "./ZohoCliq.vue"; import Splunk from "./Splunk.vue"; +import Whapi from "./Whapi.vue"; import Cellsynt from "./Cellsynt.vue"; /** @@ -118,6 +119,7 @@ const NotificationFormList = { "GoAlert": GoAlert, "ServerChan": ServerChan, "ZohoCliq": ZohoCliq, + "whapi": Whapi, "gtxmessaging": GtxMessaging, "Cellsynt": Cellsynt, }; diff --git a/src/lang/en.json b/src/lang/en.json index 8fb04ae69..21b0eec70 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -885,6 +885,10 @@ "deleteRemoteBrowserMessage": "Are you sure want to delete this Remote Browser for all monitors?", "GrafanaOncallUrl": "Grafana Oncall URL", "Browser Screenshot": "Browser Screenshot", + "wayToWriteWhapiRecipient": "The phone number with the international prefix, but without the plus sign at the start ({0}), the Contact ID ({1}) or the Group ID ({2}).", + "wayToGetWhapiUrlAndToken": "You can get the API URL and the token by going into your desired channel from {0}", + "whapiRecipient": "Phone Number / Contact ID / Group ID", + "API URL": "API URL", "What is a Remote Browser?": "What is a Remote Browser?", "wayToGetHeiiOnCallDetails": "How to get the Trigger ID and API Keys is explained in the {documentation}", "documentationOf": "{0} Documentation",