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