mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-24 16:10:47 -06:00
bc077cc536
Co-authored-by: Frank Elsinga <frank@elsinga.de> Co-authored-by: Seb <144435+rmtsrc@users.noreply.github.com>
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
|
|
const defaultNotificationService = "notify";
|
|
|
|
class HomeAssistant extends NotificationProvider {
|
|
name = "HomeAssistant";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
const notificationService = notification?.notificationService || defaultNotificationService;
|
|
|
|
try {
|
|
await axios.post(
|
|
`${notification.homeAssistantUrl.trim().replace(/\/*$/, "")}/api/services/notify/${notificationService}`,
|
|
{
|
|
title: "Uptime Kuma",
|
|
message: msg,
|
|
...(notificationService !== "persistent_notification" && { data: {
|
|
name: monitorJSON?.name,
|
|
status: heartbeatJSON?.status,
|
|
channel: "Uptime Kuma",
|
|
icon_url: "https://github.com/louislam/uptime-kuma/blob/master/public/icon.png?raw=true",
|
|
} }),
|
|
},
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${notification.longLivedAccessToken}`,
|
|
"Content-Type": "application/json",
|
|
},
|
|
}
|
|
);
|
|
|
|
return okMsg;
|
|
} catch (error) {
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = HomeAssistant;
|