forked from louislam/uptime-kuma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request louislam#2980 from Genc/feature/twilio-notificatio…
…n-provider Add Twilio Sms Notification Provider
- Loading branch information
Showing
6 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters