diff options
Diffstat (limited to 'server/notification-providers/pushbullet.js')
-rw-r--r-- | server/notification-providers/pushbullet.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/server/notification-providers/pushbullet.js b/server/notification-providers/pushbullet.js new file mode 100644 index 0000000..0b73031 --- /dev/null +++ b/server/notification-providers/pushbullet.js @@ -0,0 +1,56 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +const { DOWN, UP } = require("../../src/util"); + +class Pushbullet extends NotificationProvider { + name = "pushbullet"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + const url = "https://api.pushbullet.com/v2/pushes"; + + try { + let config = { + headers: { + "Access-Token": notification.pushbulletAccessToken, + "Content-Type": "application/json" + } + }; + if (heartbeatJSON == null) { + let data = { + "type": "note", + "title": "Uptime Kuma Alert", + "body": msg, + }; + await axios.post(url, data, config); + } else if (heartbeatJSON["status"] === DOWN) { + let downData = { + "type": "note", + "title": "UptimeKuma Alert: " + monitorJSON["name"], + "body": "[🔴 Down] " + + heartbeatJSON["msg"] + + `\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, + }; + await axios.post(url, downData, config); + } else if (heartbeatJSON["status"] === UP) { + let upData = { + "type": "note", + "title": "UptimeKuma Alert: " + monitorJSON["name"], + "body": "[✅ Up] " + + heartbeatJSON["msg"] + + `\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`, + }; + await axios.post(url, upData, config); + } + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Pushbullet; |