From c60b741406d45c7678e16a53500f1359678bd95c Mon Sep 17 00:00:00 2001 From: 401Unauthorized Date: Tue, 27 Dec 2022 14:05:45 +0800 Subject: [PATCH] Add kook notification provider --- server/notification-providers/kook.js | 31 +++++++++++++++++++++++ server/notification.js | 2 ++ src/components/notifications/Kook.vue | 36 +++++++++++++++++++++++++++ src/components/notifications/index.js | 2 ++ src/languages/en.js | 4 +++ src/languages/zh-CN.js | 4 +++ 6 files changed, 79 insertions(+) create mode 100644 server/notification-providers/kook.js create mode 100644 src/components/notifications/Kook.vue diff --git a/server/notification-providers/kook.js b/server/notification-providers/kook.js new file mode 100644 index 00000000..b37b75ab --- /dev/null +++ b/server/notification-providers/kook.js @@ -0,0 +1,31 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class Kook extends NotificationProvider { + + name = "Kook"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + let url = "https://www.kookapp.cn/api/v3/message/create"; + let data = { + target_id: notification.kookGuildID, + content: msg, + }; + let config = { + headers: { + "Authorization": "Bot " + notification.kookBotToken, + "Content-Type": "application/json", + }, + }; + try { + await axios.post(url, data, config); + return okMsg; + + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Kook; diff --git a/server/notification.js b/server/notification.js index 9069601b..6ff42e01 100644 --- a/server/notification.js +++ b/server/notification.js @@ -14,6 +14,7 @@ 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 Kook = require("./notification-providers/kook"); const Line = require("./notification-providers/line"); const LineNotify = require("./notification-providers/linenotify"); const LunaSea = require("./notification-providers/lunasea"); @@ -70,6 +71,7 @@ class Notification { new Gorush(), new Gotify(), new HomeAssistant(), + new Kook(), new Line(), new LineNotify(), new LunaSea(), diff --git a/src/components/notifications/Kook.vue b/src/components/notifications/Kook.vue new file mode 100644 index 00000000..d618750b --- /dev/null +++ b/src/components/notifications/Kook.vue @@ -0,0 +1,36 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 0c220b71..a2ba485f 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -12,6 +12,7 @@ import GoogleChat from "./GoogleChat.vue"; import Gorush from "./Gorush.vue"; import Gotify from "./Gotify.vue"; import HomeAssistant from "./HomeAssistant.vue"; +import Kook from "./Kook.vue"; import Line from "./Line.vue"; import LineNotify from "./LineNotify.vue"; import LunaSea from "./LunaSea.vue"; @@ -63,6 +64,7 @@ const NotificationFormList = { "gorush": Gorush, "gotify": Gotify, "HomeAssistant": HomeAssistant, + "Kook": Kook, "line": Line, "LineNotify": LineNotify, "lunasea": LunaSea, diff --git a/src/languages/en.js b/src/languages/en.js index e760f92e..786185f3 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -270,6 +270,10 @@ export default { apprise: "Apprise (Support 50+ Notification services)", GoogleChat: "Google Chat (Google Workspace only)", pushbullet: "Pushbullet", + Kook: "Kook", + wayToGetKookBotToken: "Create application and get your bot token at {0}", + wayToGetKookGuildID: "Switch on 'Developer Mode' in Kook setting, and right click the guild to get its ID", + "Guild ID": "Guild ID", line: "Line Messenger", mattermost: "Mattermost", "User Key": "User Key", diff --git a/src/languages/zh-CN.js b/src/languages/zh-CN.js index ff11c7e9..5878758c 100644 --- a/src/languages/zh-CN.js +++ b/src/languages/zh-CN.js @@ -250,6 +250,10 @@ export default { apprise: "Apprise (支持 50+ 种通知服务)", GoogleChat: "Google Chat(仅 Google Workspace)", pushbullet: "Pushbullet", + Kook: "Kook", + wayToGetKookBotToken: "在 {0} 创建应用并获取机器人 Token", + wayToGetKookGuildID: "在Kook设置中打开 ‘开发者模式’,然后右键频道可获取其 ID", + "Guild ID": "频道 ID", line: "Line Messenger", mattermost: "Mattermost", "User Key": "User Key",