mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-29 16:06:07 +08:00
✨ 自定义通知
This commit is contained in:
parent
cc9a17afa3
commit
b92b9c2ad4
|
@ -125,6 +125,10 @@ let AIBOTK_NAME = '';
|
||||||
//FSKEY 飞书机器人的 FSKEY
|
//FSKEY 飞书机器人的 FSKEY
|
||||||
let FSKEY = '';
|
let FSKEY = '';
|
||||||
|
|
||||||
|
// =======================================自定义通知设置区域=======================================
|
||||||
|
// 自定义通知 接收回调的URL
|
||||||
|
let CUSTOM_URL = '';
|
||||||
|
|
||||||
// =======================================SMTP 邮件设置区域=======================================
|
// =======================================SMTP 邮件设置区域=======================================
|
||||||
// SMTP_SERVER: 填写 SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465
|
// SMTP_SERVER: 填写 SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465
|
||||||
// SMTP_SSL: 填写 SMTP 发送邮件服务器是否使用 SSL,内容应为 true 或 false
|
// SMTP_SSL: 填写 SMTP 发送邮件服务器是否使用 SSL,内容应为 true 或 false
|
||||||
|
@ -278,6 +282,9 @@ if (process.env.SMTP_PASSWORD) {
|
||||||
if (process.env.SMTP_NAME) {
|
if (process.env.SMTP_NAME) {
|
||||||
SMTP_NAME = process.env.SMTP_NAME;
|
SMTP_NAME = process.env.SMTP_NAME;
|
||||||
}
|
}
|
||||||
|
if (process.env.CUSTOM_URL) {
|
||||||
|
CUSTOM_URL = process.env.CUSTOM_URL;
|
||||||
|
}
|
||||||
//==========================云端环境变量的判断与接收=========================
|
//==========================云端环境变量的判断与接收=========================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -316,6 +323,7 @@ async function sendNotify(
|
||||||
aibotkNotify(text, desp), //智能微秘书
|
aibotkNotify(text, desp), //智能微秘书
|
||||||
fsBotNotify(text, desp), //飞书机器人
|
fsBotNotify(text, desp), //飞书机器人
|
||||||
smtpNotify(text, desp), //SMTP 邮件
|
smtpNotify(text, desp), //SMTP 邮件
|
||||||
|
customNotify(text, desp), //自定义通知
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1097,6 +1105,42 @@ function smtpNotify(text, desp) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function customNotify(text, desp) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const options = {
|
||||||
|
url: `${CUSTOM_URL}`,
|
||||||
|
json: {
|
||||||
|
title: text,
|
||||||
|
content: desp
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
timeout,
|
||||||
|
};
|
||||||
|
if (CUSTOM_URL) {
|
||||||
|
$.post(options, (err, resp, data) => {
|
||||||
|
try {
|
||||||
|
if (err) {
|
||||||
|
console.log('自定义发送通知消息失败!!\n');
|
||||||
|
console.log(err);
|
||||||
|
} else {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
console.log('自定义发送通知消息成功🎉。\n');
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
$.logErr(e, resp);
|
||||||
|
} finally {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sendNotify,
|
sendNotify,
|
||||||
BARK_PUSH,
|
BARK_PUSH,
|
||||||
|
|
|
@ -96,6 +96,8 @@ push_config = {
|
||||||
'SMTP_EMAIL': '', # SMTP 收发件邮箱,通知将会由自己发给自己
|
'SMTP_EMAIL': '', # SMTP 收发件邮箱,通知将会由自己发给自己
|
||||||
'SMTP_PASSWORD': '', # SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
|
'SMTP_PASSWORD': '', # SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
|
||||||
'SMTP_NAME': '', # SMTP 收发件人姓名,可随意填写
|
'SMTP_NAME': '', # SMTP 收发件人姓名,可随意填写
|
||||||
|
|
||||||
|
'CUSTOM_URL': '' # 自定义通知 接收回调的URL
|
||||||
}
|
}
|
||||||
notify_function = []
|
notify_function = []
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
@ -595,6 +597,24 @@ def smtp(title: str, content: str) -> None:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'SMTP 邮件 推送失败!{e}')
|
print(f'SMTP 邮件 推送失败!{e}')
|
||||||
|
|
||||||
|
def custom_notify(title: str, content: str) -> None:
|
||||||
|
"""
|
||||||
|
通过 自定义通知 推送消息。
|
||||||
|
"""
|
||||||
|
if not push_config.get("CUSTOM_URL"):
|
||||||
|
print("自定义通知 服务的 CUSTOM_URL 未设置!!\n取消推送")
|
||||||
|
return
|
||||||
|
print("自定义通知服务启动")
|
||||||
|
|
||||||
|
url = f"{push_config.get('CUSTOM_URL')}"
|
||||||
|
headers = {"Content-Type": "application/json;charset=utf-8"}
|
||||||
|
data = {"title": f"{title}", "content": f"{content}"}
|
||||||
|
response = requests.post(
|
||||||
|
url=url, data=json.dumps(data), headers=headers, timeout=15
|
||||||
|
).json()
|
||||||
|
|
||||||
|
print("自定义通知推送成功!")
|
||||||
|
print(response)
|
||||||
|
|
||||||
def one() -> str:
|
def one() -> str:
|
||||||
"""
|
"""
|
||||||
|
@ -640,6 +660,8 @@ if push_config.get("AIBOTK_KEY") and push_config.get("AIBOTK_TYPE") and push_con
|
||||||
notify_function.append(aibotk)
|
notify_function.append(aibotk)
|
||||||
if push_config.get("SMTP_SERVER") and push_config.get("SMTP_SSL") and push_config.get("SMTP_EMAIL") and push_config.get("SMTP_PASSWORD") and push_config.get("SMTP_NAME"):
|
if push_config.get("SMTP_SERVER") and push_config.get("SMTP_SSL") and push_config.get("SMTP_EMAIL") and push_config.get("SMTP_PASSWORD") and push_config.get("SMTP_NAME"):
|
||||||
notify_function.append(smtp)
|
notify_function.append(smtp)
|
||||||
|
if push_config.get("CUSTOM_URL"):
|
||||||
|
notify_function.append(custom_notify)
|
||||||
|
|
||||||
|
|
||||||
def send(title: str, content: str) -> None:
|
def send(title: str, content: str) -> None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user