summaryrefslogtreecommitdiffstats
path: root/server/notification-providers/46elks.js
blob: 4b15e9fad7875a8cce4e605d4ea736c0c130eb9a (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
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class Elks extends NotificationProvider {
    name = "Elks";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";
        const url = "https://api.46elks.com/a1/sms";

        try {
            let data = new URLSearchParams();
            data.append("from", notification.elksFromNumber);
            data.append("to", notification.elksToNumber );
            data.append("message", msg);

            const config = {
                headers: {
                    "Authorization": "Basic " + Buffer.from(`${notification.elksUsername}:${notification.elksAuthToken}`).toString("base64")
                }
            };

            await axios.post(url, data, config);

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Elks;