diff --git a/backend/src/module/notification/notification.py b/backend/src/module/notification/notification.py index 909fc92ca..4a22f65ee 100644 --- a/backend/src/module/notification/notification.py +++ b/backend/src/module/notification/notification.py @@ -6,6 +6,7 @@ from .plugin import ( BarkNotification, + GotifyNotification, ServerChanNotification, TelegramNotification, WecomNotification, @@ -23,6 +24,8 @@ def getClient(type: str): return BarkNotification elif type.lower() == "wecom": return WecomNotification + elif type.lower() == "gotify": + return GotifyNotification else: return None diff --git a/backend/src/module/notification/plugin/__init__.py b/backend/src/module/notification/plugin/__init__.py index e9acda8f1..1f101fa9d 100644 --- a/backend/src/module/notification/plugin/__init__.py +++ b/backend/src/module/notification/plugin/__init__.py @@ -1,4 +1,5 @@ from .bark import BarkNotification +from .gotify import GotifyNotification from .server_chan import ServerChanNotification from .telegram import TelegramNotification from .wecom import WecomNotification diff --git a/backend/src/module/notification/plugin/gotify.py b/backend/src/module/notification/plugin/gotify.py new file mode 100644 index 000000000..ee1549f88 --- /dev/null +++ b/backend/src/module/notification/plugin/gotify.py @@ -0,0 +1,30 @@ +import logging + +from module.models import Notification +from module.network import RequestContent +from module.utils import load_image + +logger = logging.getLogger(__name__) + +class GotifyNotification(RequestContent): + def __init__(self, token: str, chat_id: str): + # chat_id is actually endpoint here LUL + super().__init__() + self.endpoint = chat_id + self.header["Authorization"] = f"Bearer {token}" + + @staticmethod + def gen_message(notify: Notification) -> str: + text = f""" + 番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n![]({notify.poster_path})\n + """ + return text.strip() + + def post_msg(self, notify: Notification) -> bool: + data = { + "title": notify.official_title, + "message": self.gen_message(notify) + } + resp = self.post_data(self.endpoint, data) + logger.debug(f"Gotify notification: {resp.status_code}") + return resp.status_code == 200 diff --git a/backend/src/module/notification/plugin/slack.py b/backend/src/module/notification/plugin/slack.py index b9cbcf690..33bd21677 100644 --- a/backend/src/module/notification/plugin/slack.py +++ b/backend/src/module/notification/plugin/slack.py @@ -23,5 +23,5 @@ def post_msg(self, notify: Notification) -> bool: text = self.gen_message(notify) data = {"title": notify.official_title, "body": text, "device_key": self.token} resp = self.post_data(self.notification_url, data) - logger.debug(f"Bark notification: {resp.status_code}") + logger.debug(f"Slack notification: {resp.status_code}") return resp.status_code == 200 diff --git a/docs/config/notifier.md b/docs/config/notifier.md index 1603322d9..b219f186f 100644 --- a/docs/config/notifier.md +++ b/docs/config/notifier.md @@ -12,8 +12,10 @@ - Wecom - Bark - ServerChan + - Gotify - **Chat ID** 仅在使用 `telegram` 通知时需要填写。[Telegram Bot 获取 Chat ID][1] - **Wecom**,chat_id参数框填写自建推送的url地址,同时需要在服务端增加[图文消息][2]类型。[Wecom酱配置说明][3] +- **Gotify**,chat_id参数框填写自建推送的url地址。 ## `config.json` 中的配置选项 diff --git a/webui/src/components/setting/config-notification.vue b/webui/src/components/setting/config-notification.vue index c2bf5088a..e1f97f19e 100644 --- a/webui/src/components/setting/config-notification.vue +++ b/webui/src/components/setting/config-notification.vue @@ -11,6 +11,7 @@ const notificationType: NotificationType = [ 'server-chan', 'bark', 'wecom', + 'gotify' ]; const items: SettingItem[] = [ diff --git a/webui/types/config.ts b/webui/types/config.ts index cafaa1818..fe9de17ed 100644 --- a/webui/types/config.ts +++ b/webui/types/config.ts @@ -13,7 +13,7 @@ export type RenameMethod = ['normal', 'pn', 'advance', 'none']; /** 代理类型 */ export type ProxyType = ['http', 'https', 'socks5']; /** 通知类型 */ -export type NotificationType = ['telegram', 'server-chan', 'bark', 'wecom']; +export type NotificationType = ['telegram', 'server-chan', 'bark', 'wecom', 'gotify']; /** OpenAI Model List */ export type OpenAIModel = ['gpt-3.5-turbo']; /** OpenAI API Type */ @@ -62,7 +62,7 @@ export interface Proxy { } export interface Notification { enable: boolean; - type: 'telegram' | 'server-chan' | 'bark' | 'wecom'; + type: 'telegram' | 'server-chan' | 'bark' | 'wecom' | 'gotify'; token: string; chat_id: string; }