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: Add ntfy notification method #815

Open
wants to merge 1 commit into
base: 3.2-dev
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 @@ -9,6 +9,7 @@
ServerChanNotification,
TelegramNotification,
WecomNotification,
NtfyNotification,
)

logger = logging.getLogger(__name__)
Expand All @@ -23,6 +24,8 @@ def getClient(type: str):
return BarkNotification
elif type.lower() == "wecom":
return WecomNotification
elif type.lower() == 'ntfy':
return NtfyNotification
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
Expand Up @@ -2,3 +2,4 @@
from .server_chan import ServerChanNotification
from .telegram import TelegramNotification
from .wecom import WecomNotification
from .ntfy import NtfyNotification
31 changes: 31 additions & 0 deletions backend/src/module/notification/plugin/ntfy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import logging

from module.models import Notification
from module.network import RequestContent

logger = logging.getLogger(__name__)


class NtfyNotification(RequestContent):
def __init__(self, token, chat_id, **kwargs):
super().__init__()

self.notification_url = f"{chat_id}"
self.token = token

@staticmethod
def gen_message(notify: Notification) -> str:
text = f"""
番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n
"""
return text.strip()

def post_msg(self, notify: Notification) -> bool:
text = self.gen_message(notify)
self.header["Authorization"] = "Bearer " + self.token
self.header["Title"] = notify.official_title.encode('utf-8')
# self.header["Icon"] = notify.poster_path
data = text.encode('utf-8')
resp = self.post_data(self.notification_url, data)
logger.debug(f"ServerChan notification: {resp.status_code}")
return resp.status_code == 200
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',
'ntfy',
];

const items: SettingItem<Notification>[] = [
Expand Down
2 changes: 1 addition & 1 deletion webui/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface Config {
};
notification: {
enable: boolean;
type: 'telegram' | 'server-chan' | 'bark' | 'wecom';
type: 'telegram' | 'server-chan' | 'bark' | 'wecom' | 'ntfy';
token: string;
chat_id: string;
};
Expand Down