mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 06:46:09 +08:00
添加群晖synology chat通知推送 (#1610)
This commit is contained in:
parent
2de189d189
commit
952cdc0e3f
|
@ -4,6 +4,7 @@ export enum NotificationMode {
|
||||||
'serverChan' = 'serverChan',
|
'serverChan' = 'serverChan',
|
||||||
'pushDeer' = 'pushDeer',
|
'pushDeer' = 'pushDeer',
|
||||||
'bark' = 'bark',
|
'bark' = 'bark',
|
||||||
|
'chat' = 'chat'
|
||||||
'telegramBot' = 'telegramBot',
|
'telegramBot' = 'telegramBot',
|
||||||
'dingtalkBot' = 'dingtalkBot',
|
'dingtalkBot' = 'dingtalkBot',
|
||||||
'weWorkBot' = 'weWorkBot',
|
'weWorkBot' = 'weWorkBot',
|
||||||
|
@ -37,6 +38,11 @@ export class PushDeerNotification extends NotificationBaseInfo {
|
||||||
public pushDeerKey = '';
|
public pushDeerKey = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ChatNotification extends NotificationBaseInfo {
|
||||||
|
public chatUrl = '';
|
||||||
|
public chattoken = '';
|
||||||
|
}
|
||||||
|
|
||||||
export class BarkNotification extends NotificationBaseInfo {
|
export class BarkNotification extends NotificationBaseInfo {
|
||||||
public barkPush = '';
|
public barkPush = '';
|
||||||
public barkIcon = 'http://qn.whyour.cn/logo.png';
|
public barkIcon = 'http://qn.whyour.cn/logo.png';
|
||||||
|
@ -86,6 +92,7 @@ export interface NotificationInfo
|
||||||
GotifyNotification,
|
GotifyNotification,
|
||||||
ServerChanNotification,
|
ServerChanNotification,
|
||||||
PushDeerNotification,
|
PushDeerNotification,
|
||||||
|
ChatNotification,
|
||||||
BarkNotification,
|
BarkNotification,
|
||||||
TelegramBotNotification,
|
TelegramBotNotification,
|
||||||
DingtalkBotNotification,
|
DingtalkBotNotification,
|
||||||
|
|
|
@ -17,6 +17,7 @@ export default class NotificationService {
|
||||||
['goCqHttpBot', this.goCqHttpBot],
|
['goCqHttpBot', this.goCqHttpBot],
|
||||||
['serverChan', this.serverChan],
|
['serverChan', this.serverChan],
|
||||||
['pushDeer', this.pushDeer],
|
['pushDeer', this.pushDeer],
|
||||||
|
['chat', this.chat],
|
||||||
['bark', this.bark],
|
['bark', this.bark],
|
||||||
['telegramBot', this.telegramBot],
|
['telegramBot', this.telegramBot],
|
||||||
['dingtalkBot', this.dingtalkBot],
|
['dingtalkBot', this.dingtalkBot],
|
||||||
|
@ -135,6 +136,22 @@ export default class NotificationService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async chat() {
|
||||||
|
const { chatUrl, chattoken } = this.params;
|
||||||
|
const url = `${chatUrl}${chattoken}`;
|
||||||
|
const res: any = await got
|
||||||
|
.post(url, {
|
||||||
|
timeout: this.timeout,
|
||||||
|
retry: 0,
|
||||||
|
body: `payload={"text":"${this.title}\n${this.content}"}`,
|
||||||
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
})
|
||||||
|
.json();
|
||||||
|
return (
|
||||||
|
res.success
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private async bark() {
|
private async bark() {
|
||||||
let { barkPush, barkIcon, barkSound, barkGroup } = this.params;
|
let { barkPush, barkIcon, barkSound, barkGroup } = this.params;
|
||||||
if (!barkPush.startsWith('http') && !barkPush.startsWith('https')) {
|
if (!barkPush.startsWith('http') && !barkPush.startsWith('https')) {
|
||||||
|
|
|
@ -137,4 +137,10 @@ export GOTIFY_PRIORITY=0
|
||||||
## deer_key 填写PushDeer的key
|
## deer_key 填写PushDeer的key
|
||||||
export DEER_KEY=""
|
export DEER_KEY=""
|
||||||
|
|
||||||
|
## 12. Chat
|
||||||
|
## chat_url 填写synology chat地址,http://IP:PORT/webapi/***token=
|
||||||
|
## chat_token 填写后面的token
|
||||||
|
export CHAT_URL=""
|
||||||
|
export CHAT_TOKEN=""
|
||||||
|
|
||||||
## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可
|
## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可
|
||||||
|
|
|
@ -39,6 +39,12 @@ let SCKEY = '';
|
||||||
//(环境变量名 DEER_KEY)
|
//(环境变量名 DEER_KEY)
|
||||||
let PUSHDEER_KEY = '';
|
let PUSHDEER_KEY = '';
|
||||||
|
|
||||||
|
// =======================================Synology Chat通知设置区域===========================================
|
||||||
|
//此处填你申请的CHAT_URL与CHAT_TOKEN
|
||||||
|
//(环境变量名 CHAT_URL CHAT_TOKEN)
|
||||||
|
let CHAT_URL = '';
|
||||||
|
let CHAT_TOKEN = '';
|
||||||
|
|
||||||
// =======================================Bark App通知设置区域===========================================
|
// =======================================Bark App通知设置区域===========================================
|
||||||
//此处填你BarkAPP的信息(IP/设备码,例如:https://api.day.app/XXXXXXXX)
|
//此处填你BarkAPP的信息(IP/设备码,例如:https://api.day.app/XXXXXXXX)
|
||||||
let BARK_PUSH = '';
|
let BARK_PUSH = '';
|
||||||
|
@ -133,6 +139,14 @@ if (process.env.DEER_KEY) {
|
||||||
PUSHDEER_KEY = process.env.DEER_KEY;
|
PUSHDEER_KEY = process.env.DEER_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env.CHAT_URL) {
|
||||||
|
CHAT_URL = process.env.CHAT_URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.CHAT_TOKEN) {
|
||||||
|
CHAT_TOKEN = process.env.CHAT_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
if (process.env.QQ_SKEY) {
|
if (process.env.QQ_SKEY) {
|
||||||
QQ_SKEY = process.env.QQ_SKEY;
|
QQ_SKEY = process.env.QQ_SKEY;
|
||||||
}
|
}
|
||||||
|
@ -239,6 +253,7 @@ async function sendNotify(
|
||||||
iGotNotify(text, desp, params), //iGot
|
iGotNotify(text, desp, params), //iGot
|
||||||
gobotNotify(text, desp), //go-cqhttp
|
gobotNotify(text, desp), //go-cqhttp
|
||||||
gotifyNotify(text, desp), //gotify
|
gotifyNotify(text, desp), //gotify
|
||||||
|
ChatNotify(text, desp), //synolog chat
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,6 +430,49 @@ function PushDeerNotify(text, desp, time = 2100) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ChatNotify(text, desp, time = 2100) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (CHAT_URL && CHAT_TOKEN ) {
|
||||||
|
// 对消息内容进行 urlencode
|
||||||
|
desp = encodeURI(desp);
|
||||||
|
const options = {
|
||||||
|
url: `${CHAT_URL}${CHAT_TOKEN}`,
|
||||||
|
body: `payload={"text":"${text}\n${desp}"}`,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
setTimeout(() => {
|
||||||
|
$.post(options, (err, resp, data) => {
|
||||||
|
try {
|
||||||
|
if (err) {
|
||||||
|
console.log('发送通知调用API失败!!\n');
|
||||||
|
console.log(err);
|
||||||
|
} else {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
if (
|
||||||
|
data.success
|
||||||
|
) {
|
||||||
|
console.log('Chat发送通知消息成功🎉\n');
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`Chat发送通知消息异常\n${JSON.stringify(data)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
$.logErr(e);
|
||||||
|
} finally {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, time);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function CoolPush(text, desp) {
|
function CoolPush(text, desp) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (QQ_SKEY) {
|
if (QQ_SKEY) {
|
||||||
|
|
|
@ -61,7 +61,10 @@ push_config = {
|
||||||
'PUSH_KEY': '', # server 酱的 PUSH_KEY,兼容旧版与 Turbo 版
|
'PUSH_KEY': '', # server 酱的 PUSH_KEY,兼容旧版与 Turbo 版
|
||||||
|
|
||||||
'DEER_KEY': '', # PushDeer 的 PUSHDEER_KEY
|
'DEER_KEY': '', # PushDeer 的 PUSHDEER_KEY
|
||||||
|
|
||||||
|
'CHAT_URL': '', # synology chat url
|
||||||
|
'CHAT_TOKEN': '', # synology chat token
|
||||||
|
|
||||||
'PUSH_PLUS_TOKEN': '', # push+ 微信推送的用户令牌
|
'PUSH_PLUS_TOKEN': '', # push+ 微信推送的用户令牌
|
||||||
'PUSH_PLUS_USER': '', # push+ 微信推送的群组编码
|
'PUSH_PLUS_USER': '', # push+ 微信推送的群组编码
|
||||||
|
|
||||||
|
@ -279,8 +282,27 @@ def pushdeer(title: str, content: str) -> None:
|
||||||
print("PushDeer 推送成功!")
|
print("PushDeer 推送成功!")
|
||||||
else:
|
else:
|
||||||
print("PushDeer 推送失败!错误信息:", response)
|
print("PushDeer 推送失败!错误信息:", response)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def chat(title: str, content: str) -> None:
|
||||||
|
"""
|
||||||
|
通过Chat 推送消息
|
||||||
|
"""
|
||||||
|
if not push_config.get("CHAT_URL") or not push_config.get("CHAT_TOKEN"):
|
||||||
|
print("chat 服务的 CHAT_URL或CHAT_TOKEN 未设置!!\n取消推送")
|
||||||
|
return
|
||||||
|
print("chat 服务启动")
|
||||||
|
data = 'payload=' + json.dumps({'text': title + '\n' + content})
|
||||||
|
url = push_config.get("CHAT_URL") + push_config.get("CHAT_TOKEN")
|
||||||
|
response = requests.post(url, data=data)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
print("Chat 推送成功!")
|
||||||
|
else:
|
||||||
|
print("Chat 推送失败!错误信息:", response)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def pushplus_bot(title: str, content: str) -> None:
|
def pushplus_bot(title: str, content: str) -> None:
|
||||||
"""
|
"""
|
||||||
通过 push+ 推送消息。
|
通过 push+ 推送消息。
|
||||||
|
@ -527,6 +549,8 @@ if push_config.get("PUSH_KEY"):
|
||||||
notify_function.append(serverJ)
|
notify_function.append(serverJ)
|
||||||
if push_config.get("DEER_KEY"):
|
if push_config.get("DEER_KEY"):
|
||||||
notify_function.append(pushdeer)
|
notify_function.append(pushdeer)
|
||||||
|
if push_config.get("CHAT_URL") and push_config.get("CHAT_TOKEN"):
|
||||||
|
notify_function.append(chat)
|
||||||
if push_config.get("PUSH_PLUS_TOKEN"):
|
if push_config.get("PUSH_PLUS_TOKEN"):
|
||||||
notify_function.append(pushplus_bot)
|
notify_function.append(pushplus_bot)
|
||||||
if push_config.get("QMSG_KEY") and push_config.get("QMSG_TYPE"):
|
if push_config.get("QMSG_KEY") and push_config.get("QMSG_TYPE"):
|
||||||
|
|
|
@ -90,6 +90,7 @@ export default {
|
||||||
{ value: 'weWorkApp', label: '企业微信应用' },
|
{ value: 'weWorkApp', label: '企业微信应用' },
|
||||||
{ value: 'iGot', label: 'IGot' },
|
{ value: 'iGot', label: 'IGot' },
|
||||||
{ value: 'pushPlus', label: 'PushPlus' },
|
{ value: 'pushPlus', label: 'PushPlus' },
|
||||||
|
{ value: 'chat', label: 'chat' },
|
||||||
{ value: 'email', label: '邮箱' },
|
{ value: 'email', label: '邮箱' },
|
||||||
{ value: 'closed', label: '已关闭' },
|
{ value: 'closed', label: '已关闭' },
|
||||||
],
|
],
|
||||||
|
@ -103,6 +104,14 @@ export default {
|
||||||
{ label: 'gotifyToken', tip: 'gotify的消息应用token码', required: true },
|
{ label: 'gotifyToken', tip: 'gotify的消息应用token码', required: true },
|
||||||
{ label: 'gotifyPriority', tip: '推送消息的优先级' },
|
{ label: 'gotifyPriority', tip: '推送消息的优先级' },
|
||||||
],
|
],
|
||||||
|
chat: [
|
||||||
|
{
|
||||||
|
label: 'chatUrl',
|
||||||
|
tip: 'chat的url地址',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{ label: 'chattoken', tip: 'chat的token码', required: true },
|
||||||
|
],
|
||||||
goCqHttpBot: [
|
goCqHttpBot: [
|
||||||
{
|
{
|
||||||
label: 'goCqHttpBotUrl',
|
label: 'goCqHttpBotUrl',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user