uptime-kuma/server/notification-providers/twilio.js
Frank Elsinga 0f61d7ee1b
chore: enable formatting over the entire codebase in CI (#6655)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-01-09 02:10:36 +01:00

47 lines
1.5 KiB
JavaScript

const NotificationProvider = require("./notification-provider");
const axios = require("axios");
class Twilio extends NotificationProvider {
name = "twilio";
/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";
let apiKey = notification.twilioApiKey ? notification.twilioApiKey : notification.twilioAccountSID;
try {
let config = {
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
Authorization:
"Basic " + Buffer.from(apiKey + ":" + notification.twilioAuthToken).toString("base64"),
},
};
config = this.getAxiosConfigWithProxy(config);
let data = new URLSearchParams();
data.append("To", notification.twilioToNumber);
data.append("From", notification.twilioFromNumber);
data.append("Body", msg);
if (notification.twilioMessagingServiceSID) {
data.append("MessagingServiceSid", notification.twilioMessagingServiceSID);
}
await axios.post(
`https://api.twilio.com/2010-04-01/Accounts/${notification.twilioAccountSID}/Messages.json`,
data,
config
);
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = Twilio;