Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support gotify for notification #867

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/src/module/notification/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .plugin import (
BarkNotification,
GotifyNotification,
ServerChanNotification,
TelegramNotification,
WecomNotification,
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions backend/src/module/notification/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions backend/src/module/notification/plugin/gotify.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion backend/src/module/notification/plugin/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions docs/config/notifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 中的配置选项

Expand Down
1 change: 1 addition & 0 deletions webui/src/components/setting/config-notification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const notificationType: NotificationType = [
'server-chan',
'bark',
'wecom',
'gotify'
];

const items: SettingItem<Notification>[] = [
Expand Down
4 changes: 2 additions & 2 deletions webui/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
Expand Down