2022-06-25 12:22:53 -04:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
|
|
|
|
const defaultNotificationService = "notify";
|
|
|
|
|
|
|
|
class HomeAssistant extends NotificationProvider {
|
|
|
|
name = "HomeAssistant";
|
|
|
|
|
2023-08-11 03:46:41 -04:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2024-03-14 09:21:15 -04:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
|
2022-06-25 12:22:53 -04:00
|
|
|
const notificationService = notification?.notificationService || defaultNotificationService;
|
|
|
|
|
|
|
|
try {
|
|
|
|
await axios.post(
|
2023-06-18 06:58:10 -04:00
|
|
|
`${notification.homeAssistantUrl.trim().replace(/\/*$/, "")}/api/services/notify/${notificationService}`,
|
2022-06-25 12:22:53 -04:00
|
|
|
{
|
|
|
|
title: "Uptime Kuma",
|
2024-03-14 09:21:15 -04:00
|
|
|
message: msg,
|
2022-06-25 12:22:53 -04:00
|
|
|
...(notificationService !== "persistent_notification" && { data: {
|
2024-03-14 09:21:15 -04:00
|
|
|
name: monitorJSON?.name,
|
|
|
|
status: heartbeatJSON?.status,
|
2024-03-18 18:31:37 -04:00
|
|
|
channel: "Uptime Kuma",
|
|
|
|
icon_url: "https://github.com/louislam/uptime-kuma/blob/master/public/icon.png?raw=true",
|
2022-06-25 12:22:53 -04:00
|
|
|
} }),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
Authorization: `Bearer ${notification.longLivedAccessToken}`,
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-03-14 09:21:15 -04:00
|
|
|
return okMsg;
|
2022-06-25 12:22:53 -04:00
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = HomeAssistant;
|