2023-07-14 08:29:35 +02:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
|
|
|
|
class SMSC extends NotificationProvider {
|
|
|
|
name = "smsc";
|
|
|
|
|
2023-08-11 09:46:41 +02:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2023-07-14 08:29:35 +02:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 15:21:15 +02:00
|
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
const url = "https://smsc.kz/sys/send.php?";
|
|
|
|
|
2023-07-14 08:29:35 +02:00
|
|
|
try {
|
|
|
|
let config = {
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Accept": "text/json",
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let getArray = [
|
|
|
|
"fmt=3",
|
|
|
|
"translit=" + notification.smscTranslit,
|
|
|
|
"login=" + notification.smscLogin,
|
|
|
|
"psw=" + notification.smscPassword,
|
|
|
|
"phones=" + notification.smscToNumber,
|
|
|
|
"mes=" + encodeURIComponent(msg.replace(/[^\x00-\x7F]/g, "")),
|
|
|
|
];
|
|
|
|
if (notification.smscSenderName !== "") {
|
|
|
|
getArray.push("sender=" + notification.smscSenderName);
|
|
|
|
}
|
|
|
|
|
2024-03-14 15:21:15 +02:00
|
|
|
let resp = await axios.get(url + getArray.join("&"), config);
|
2023-07-14 08:29:35 +02:00
|
|
|
if (resp.data.id === undefined) {
|
|
|
|
let error = `Something gone wrong. Api returned code ${resp.data.error_code}: ${resp.data.error}`;
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = SMSC;
|