summaryrefslogtreecommitdiffstats
path: root/server/notification-providers/smspartner.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/notification-providers/smspartner.js')
-rw-r--r--server/notification-providers/smspartner.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/server/notification-providers/smspartner.js b/server/notification-providers/smspartner.js
new file mode 100644
index 0000000..5595217
--- /dev/null
+++ b/server/notification-providers/smspartner.js
@@ -0,0 +1,46 @@
+const NotificationProvider = require("./notification-provider");
+const axios = require("axios");
+
+class SMSPartner extends NotificationProvider {
+ name = "SMSPartner";
+
+ /**
+ * @inheritdoc
+ */
+ async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
+ const okMsg = "Sent Successfully.";
+ const url = "https://api.smspartner.fr/v1/send";
+
+ try {
+ // smspartner does not support non ascii characters and only a maximum 639 characters
+ let cleanMsg = msg.replace(/[^\x00-\x7F]/g, "").substring(0, 639);
+
+ let data = {
+ "apiKey": notification.smspartnerApikey,
+ "sender": notification.smspartnerSenderName.substring(0, 11),
+ "phoneNumbers": notification.smspartnerPhoneNumber,
+ "message": cleanMsg,
+ };
+
+ let config = {
+ headers: {
+ "Content-Type": "application/json",
+ "cache-control": "no-cache",
+ "Accept": "application/json",
+ }
+ };
+
+ let resp = await axios.post(url, data, config);
+
+ if (resp.data.success !== true) {
+ throw Error(`Api returned ${resp.data.response.status}.`);
+ }
+
+ return okMsg;
+ } catch (error) {
+ this.throwGeneralAxiosError(error);
+ }
+ }
+}
+
+module.exports = SMSPartner;