2021-10-07 22:56:32 +03:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
|
|
|
|
class PromoSMS extends NotificationProvider {
|
|
|
|
|
|
|
|
name = "promosms";
|
|
|
|
|
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
|
|
let okMsg = "Sent Successfully.";
|
|
|
|
|
|
|
|
try {
|
|
|
|
let config = {
|
|
|
|
headers: {
|
2021-10-08 10:11:13 +03:00
|
|
|
"Content-Type": "application/json",
|
2022-04-13 19:30:32 +03:00
|
|
|
"Authorization": "Basic " + Buffer.from(notification.promosmsLogin + ":" + notification.promosmsPassword).toString("base64"),
|
2021-10-08 10:11:13 +03:00
|
|
|
"Accept": "text/json",
|
2021-10-07 22:56:32 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
let data = {
|
2021-10-08 10:11:13 +03:00
|
|
|
"recipients": [ notification.promosmsPhoneNumber ],
|
2021-10-07 22:56:32 +03:00
|
|
|
//Lets remove non ascii char
|
|
|
|
"text": msg.replace(/[^\x00-\x7F]/g, ""),
|
2021-10-08 10:11:13 +03:00
|
|
|
"type": Number(notification.promosmsSMSType),
|
2021-10-07 22:56:32 +03:00
|
|
|
"sender": notification.promosmsSenderName
|
|
|
|
};
|
|
|
|
|
2021-10-08 12:49:12 +03:00
|
|
|
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);
|
|
|
|
}
|
2022-04-13 19:30:32 +03:00
|
|
|
|
2021-10-07 22:56:32 +03:00
|
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = PromoSMS;
|