Add Whapi notification provider

pull/4323/head
edo2313 11 months ago
parent 0060e46b91
commit e8e7c7afb0
No known key found for this signature in database

@ -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;

@ -54,6 +54,7 @@ const GoAlert = require("./notification-providers/goalert");
const SMSManager = require("./notification-providers/smsmanager"); const SMSManager = require("./notification-providers/smsmanager");
const ServerChan = require("./notification-providers/serverchan"); const ServerChan = require("./notification-providers/serverchan");
const ZohoCliq = require("./notification-providers/zoho-cliq"); const ZohoCliq = require("./notification-providers/zoho-cliq");
const Whapi = require("./notification-providers/whapi");
class Notification { class Notification {
@ -124,7 +125,8 @@ class Notification {
new Webhook(), new Webhook(),
new WeCom(), new WeCom(),
new GoAlert(), new GoAlert(),
new ZohoCliq() new ZohoCliq(),
new Whapi(),
]; ];
for (let item of list) { for (let item of list) {
if (! item.name) { if (! item.name) {

@ -151,7 +151,8 @@ export default {
"Splunk": "Splunk", "Splunk": "Splunk",
"webhook": "Webhook", "webhook": "Webhook",
"GoAlert": "GoAlert", "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 // Put notifications here if it's not supported in most regions or its documentation is not in English

@ -0,0 +1,23 @@
<template>
<div class="mb-3">
<label for="whapi-api-url" class="form-label">{{ $t("API URL") }}</label>
<input id="whapi-api-url" v-model="$parent.notification.whapiApiUrl" type="text" class="form-control" required>
</div>
<div class="mb-3">
<label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
<input id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" type="text" class="form-control" required>
</div>
<div class="mb-3">
<label for="whapi-to-number" class="form-label">{{ $t("Phone number") }}</label>
<input id="whapi-to-number" v-model="$parent.notification.whapiToNumber" type="text" pattern="^[\d-]{10,31}(@[\w\.]{1,})?$" class="form-control" required>
<i18n-t tag="div" keypath="wayToWriteWhapiPhoneNumber" class="form-text"></i18n-t>
</div>
<div class="mb-3">
<i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
<a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
</i18n-t>
</div>
</template>

@ -52,6 +52,7 @@ import WeCom from "./WeCom.vue";
import GoAlert from "./GoAlert.vue"; import GoAlert from "./GoAlert.vue";
import ZohoCliq from "./ZohoCliq.vue"; import ZohoCliq from "./ZohoCliq.vue";
import Splunk from "./Splunk.vue"; import Splunk from "./Splunk.vue";
import Whapi from "./Whapi.vue";
/** /**
* Manage all notification form. * Manage all notification form.
@ -111,7 +112,8 @@ const NotificationFormList = {
"WeCom": WeCom, "WeCom": WeCom,
"GoAlert": GoAlert, "GoAlert": GoAlert,
"ServerChan": ServerChan, "ServerChan": ServerChan,
"ZohoCliq": ZohoCliq "ZohoCliq": ZohoCliq,
"whapi": Whapi,
}; };
export default NotificationFormList; export default NotificationFormList;

@ -882,5 +882,6 @@
"useRemoteBrowser": "Use a Remote Browser", "useRemoteBrowser": "Use a Remote Browser",
"deleteRemoteBrowserMessage": "Are you sure want to delete this Remote Browser for all monitors?", "deleteRemoteBrowserMessage": "Are you sure want to delete this Remote Browser for all monitors?",
"GrafanaOncallUrl": "Grafana Oncall URL", "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"
} }

Loading…
Cancel
Save