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