2021-09-07 14:42:46 +00:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
|
|
|
|
class Pushover extends NotificationProvider {
|
|
|
|
|
|
|
|
name = "pushover";
|
|
|
|
|
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2021-10-05 19:40:59 +00:00
|
|
|
let okMsg = "Sent Successfully.";
|
2021-11-29 09:19:55 +00:00
|
|
|
let pushoverlink = "https://api.pushover.net/1/messages.json";
|
2021-09-07 14:42:46 +00:00
|
|
|
|
2022-03-24 04:14:17 +00:00
|
|
|
let data = {
|
2023-01-21 05:59:11 +00:00
|
|
|
"message": msg,
|
2022-03-24 04:14:17 +00:00
|
|
|
"user": notification.pushoveruserkey,
|
|
|
|
"token": notification.pushoverapptoken,
|
|
|
|
"sound": notification.pushoversounds,
|
|
|
|
"priority": notification.pushoverpriority,
|
|
|
|
"title": notification.pushovertitle,
|
|
|
|
"retry": "30",
|
|
|
|
"expire": "3600",
|
|
|
|
"html": 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (notification.pushoverdevice) {
|
|
|
|
data.device = notification.pushoverdevice;
|
|
|
|
}
|
2023-05-16 16:31:28 +00:00
|
|
|
if (notification.pushoverttl) {
|
|
|
|
data.ttl = notification.pushoverttl;
|
|
|
|
}
|
2022-03-24 04:14:17 +00:00
|
|
|
|
2021-09-07 14:42:46 +00:00
|
|
|
try {
|
|
|
|
if (heartbeatJSON == null) {
|
2022-03-24 04:14:17 +00:00
|
|
|
await axios.post(pushoverlink, data);
|
|
|
|
return okMsg;
|
|
|
|
} else {
|
2023-05-29 17:24:40 +00:00
|
|
|
data.message += `\n<b>Time (${heartbeatJSON["timezone"]})</b>:${heartbeatJSON["localDateTime"]}`;
|
2021-11-29 09:19:55 +00:00
|
|
|
await axios.post(pushoverlink, data);
|
2021-09-07 14:42:46 +00:00
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2021-11-29 09:19:55 +00:00
|
|
|
this.throwGeneralAxiosError(error);
|
2021-09-07 14:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Pushover;
|