From 64501bf0651d87f4ffaf9ba19e35145b2e3b11a8 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Tue, 17 Aug 2021 13:40:01 +0200 Subject: [PATCH] Added Line Messenger Notification Service --- server/notification.js | 47 +++++++++++++++++++++++++++ src/components/NotificationDialog.vue | 21 ++++++++++++ 2 files changed, 68 insertions(+) diff --git a/server/notification.js b/server/notification.js index 924aa07c2..344a427e0 100644 --- a/server/notification.js +++ b/server/notification.js @@ -389,6 +389,53 @@ class Notification { } catch (error) { throwGeneralAxiosError(error) } + } else if (notification.type === "line") { + try { + let lineAPIUrl = "https://api.line.me/v2/bot/message/push"; + let config = { + headers: { + "Content-Type": "application/json", + "Authorization": "Bearer " + notification.lineChannelAccessToken + } + }; + if (heartbeatJSON == null) { + let testMessage = { + "to": notification.lineUserID, + "messages": [ + { + "type": "text", + "text":"Test Successful!" + } + ] + } + await axios.post(lineAPIUrl, testMessage, config) + } else if (heartbeatJSON["status"] == 0) { + let downMessage = { + "to": notification.lineUserID, + "messages": [ + { + "type": "text", + "text":"UptimeKuma Alert: [🔴 Down]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"] + } + ] + } + await axios.post(lineAPIUrl, downMessage, config) + } else if (heartbeatJSON["status"] == 1) { + let upMessage = { + "to": notification.lineUserID, + "messages": [ + { + "type": "text", + "text":"UptimeKuma Alert: [✅ Up]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"] + } + ] + } + await axios.post(lineAPIUrl, upMessage, config) + } + return okMsg; + } catch (error) { + throwGeneralAxiosError(error) + } } else { throw new Error("Notification type is not supported") } diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 5d2dbd6b8..76421665b 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -26,6 +26,7 @@ + @@ -383,6 +384,26 @@ More info on: https://docs.pushbullet.com

+ +