diff --git a/server/notification-providers/linenotify.js b/server/notification-providers/linenotify.js new file mode 100644 index 000000000..8454152d8 --- /dev/null +++ b/server/notification-providers/linenotify.js @@ -0,0 +1,43 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const qs = require("qs"); +const { DOWN, UP } = require("../../src/util"); + +class LineNotify extends NotificationProvider { + + name = "LineNotify"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + try { + let lineAPIUrl = "https://notify-api.line.me/api/notify"; + let config = { + headers: { + "Content-Type": "application/x-www-form-urlencoded", + "Authorization": "Bearer " + notification.lineNotifyAccessToken + } + }; + if (heartbeatJSON == null) { + let testMessage = { + "message": msg, + }; + await axios.post(lineAPIUrl, qs.stringify(testMessage), config); + } else if (heartbeatJSON["status"] === DOWN) { + let downMessage = { + "message": "\n[🔴 Down]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"] + }; + await axios.post(lineAPIUrl, qs.stringify(downMessage), config); + } else if (heartbeatJSON["status"] === UP) { + let upMessage = { + "message": "\n[✅ Up]\n" + "Name: " + monitorJSON["name"] + " \n" + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"] + }; + await axios.post(lineAPIUrl, qs.stringify(upMessage), config); + } + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = LineNotify; diff --git a/server/notification.js b/server/notification.js index a3b3a70b6..ad1c8705a 100644 --- a/server/notification.js +++ b/server/notification.js @@ -13,6 +13,7 @@ const GoogleChat = require("./notification-providers/google-chat"); const Gorush = require("./notification-providers/gorush"); const Gotify = require("./notification-providers/gotify"); const Line = require("./notification-providers/line"); +const LineNotify = require("./notification-providers/linenotify"); const LunaSea = require("./notification-providers/lunasea"); const Matrix = require("./notification-providers/matrix"); const Mattermost = require("./notification-providers/mattermost"); @@ -61,6 +62,7 @@ class Notification { new Gorush(), new Gotify(), new Line(), + new LineNotify(), new LunaSea(), new Matrix(), new Mattermost(), diff --git a/src/components/notifications/LineNotify.vue b/src/components/notifications/LineNotify.vue new file mode 100644 index 000000000..0f6897f46 --- /dev/null +++ b/src/components/notifications/LineNotify.vue @@ -0,0 +1,9 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index e5cbe8ce3..c1b7da4aa 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -11,6 +11,7 @@ import GoogleChat from "./GoogleChat.vue"; import Gorush from "./Gorush.vue"; import Gotify from "./Gotify.vue"; import Line from "./Line.vue"; +import LineNotify from "./LineNotify.vue"; import LunaSea from "./LunaSea.vue"; import Matrix from "./Matrix.vue"; import Mattermost from "./Mattermost.vue"; @@ -54,6 +55,7 @@ const NotificationFormList = { "gorush": Gorush, "gotify": Gotify, "line": Line, + "LineNotify": LineNotify, "lunasea": LunaSea, "matrix": Matrix, "mattermost": Mattermost, diff --git a/src/languages/en.js b/src/languages/en.js index 9aeedd9de..15bdcc8a4 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -536,4 +536,5 @@ export default { "Domain": "Domain", "Workstation": "Workstation", disableCloudflaredNoAuthMsg: "You are in No Auth mode, password is not require.", + wayToGetLineNotifyToken: "You can get a access token from {0}", }; diff --git a/src/languages/th-TH.js b/src/languages/th-TH.js index a573206b5..92c4eb80b 100644 --- a/src/languages/th-TH.js +++ b/src/languages/th-TH.js @@ -518,4 +518,5 @@ export default { "Go back to the previous page.": "กลับไปที่หน้าก่อนหน้า", "Coming Soon": "เร็ว ๆ นี้", wayToGetClickSendSMSToken: "คุณสามารถรับ API Username และ API Key ได้จาก {0}", + wayToGetLineNotifyToken: "คุณสามารถรับ access token ได้จาก {0}", };