2024-08-27 18:24:29 -07:00
|
|
|
const { getMonitorRelativeURL } = require("../../src/util");
|
|
|
|
const { setting } = require("../util-server");
|
|
|
|
|
2021-09-07 07:42:46 -07:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
|
|
|
|
class Pushover extends NotificationProvider {
|
|
|
|
name = "pushover";
|
|
|
|
|
2023-08-11 00:46:41 -07:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-09-07 07:42:46 -07:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 06:21:15 -07:00
|
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
const url = "https://api.pushover.net/1/messages.json";
|
2021-09-07 07:42:46 -07:00
|
|
|
|
2022-03-23 21:14:17 -07:00
|
|
|
let data = {
|
2023-01-20 21:59:11 -08:00
|
|
|
"message": msg,
|
2022-03-23 21:14:17 -07:00
|
|
|
"user": notification.pushoveruserkey,
|
|
|
|
"token": notification.pushoverapptoken,
|
|
|
|
"sound": notification.pushoversounds,
|
|
|
|
"priority": notification.pushoverpriority,
|
|
|
|
"title": notification.pushovertitle,
|
|
|
|
"retry": "30",
|
|
|
|
"expire": "3600",
|
|
|
|
"html": 1,
|
|
|
|
};
|
|
|
|
|
2024-08-27 18:24:29 -07:00
|
|
|
const baseURL = await setting("primaryBaseURL");
|
|
|
|
if (baseURL && monitorJSON) {
|
|
|
|
data["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
|
|
|
|
data["url_title"] = "Link to Monitor";
|
|
|
|
}
|
|
|
|
|
2022-03-23 21:14:17 -07:00
|
|
|
if (notification.pushoverdevice) {
|
|
|
|
data.device = notification.pushoverdevice;
|
|
|
|
}
|
2023-05-16 09:31:28 -07:00
|
|
|
if (notification.pushoverttl) {
|
|
|
|
data.ttl = notification.pushoverttl;
|
|
|
|
}
|
2022-03-23 21:14:17 -07:00
|
|
|
|
2021-09-07 07:42:46 -07:00
|
|
|
try {
|
|
|
|
if (heartbeatJSON == null) {
|
2024-03-14 06:21:15 -07:00
|
|
|
await axios.post(url, data);
|
2022-03-23 21:14:17 -07:00
|
|
|
return okMsg;
|
|
|
|
} else {
|
2023-05-29 10:24:40 -07:00
|
|
|
data.message += `\n<b>Time (${heartbeatJSON["timezone"]})</b>:${heartbeatJSON["localDateTime"]}`;
|
2024-03-14 06:21:15 -07:00
|
|
|
await axios.post(url, data);
|
2021-09-07 07:42:46 -07:00
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2021-11-29 01:19:55 -08:00
|
|
|
this.throwGeneralAxiosError(error);
|
2021-09-07 07:42:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Pushover;
|