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

添加Bark消息推送更多参数设置 #793

Open
wants to merge 2 commits 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
29 changes: 26 additions & 3 deletions backend/src/module/notification/plugin/bark.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Optional

from module.models import Notification
from module.network import RequestContent
Expand All @@ -7,10 +8,25 @@


class BarkNotification(RequestContent):
def __init__(self, token, **kwargs):
def __init__(
self,
token: str,
bark_params: Optional[dict],
bark_server: Optional[str],
**kwargs,
) -> None:
super().__init__()
self.token = token
self.notification_url = "https://api.day.app/push"
self.params = bark_params
if bark_server is not None:
if not bark_server.startswith("http"):
bark_server = "https://" + bark_server
if not bark_server.endswith("push"):
bark_server = bark_server.rstrip("/") + "/push"

self.notification_url = bark_server
else:
self.notification_url = "https://api.day.app/push"

@staticmethod
def gen_message(notify: Notification) -> str:
Expand All @@ -21,7 +37,14 @@ def gen_message(notify: Notification) -> str:

def post_msg(self, notify: Notification) -> bool:
text = self.gen_message(notify)
data = {"title": notify.official_title, "body": text, "icon": notify.poster_path, "device_key": self.token}
data = {
"title": notify.official_title,
"body": text,
"icon": notify.poster_path,
"device_key": self.token,
}
if isinstance(self.params, dict):
data.update(self.params)
resp = self.post_data(self.notification_url, data)
logger.debug(f"Bark notification: {resp.status_code}")
return resp.status_code == 200
2 changes: 2 additions & 0 deletions webui/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface Config {
type: 'telegram' | 'server-chan' | 'bark' | 'wecom';
token: string;
chat_id: string;
bark_params: string;
bark_server: string;
};
experimental_openai: {
enable: boolean;
Expand Down