Skip to content

Commit

Permalink
消息通知 Bark 增加额外参数:时效性通知、跳转Url (#2112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akimio521 authored Sep 16, 2023
1 parent acc7443 commit aab0968
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions back/data/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export class BarkNotification extends NotificationBaseInfo {
public barkIcon = 'https://qn.whyour.cn/logo.png';
public barkSound = '';
public barkGroup = 'qinglong';
public barkLevel = 'active';
public barkUrl = '';
}

export class TelegramBotNotification extends NotificationBaseInfo {
Expand Down
4 changes: 2 additions & 2 deletions back/services/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ export default class NotificationService {
}

private async bark() {
let { barkPush, barkIcon, barkSound, barkGroup } = this.params;
let { barkPush, barkIcon, barkSound, barkGroup, barkLevel, barkUrl } = this.params;
if (!barkPush.startsWith('http')) {
barkPush = `https://api.day.app/${barkPush}`;
}
const url = `${barkPush}/${encodeURIComponent(
this.title,
)}/${encodeURIComponent(
this.content,
)}?icon=${barkIcon}&sound=${barkSound}&group=${barkGroup}`;
)}?icon=${barkIcon}&sound=${barkSound}&group=${barkGroup}&level=${barkLevel}&url=${barkUrl}`;

try {
const res: any = await got
Expand Down
12 changes: 11 additions & 1 deletion sample/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ let BARK_ICON = 'https://qn.whyour.cn/logo.png';
let BARK_SOUND = '';
//BARK app推送消息的分组, 默认为"QingLong"
let BARK_GROUP = 'QingLong';
//BARK app推送消息的时效性, 默认为"active"
let BARK_LEVEL = 'active';
//BARK app推送消息的跳转URL
let BARK_URL = '';

// =======================================telegram机器人通知设置区域===========================================
//此处填你telegram bot 的Token,telegram机器人通知推送必填项.例如:1077xxx4424:AAFjv0FcqxxxxxxgEMGfi22B4yh15R5uw
Expand Down Expand Up @@ -211,6 +215,12 @@ if (process.env.BARK_PUSH) {
if (process.env.BARK_GROUP) {
BARK_GROUP = process.env.BARK_GROUP;
}
if (process.env.BARK_LEVEL) {
BARK_LEVEL = process.env.BARK_LEVEL;
}
if (process.env.BARK_URL) {
BARK_URL = process.env.BARK_URL;
}
} else {
if (
BARK_PUSH &&
Expand Down Expand Up @@ -552,7 +562,7 @@ function BarkNotify(text, desp, params = {}) {
const options = {
url: `${BARK_PUSH}/${encodeURIComponent(text)}/${encodeURIComponent(
desp,
)}?icon=${BARK_ICON}&sound=${BARK_SOUND}&group=${BARK_GROUP}&${querystring.stringify(
)}?icon=${BARK_ICON}&sound=${BARK_SOUND}&group=${BARK_GROUP}&level=${BARK_LEVEL}&url=${BARK_URL}&${querystring.stringify(
params,
)}`,
headers: {
Expand Down
4 changes: 4 additions & 0 deletions sample/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def print(text, *args, **kw):
'BARK_GROUP': '', # bark 推送分组
'BARK_SOUND': '', # bark 推送声音
'BARK_ICON': '', # bark 推送图标
'BARK_LEVEL': '', # bark 推送时效性
'BARK_URL': '', # bark 推送跳转URL

'CONSOLE': True, # 控制台输出

Expand Down Expand Up @@ -130,6 +132,8 @@ def bark(title: str, content: str) -> None:
"BARK_GROUP": "group",
"BARK_SOUND": "sound",
"BARK_ICON": "icon",
"BARK_LEVEL": "level",
"BARK_URL": "url",
}
params = ""
for pair in filter(
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@
"BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)": "BARK push icon, custom push icon (requires iOS 15 or above to display)",
"BARK推送铃声,铃声列表去APP查看复制填写": "BARK push ringtone, check and copy from the APP's ringtone list",
"BARK推送消息的分组,默认为qinglong": "BARK push message grouping, default is qinglong",
"BARK推送消息的时效性,默认为active": "BARK push message redirecting URL",
"BARK推送消息的跳转URL": "BARK push message grouping, default is qinglong",
"telegram机器人的token,例如:1077xxx4424:AAFjv0FcqxxxxxxgEMGfi22B4yh15R5uw": "Telegram Bot token, e.g., 1077xxx4424:AAFjv0FcqxxxxxxgEMGfi22B4yh15R5uw",
"telegram用户的id,例如:129xxx206": "Telegram user ID, e.g., 129xxx206",
"代理IP": "Proxy IP",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@
"BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)": "BARK推送图标,自定义推送图标 (需iOS15或以上才能显示)",
"BARK推送铃声,铃声列表去APP查看复制填写": "BARK推送铃声,铃声列表去APP查看复制填写",
"BARK推送消息的分组,默认为qinglong": "BARK推送消息的分组,默认为qinglong",
"BARK推送消息的时效性,默认为active": "BARK推送消息的时效性,默认为active",
"BARK推送消息的跳转URL": "BARK推送消息的跳转URL",
"telegram机器人的token,例如:1077xxx4424:AAFjv0FcqxxxxxxgEMGfi22B4yh15R5uw": "telegram机器人的token,例如:1077xxx4424:AAFjv0FcqxxxxxxgEMGfi22B4yh15R5uw",
"telegram用户的id,例如:129xxx206": "telegram用户的id,例如:129xxx206",
"代理IP": "代理IP",
Expand Down
8 changes: 8 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ export default {
label: 'barkGroup',
tip: intl.get('BARK推送消息的分组,默认为qinglong'),
},
{
label: 'barkLevel',
tip: intl.get('BARK推送消息的时效性,默认为active'),
},
{
label: 'barkUrl',
tip: intl.get('BARK推送消息的跳转URL'),
},
],
telegramBot: [
{
Expand Down

0 comments on commit aab0968

Please sign in to comment.