diff --git a/server/notification-providers/home-assistant.js b/server/notification-providers/home-assistant.js new file mode 100644 index 000000000..285989eeb --- /dev/null +++ b/server/notification-providers/home-assistant.js @@ -0,0 +1,38 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +const defaultNotificationService = "notify"; + +class HomeAssistant extends NotificationProvider { + name = "HomeAssistant"; + + async send(notification, message, monitor = null, heartbeat = null) { + const notificationService = notification?.notificationService || defaultNotificationService; + + try { + await axios.post( + `${notification.homeAssistantUrl}/api/services/notify/${notificationService}`, + { + title: "Uptime Kuma", + message, + ...(notificationService !== "persistent_notification" && { data: { + name: monitor?.name, + status: heartbeat?.status, + } }), + }, + { + headers: { + Authorization: `Bearer ${notification.longLivedAccessToken}`, + "Content-Type": "application/json", + }, + } + ); + + return "Sent Successfully."; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = HomeAssistant; diff --git a/server/notification.js b/server/notification.js index ad1c8705a..8093572a1 100644 --- a/server/notification.js +++ b/server/notification.js @@ -12,6 +12,7 @@ const Feishu = require("./notification-providers/feishu"); const GoogleChat = require("./notification-providers/google-chat"); const Gorush = require("./notification-providers/gorush"); const Gotify = require("./notification-providers/gotify"); +const HomeAssistant = require("./notification-providers/home-assistant"); const Line = require("./notification-providers/line"); const LineNotify = require("./notification-providers/linenotify"); const LunaSea = require("./notification-providers/lunasea"); @@ -61,6 +62,7 @@ class Notification { new GoogleChat(), new Gorush(), new Gotify(), + new HomeAssistant(), new Line(), new LineNotify(), new LunaSea(), diff --git a/src/components/notifications/HomeAssistant.vue b/src/components/notifications/HomeAssistant.vue new file mode 100644 index 000000000..67e370a15 --- /dev/null +++ b/src/components/notifications/HomeAssistant.vue @@ -0,0 +1,40 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index c1b7da4aa..ff523052e 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -10,6 +10,7 @@ import Feishu from "./Feishu.vue"; import GoogleChat from "./GoogleChat.vue"; import Gorush from "./Gorush.vue"; import Gotify from "./Gotify.vue"; +import HomeAssistant from "./HomeAssistant.vue"; import Line from "./Line.vue"; import LineNotify from "./LineNotify.vue"; import LunaSea from "./LunaSea.vue"; @@ -54,6 +55,7 @@ const NotificationFormList = { "GoogleChat": GoogleChat, "gorush": Gorush, "gotify": Gotify, + "HomeAssistant": HomeAssistant, "line": Line, "LineNotify": LineNotify, "lunasea": LunaSea, diff --git a/src/languages/en.js b/src/languages/en.js index fc7777311..2232ea5fc 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -467,6 +467,7 @@ export default { "Domain Name Expiry Notification": "Domain Name Expiry Notification", Proxy: "Proxy", "Date Created": "Date Created", + HomeAssistant: "Home Assistant", onebotHttpAddress: "OneBot HTTP Address", onebotMessageType: "OneBot Message Type", onebotGroupMessage: "Group",