mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-15 19:57:07 +08:00
feat: add WPUSH notification provider (#3066)
Add WPUSH as a notification channel for Qinglong panel settings and sample notify scripts (Python/JS), using POST https://api.wpush.cn/api/v1/send with success code === 0. Supports optional channel and topic_code.
This commit is contained in:
+9
-1
@@ -21,6 +21,7 @@ export enum NotificationMode {
|
|||||||
'ntfy' = 'ntfy',
|
'ntfy' = 'ntfy',
|
||||||
'wxPusherBot' = 'wxPusherBot',
|
'wxPusherBot' = 'wxPusherBot',
|
||||||
'openiLink' = 'openiLink',
|
'openiLink' = 'openiLink',
|
||||||
|
'wpush' = 'wpush',
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class NotificationBaseInfo {
|
abstract class NotificationBaseInfo {
|
||||||
@@ -172,6 +173,12 @@ export class OpeniLinkNotification extends NotificationBaseInfo {
|
|||||||
public openiLinkContextToken = '';
|
public openiLinkContextToken = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class WpushNotification extends NotificationBaseInfo {
|
||||||
|
public wpushApiKey = '';
|
||||||
|
public wpushChannel = '';
|
||||||
|
public wpushTopicCode = '';
|
||||||
|
}
|
||||||
|
|
||||||
export interface NotificationInfo
|
export interface NotificationInfo
|
||||||
extends GoCqHttpBotNotification,
|
extends GoCqHttpBotNotification,
|
||||||
GotifyNotification,
|
GotifyNotification,
|
||||||
@@ -195,4 +202,5 @@ export interface NotificationInfo
|
|||||||
NtfyNotification,
|
NtfyNotification,
|
||||||
WxPusherBotNotification,
|
WxPusherBotNotification,
|
||||||
WxPusherSptNotification,
|
WxPusherSptNotification,
|
||||||
OpeniLinkNotification {}
|
OpeniLinkNotification,
|
||||||
|
WpushNotification {}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export default class NotificationService {
|
|||||||
['wxPusherBot', this.wxPusherBot],
|
['wxPusherBot', this.wxPusherBot],
|
||||||
['wxPusherSpt', this.wxPusherSpt],
|
['wxPusherSpt', this.wxPusherSpt],
|
||||||
['openiLink', this.openiLink],
|
['openiLink', this.openiLink],
|
||||||
|
['wpush', this.wpush],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
private title = '';
|
private title = '';
|
||||||
@@ -947,4 +948,31 @@ export default class NotificationService {
|
|||||||
throw new Error(error.response ? error.response.body : error);
|
throw new Error(error.response ? error.response.body : error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private async wpush() {
|
||||||
|
const { wpushApiKey, wpushChannel, wpushTopicCode } = this.params;
|
||||||
|
const url = 'https://api.wpush.cn/api/v1/send';
|
||||||
|
const json: Record<string, string> = {
|
||||||
|
apikey: `${wpushApiKey}`,
|
||||||
|
title: `${this.title}`,
|
||||||
|
content: `${this.content}`,
|
||||||
|
channel: `${wpushChannel || 'wechat'}`,
|
||||||
|
};
|
||||||
|
if (wpushTopicCode) {
|
||||||
|
json.topic_code = `${wpushTopicCode}`;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const res = await httpClient.post(url, {
|
||||||
|
...this.gotOption,
|
||||||
|
json,
|
||||||
|
});
|
||||||
|
if (res.code === 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw new Error(JSON.stringify(res));
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
throw new Error(error.response ? error.response.body : error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,3 +276,13 @@ export OPENILINK_HUB_URL=""
|
|||||||
export OPENILINK_CONTEXT_TOKEN=""
|
export OPENILINK_CONTEXT_TOKEN=""
|
||||||
|
|
||||||
## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可
|
## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可
|
||||||
|
|
||||||
|
## 23. WPUSH
|
||||||
|
## 官方文档: https://wpush.cn/docs
|
||||||
|
## WPUSH_APIKEY (必填) 在 https://wpush.cn/settings 获取,以 WPUSH 开头
|
||||||
|
export WPUSH_APIKEY=""
|
||||||
|
## 推送渠道,支持 wechat/app/sms/mail/webhook/dingtalk/feishu/wechat_work/clawbot/qqbot,默认 wechat
|
||||||
|
export WPUSH_CHANNEL="wechat"
|
||||||
|
## 可选,Topic 广播编码;填写后按 Topic 推送
|
||||||
|
export WPUSH_TOPIC_CODE=""
|
||||||
|
|
||||||
|
|||||||
@@ -162,6 +162,11 @@ const push_config = {
|
|||||||
OPENILINK_APP_TOKEN: '', // OpeniLink 的 app_token,在 OpeniLink Hub 后台安装 App 后获取
|
OPENILINK_APP_TOKEN: '', // OpeniLink 的 app_token,在 OpeniLink Hub 后台安装 App 后获取
|
||||||
OPENILINK_HUB_URL: '', // OpeniLink Hub 地址,默认为 https://hub.openilink.com,自建 Hub 时填写自己的地址
|
OPENILINK_HUB_URL: '', // OpeniLink Hub 地址,默认为 https://hub.openilink.com,自建 Hub 时填写自己的地址
|
||||||
OPENILINK_CONTEXT_TOKEN: '', // OpeniLink 的 context_token,用于标识消息会话上下文,可从消息事件中获取
|
OPENILINK_CONTEXT_TOKEN: '', // OpeniLink 的 context_token,用于标识消息会话上下文,可从消息事件中获取
|
||||||
|
|
||||||
|
// WPUSH 官方文档: https://wpush.cn/docs
|
||||||
|
WPUSH_APIKEY: '', // WPUSH 的 API Key,在 https://wpush.cn/settings 获取
|
||||||
|
WPUSH_CHANNEL: 'wechat', // 推送渠道,支持 wechat/app/sms/mail/webhook/dingtalk/feishu/wechat_work/clawbot/qqbot
|
||||||
|
WPUSH_TOPIC_CODE: '', // 可选,Topic 广播编码
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const key in push_config) {
|
for (const key in push_config) {
|
||||||
@@ -1494,6 +1499,54 @@ function wxPusherSptNotify(text, desp) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function wpushNotify(text, desp) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const { WPUSH_APIKEY, WPUSH_CHANNEL, WPUSH_TOPIC_CODE } = push_config;
|
||||||
|
if (WPUSH_APIKEY) {
|
||||||
|
const body = {
|
||||||
|
apikey: `${WPUSH_APIKEY}`,
|
||||||
|
title: `${text}`,
|
||||||
|
content: `${desp}`,
|
||||||
|
channel: `${WPUSH_CHANNEL || 'wechat'}`,
|
||||||
|
};
|
||||||
|
if (WPUSH_TOPIC_CODE) {
|
||||||
|
body.topic_code = WPUSH_TOPIC_CODE;
|
||||||
|
}
|
||||||
|
const options = {
|
||||||
|
url: `https://api.wpush.cn/api/v1/send`,
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
timeout,
|
||||||
|
};
|
||||||
|
$.post(options, (err, resp, data) => {
|
||||||
|
try {
|
||||||
|
if (err) {
|
||||||
|
console.log('WPUSH 发送通知消息失败!\n', err);
|
||||||
|
} else {
|
||||||
|
if (data.code === 0) {
|
||||||
|
console.log('WPUSH 发送通知消息成功!');
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`WPUSH 发送通知消息异常:${data.message || JSON.stringify(data)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
$.logErr(e, resp);
|
||||||
|
} finally {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function openiLinkNotify(text, desp) {
|
function openiLinkNotify(text, desp) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const { OPENILINK_APP_TOKEN, OPENILINK_HUB_URL, OPENILINK_CONTEXT_TOKEN } =
|
const { OPENILINK_APP_TOKEN, OPENILINK_HUB_URL, OPENILINK_CONTEXT_TOKEN } =
|
||||||
@@ -1674,6 +1727,7 @@ async function sendNotify(text, desp, params = {}) {
|
|||||||
wxPusherNotify(text, desp), // wxpusher
|
wxPusherNotify(text, desp), // wxpusher
|
||||||
wxPusherSptNotify(text, desp), // wxpusher SPT
|
wxPusherSptNotify(text, desp), // wxpusher SPT
|
||||||
openiLinkNotify(text, desp), // OpeniLink
|
openiLinkNotify(text, desp), // OpeniLink
|
||||||
|
wpushNotify(text, desp), // WPUSH
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,6 +147,11 @@ push_config = {
|
|||||||
'OPENILINK_APP_TOKEN': '', # OpeniLink 的 app_token,在 OpeniLink Hub 后台安装 App 后获取 官方文档: https://openilink.com/docs/hub/apps
|
'OPENILINK_APP_TOKEN': '', # OpeniLink 的 app_token,在 OpeniLink Hub 后台安装 App 后获取 官方文档: https://openilink.com/docs/hub/apps
|
||||||
'OPENILINK_HUB_URL': '', # OpeniLink Hub 地址,默认为 https://hub.openilink.com,自建 Hub 时填写自己的地址
|
'OPENILINK_HUB_URL': '', # OpeniLink Hub 地址,默认为 https://hub.openilink.com,自建 Hub 时填写自己的地址
|
||||||
'OPENILINK_CONTEXT_TOKEN': '', # OpeniLink 的 context_token,用于标识消息会话上下文,可从消息事件中获取
|
'OPENILINK_CONTEXT_TOKEN': '', # OpeniLink 的 context_token,用于标识消息会话上下文,可从消息事件中获取
|
||||||
|
|
||||||
|
# WPUSH 官方文档: https://wpush.cn/docs
|
||||||
|
'WPUSH_APIKEY': '', # WPUSH 的 API Key,在 https://wpush.cn/settings 获取
|
||||||
|
'WPUSH_CHANNEL': 'wechat', # 推送渠道,支持 wechat/app/sms/mail/webhook/dingtalk/feishu/wechat_work/clawbot/qqbot
|
||||||
|
'WPUSH_TOPIC_CODE': '', # 可选,Topic 广播编码
|
||||||
}
|
}
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
@@ -956,6 +961,36 @@ def wxpusher_spt(title: str, content: str) -> None:
|
|||||||
print(f"wxpusher SPT 推送失败!错误信息:{response.get('msg')}")
|
print(f"wxpusher SPT 推送失败!错误信息:{response.get('msg')}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def wpush(title: str, content: str) -> None:
|
||||||
|
"""
|
||||||
|
通过 WPUSH 推送消息。
|
||||||
|
官方文档: https://wpush.cn/docs
|
||||||
|
"""
|
||||||
|
if not push_config.get("WPUSH_APIKEY"):
|
||||||
|
return
|
||||||
|
|
||||||
|
print("WPUSH 服务启动")
|
||||||
|
|
||||||
|
url = "https://api.wpush.cn/api/v1/send"
|
||||||
|
data = {
|
||||||
|
"apikey": push_config.get("WPUSH_APIKEY"),
|
||||||
|
"title": title,
|
||||||
|
"content": content,
|
||||||
|
"channel": push_config.get("WPUSH_CHANNEL") or "wechat",
|
||||||
|
}
|
||||||
|
if push_config.get("WPUSH_TOPIC_CODE"):
|
||||||
|
data["topic_code"] = push_config.get("WPUSH_TOPIC_CODE")
|
||||||
|
|
||||||
|
headers = {"Content-Type": "application/json"}
|
||||||
|
response = requests.post(url=url, json=data, headers=headers, timeout=15).json()
|
||||||
|
|
||||||
|
if response.get("code") == 0:
|
||||||
|
print("WPUSH 推送成功!")
|
||||||
|
else:
|
||||||
|
print(f'WPUSH 推送失败!错误信息:{response.get("message") or response}')
|
||||||
|
|
||||||
|
|
||||||
def openilink(title: str, content: str) -> None:
|
def openilink(title: str, content: str) -> None:
|
||||||
"""
|
"""
|
||||||
通过 OpeniLink 推送消息。
|
通过 OpeniLink 推送消息。
|
||||||
@@ -1162,6 +1197,8 @@ def add_notify_function():
|
|||||||
notify_function.append(wxpusher_spt)
|
notify_function.append(wxpusher_spt)
|
||||||
if push_config.get("OPENILINK_APP_TOKEN"):
|
if push_config.get("OPENILINK_APP_TOKEN"):
|
||||||
notify_function.append(openilink)
|
notify_function.append(openilink)
|
||||||
|
if push_config.get("WPUSH_APIKEY"):
|
||||||
|
notify_function.append(wpush)
|
||||||
if not notify_function:
|
if not notify_function:
|
||||||
print(f"无推送渠道,请检查通知变量是否正确")
|
print(f"无推送渠道,请检查通知变量是否正确")
|
||||||
return notify_function
|
return notify_function
|
||||||
|
|||||||
@@ -661,5 +661,8 @@
|
|||||||
"失败次数": "Failure count",
|
"失败次数": "Failure count",
|
||||||
"最新日志": "Latest log",
|
"最新日志": "Latest log",
|
||||||
"加载失败": "Failed to load",
|
"加载失败": "Failed to load",
|
||||||
"重试": "Retry"
|
"重试": "Retry",
|
||||||
|
"WPUSH的API Key,在 https://wpush.cn/settings 获取,参考 https://wpush.cn/docs": "WPUSH API Key from https://wpush.cn/settings, see https://wpush.cn/docs",
|
||||||
|
"推送渠道,支持 wechat/app/sms/mail/webhook/dingtalk/feishu/wechat_work/clawbot/qqbot,默认 wechat": "Channel: wechat/app/sms/mail/webhook/dingtalk/feishu/wechat_work/clawbot/qqbot, default wechat",
|
||||||
|
"可选,Topic 广播编码;填写后按 Topic 推送,参考 https://wpush.cn/docs": "Optional Topic code for broadcast; see https://wpush.cn/docs"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -661,5 +661,8 @@
|
|||||||
"失败次数": "失败次数",
|
"失败次数": "失败次数",
|
||||||
"最新日志": "最新日志",
|
"最新日志": "最新日志",
|
||||||
"加载失败": "加载失败",
|
"加载失败": "加载失败",
|
||||||
"重试": "重试"
|
"重试": "重试",
|
||||||
|
"WPUSH的API Key,在 https://wpush.cn/settings 获取,参考 https://wpush.cn/docs": "WPUSH的API Key,在 https://wpush.cn/settings 获取,参考 https://wpush.cn/docs",
|
||||||
|
"推送渠道,支持 wechat/app/sms/mail/webhook/dingtalk/feishu/wechat_work/clawbot/qqbot,默认 wechat": "推送渠道,支持 wechat/app/sms/mail/webhook/dingtalk/feishu/wechat_work/clawbot/qqbot,默认 wechat",
|
||||||
|
"可选,Topic 广播编码;填写后按 Topic 推送,参考 https://wpush.cn/docs": "可选,Topic 广播编码;填写后按 Topic 推送,参考 https://wpush.cn/docs"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ export default {
|
|||||||
{ value: 'wxPusherBot', label: 'wxPusher' },
|
{ value: 'wxPusherBot', label: 'wxPusher' },
|
||||||
{ value: 'wxPusherSpt', label: 'WxPusher(极简推送SPT-推荐)' },
|
{ value: 'wxPusherSpt', label: 'WxPusher(极简推送SPT-推荐)' },
|
||||||
{ value: 'openiLink', label: 'OpeniLink' },
|
{ value: 'openiLink', label: 'OpeniLink' },
|
||||||
|
{ value: 'wpush', label: 'WPUSH' },
|
||||||
{ value: 'chat', label: intl.get('群晖chat') },
|
{ value: 'chat', label: intl.get('群晖chat') },
|
||||||
{ value: 'email', label: intl.get('邮箱') },
|
{ value: 'email', label: intl.get('邮箱') },
|
||||||
{ value: 'lark', label: intl.get('飞书机器人') },
|
{ value: 'lark', label: intl.get('飞书机器人') },
|
||||||
@@ -378,6 +379,27 @@ export default {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
wpush: [
|
||||||
|
{
|
||||||
|
label: 'wpushApiKey',
|
||||||
|
tip: intl.get(
|
||||||
|
'WPUSH的API Key,在 https://wpush.cn/settings 获取,参考 https://wpush.cn/docs',
|
||||||
|
),
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'wpushChannel',
|
||||||
|
tip: intl.get(
|
||||||
|
'推送渠道,支持 wechat/app/sms/mail/webhook/dingtalk/feishu/wechat_work/clawbot/qqbot,默认 wechat',
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'wpushTopicCode',
|
||||||
|
tip: intl.get(
|
||||||
|
'可选,Topic 广播编码;填写后按 Topic 推送,参考 https://wpush.cn/docs',
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
openiLink: [
|
openiLink: [
|
||||||
{
|
{
|
||||||
label: 'openiLinkAppToken',
|
label: 'openiLinkAppToken',
|
||||||
|
|||||||
Reference in New Issue
Block a user