summaryrefslogtreecommitdiffstats
path: root/server/notification-providers/cellsynt.js
blob: e842237b6a06e85ae65a92694086b7f5931eff50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class Cellsynt extends NotificationProvider {
    name = "Cellsynt";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        const data = {
            // docs at https://www.cellsynt.com/en/sms/api-integration
            params: {
                "username": notification.cellsyntLogin,
                "password": notification.cellsyntPassword,
                "destination": notification.cellsyntDestination,
                "text": msg.replace(/[^\x00-\x7F]/g, ""),
                "originatortype": notification.cellsyntOriginatortype,
                "originator": notification.cellsyntOriginator,
                "allowconcat": notification.cellsyntAllowLongSMS ? 6 : 1
            }
        };
        try {
            const resp = await axios.post("https://se-1.cellsynt.net/sms.php", null, data);
            if (resp.data == null ) {
                throw new Error("Could not connect to Cellsynt, please try again.");
            } else if (resp.data.includes("Error:")) {
                resp.data = resp.data.replaceAll("Error:", "");
                throw new Error(resp.data);
            }
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Cellsynt;