mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-03 12:02:33 +02:00

Reformatted code across multiple modules, standardizing string quotes, indentation, and spacing. Improved readability by restructuring blocks and aligning object properties consistently. These changes ensure better code maintainability and follow standard conventions. Signed-off-by: Toby Liddicoat <toby@codesure.co.uk>
47 lines
1.6 KiB
JavaScript
47 lines
1.6 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;
|