diff --git a/server/notification-providers/whapi.js b/server/notification-providers/whapi.js new file mode 100644 index 00000000..8153753a --- /dev/null +++ b/server/notification-providers/whapi.js @@ -0,0 +1,46 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class Whapi extends NotificationProvider { + + name = "whapi"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + + let okMsg = "Sent Successfully."; + + let apiUrl = notification.whapiApiUrl; + let apiToken = notification.whapiAuthToken; + let toNumber = notification.whapiToNumber; + + try { + + let config = { + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + "Authorization": "Bearer " + apiToken, + } + }; + + let data = { + "to": toNumber + "@s.whatsapp.net", + "body": msg, + }; + + let url = apiUrl + "/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 5e76d6eb..1c2abec1 100644 --- a/server/notification.js +++ b/server/notification.js @@ -54,6 +54,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"); class Notification { @@ -124,7 +125,8 @@ class Notification { new Webhook(), new WeCom(), new GoAlert(), - new ZohoCliq() + new ZohoCliq(), + new Whapi(), ]; for (let item of list) { if (! item.name) { diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 57a2fdf2..0377847e 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -151,7 +151,8 @@ export default { "Splunk": "Splunk", "webhook": "Webhook", "GoAlert": "GoAlert", - "ZohoCliq": "ZohoCliq" + "ZohoCliq": "ZohoCliq", + "whapi": "Whapi", }; // 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 00000000..ff348791 --- /dev/null +++ b/src/components/notifications/Whapi.vue @@ -0,0 +1,23 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 0606d41a..b2fe4556 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -52,6 +52,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"; /** * Manage all notification form. @@ -111,7 +112,8 @@ const NotificationFormList = { "WeCom": WeCom, "GoAlert": GoAlert, "ServerChan": ServerChan, - "ZohoCliq": ZohoCliq + "ZohoCliq": ZohoCliq, + "whapi": Whapi, }; export default NotificationFormList; diff --git a/src/lang/en.json b/src/lang/en.json index c003de74..8f63323e 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -882,5 +882,6 @@ "useRemoteBrowser": "Use a Remote Browser", "deleteRemoteBrowserMessage": "Are you sure want to delete this Remote Browser for all monitors?", "GrafanaOncallUrl": "Grafana Oncall URL", - "Browser Screenshot": "Browser Screenshot" + "Browser Screenshot": "Browser Screenshot", + "wayToWriteWhapiPhoneNumber": "The phone number with the international prefix, but without the plus sign at the start" }