summaryrefslogtreecommitdiffstats
path: root/server/notification-providers/smsc.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/notification-providers/smsc.js')
-rw-r--r--server/notification-providers/smsc.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/server/notification-providers/smsc.js b/server/notification-providers/smsc.js
new file mode 100644
index 0000000..89f01d0
--- /dev/null
+++ b/server/notification-providers/smsc.js
@@ -0,0 +1,47 @@
+const NotificationProvider = require("./notification-provider");
+const axios = require("axios");
+
+class SMSC extends NotificationProvider {
+ name = "smsc";
+
+ /**
+ * @inheritdoc
+ */
+ async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
+ const okMsg = "Sent Successfully.";
+ const url = "https://smsc.kz/sys/send.php?";
+
+ 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);
+ }
+
+ let resp = await axios.get(url + getArray.join("&"), config);
+ 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;