Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Whapi notification provider #4323

Merged
merged 8 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions server/notification-providers/whapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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.";

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;
4 changes: 3 additions & 1 deletion server/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/NotificationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions src/components/notifications/Whapi.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<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" placeholder="https://gate.whapi.cloud/" type="text" class="form-control">
</div>

<div class="mb-3">
<label for="whapi-auth-token" class="form-label">{{ $t("Token") }}</label>
<HiddenInput id="whapi-auth-token" v-model="$parent.notification.whapiAuthToken" :required="true" autocomplete="new-password"></HiddenInput>
<i18n-t tag="div" keypath="wayToGetWhapiUrlAndToken" class="form-text">
<a href="https://panel.whapi.cloud/dashboard" target="_blank">https://panel.whapi.cloud/dashboard</a>
</i18n-t>
</div>

<div class="mb-3">
<label for="whapi-recipient" class="form-label">{{ $t("whapiRecipient") }}</label>
<input id="whapi-recipient" v-model="$parent.notification.whapiRecipient" type="text" pattern="^[\d-]{10,31}(@[\w\.]{1,})?$" class="form-control" required>
<div class="form-text">{{ $t("wayToWriteWhapiRecipient", ["00117612345678", "[email protected]", "[email protected]"]) }}</div>
</div>

<i18n-t tag="div" keypath="More info on:" class="mb-3 form-text">
<a href="https://whapi.cloud/" target="_blank">https://whapi.cloud/</a>
</i18n-t>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";

export default {
components: {
HiddenInput,
}
};
</script>
4 changes: 3 additions & 1 deletion src/components/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -111,7 +112,8 @@ const NotificationFormList = {
"WeCom": WeCom,
"GoAlert": GoAlert,
"ServerChan": ServerChan,
"ZohoCliq": ZohoCliq
"ZohoCliq": ZohoCliq,
"whapi": Whapi,
};

export default NotificationFormList;
6 changes: 5 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -882,5 +882,9 @@
"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",
"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"
}
Loading