Merge pull request #2980 from Genc/feature/twilio-notification-provider
Add Twilio Sms Notification Providerpull/2983/head
commit
4869e6531c
@ -0,0 +1,41 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
class Twilio extends NotificationProvider {
|
||||||
|
|
||||||
|
name = "twilio";
|
||||||
|
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
|
||||||
|
let okMsg = "Sent Successfully.";
|
||||||
|
|
||||||
|
let accountSID = notification.twilioAccountSID;
|
||||||
|
let authToken = notification.twilioAuthToken;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
let config = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
|
||||||
|
"Authorization": "Basic " + Buffer.from(accountSID + ":" + authToken).toString("base64"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let data = new URLSearchParams();
|
||||||
|
data.append("To", notification.twilioToNumber);
|
||||||
|
data.append("From", notification.twilioFromNumber);
|
||||||
|
data.append("Body", msg);
|
||||||
|
|
||||||
|
let url = "https://api.twilio.com/2010-04-01/Accounts/" + accountSID + "/Messages.json";
|
||||||
|
|
||||||
|
await axios.post(url, data, config);
|
||||||
|
|
||||||
|
return okMsg;
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Twilio;
|
@ -0,0 +1,27 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-account-sid" class="form-label">{{ $t("Account SID") }}</label>
|
||||||
|
<input id="twilio-account-sid" v-model="$parent.notification.twilioAccountSID" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-auth-token" class="form-label">{{ $t("Auth Token") }}</label>
|
||||||
|
<input id="twilio-auth-token" v-model="$parent.notification.twilioAuthToken" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-from-number" class="form-label">{{ $t("From Number") }}</label>
|
||||||
|
<input id="twilio-from-number" v-model="$parent.notification.twilioFromNumber" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="twilio-to-number" class="form-label">{{ $t("To Number") }}</label>
|
||||||
|
<input id="twilio-to-number" v-model="$parent.notification.twilioToNumber" type="text" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
|
||||||
|
<a href="https://www.twilio.com/docs/sms" target="_blank">https://www.twilio.com/docs/sms</a>
|
||||||
|
</i18n-t>
|
||||||
|
</div>
|
||||||
|
</template>
|
Loading…
Reference in new issue