parent
0060e46b91
commit
e8e7c7afb0
@ -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;
|
@ -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>
|
Loading…
Reference in new issue