2021-10-24 15:17:29 -04:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
|
|
|
|
class ClickSendSMS extends NotificationProvider {
|
|
|
|
name = "clicksendsms";
|
|
|
|
|
2023-08-11 03:46:41 -04:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-10-24 15:17:29 -04:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 09:21:15 -04:00
|
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
const url = "https://rest.clicksend.com/v3/sms/send";
|
|
|
|
|
2021-10-24 15:17:29 -04:00
|
|
|
try {
|
|
|
|
let config = {
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
2022-04-13 12:30:32 -04:00
|
|
|
"Authorization": "Basic " + Buffer.from(notification.clicksendsmsLogin + ":" + notification.clicksendsmsPassword).toString("base64"),
|
2021-10-24 15:17:29 -04:00
|
|
|
"Accept": "text/json",
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let data = {
|
|
|
|
messages: [
|
|
|
|
{
|
|
|
|
"body": msg.replace(/[^\x00-\x7F]/g, ""),
|
2021-10-25 04:11:57 -04:00
|
|
|
"to": notification.clicksendsmsToNumber,
|
2021-10-24 15:17:29 -04:00
|
|
|
"source": "uptime-kuma",
|
|
|
|
"from": notification.clicksendsmsSenderName,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2024-03-14 09:21:15 -04:00
|
|
|
let resp = await axios.post(url, data, config);
|
2021-10-25 04:11:57 -04:00
|
|
|
if (resp.data.data.messages[0].status !== "SUCCESS") {
|
|
|
|
let error = "Something gone wrong. Api returned " + resp.data.data.messages[0].status + ".";
|
2021-10-24 15:17:29 -04:00
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ClickSendSMS;
|