mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-24 23:34:03 +00:00
8a92054c2b
* Added JSDoc to eslint rules Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> * Fixed JSDoc eslint errors Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> * Update the check-linters workflow to Node.js 20 --------- Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
|
|
class PromoSMS extends NotificationProvider {
|
|
|
|
name = "promosms";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
let okMsg = "Sent Successfully.";
|
|
|
|
if (notification.promosmsAllowLongSMS === undefined) {
|
|
notification.promosmsAllowLongSMS = false;
|
|
}
|
|
|
|
//TODO: Add option for enabling special characters. It will decrese message max length from 160 to 70 chars.
|
|
//Lets remove non ascii char
|
|
let cleanMsg = msg.replace(/[^\x00-\x7F]/g, "");
|
|
|
|
try {
|
|
let config = {
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"Authorization": "Basic " + Buffer.from(notification.promosmsLogin + ":" + notification.promosmsPassword).toString("base64"),
|
|
"Accept": "text/json",
|
|
}
|
|
};
|
|
let data = {
|
|
"recipients": [ notification.promosmsPhoneNumber ],
|
|
//Trim message to maximum length of 1 SMS or 4 if we allowed long messages
|
|
"text": notification.promosmsAllowLongSMS ? cleanMsg.substring(0, 639) : cleanMsg.substring(0, 159),
|
|
"long-sms": notification.promosmsAllowLongSMS,
|
|
"type": Number(notification.promosmsSMSType),
|
|
"sender": notification.promosmsSenderName
|
|
};
|
|
|
|
let resp = await axios.post("https://promosms.com/api/rest/v3_2/sms", data, config);
|
|
|
|
if (resp.data.response.status !== 0) {
|
|
let error = "Something gone wrong. Api returned " + resp.data.response.status + ".";
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
|
|
return okMsg;
|
|
} catch (error) {
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = PromoSMS;
|