diff options
author | Daniel Baumann <daniel@debian.org> | 2024-11-26 09:28:28 +0100 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-11-26 12:25:58 +0100 |
commit | a1882b67c41fe9901a0cd8059b5cc78a5beadec0 (patch) | |
tree | 2a24507c67aa99a15416707b2f7e645142230ed8 /server/notification-providers/smseagle.js | |
parent | Initial commit. (diff) | |
download | uptime-kuma-a1882b67c41fe9901a0cd8059b5cc78a5beadec0.tar.xz uptime-kuma-a1882b67c41fe9901a0cd8059b5cc78a5beadec0.zip |
Adding upstream version 2.0.0~beta.0+dfsg.upstream/2.0.0_beta.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'server/notification-providers/smseagle.js')
-rw-r--r-- | server/notification-providers/smseagle.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/server/notification-providers/smseagle.js b/server/notification-providers/smseagle.js new file mode 100644 index 0000000..4e89700 --- /dev/null +++ b/server/notification-providers/smseagle.js @@ -0,0 +1,73 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class SMSEagle extends NotificationProvider { + name = "SMSEagle"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + + try { + let config = { + headers: { + "Content-Type": "application/json", + } + }; + + let postData; + let sendMethod; + let recipientType; + + let encoding = (notification.smseagleEncoding) ? "1" : "0"; + let priority = (notification.smseaglePriority) ? notification.smseaglePriority : "0"; + + if (notification.smseagleRecipientType === "smseagle-contact") { + recipientType = "contactname"; + sendMethod = "sms.send_tocontact"; + } + if (notification.smseagleRecipientType === "smseagle-group") { + recipientType = "groupname"; + sendMethod = "sms.send_togroup"; + } + if (notification.smseagleRecipientType === "smseagle-to") { + recipientType = "to"; + sendMethod = "sms.send_sms"; + } + + let params = { + access_token: notification.smseagleToken, + [recipientType]: notification.smseagleRecipient, + message: msg, + responsetype: "extended", + unicode: encoding, + highpriority: priority + }; + + postData = { + method: sendMethod, + params: params + }; + + let resp = await axios.post(notification.smseagleUrl + "/jsonrpc/sms", postData, config); + + if ((JSON.stringify(resp.data)).indexOf("message_id") === -1) { + let error = ""; + if (resp.data.result && resp.data.result.error_text) { + error = `SMSEagle API returned error: ${JSON.stringify(resp.data.result.error_text)}`; + } else { + error = "SMSEagle API returned an unexpected response"; + } + throw new Error(error); + } + + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = SMSEagle; |