mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-07-22 21:13:47 +08:00
feat: Integrate Feishu for notification (#482)
Build and push Docker images / docker (push) Has been cancelled
Mirror and run GitLab CI / build (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, linux) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, macos) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, win) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (alpine) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linux) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linuxstatic) (push) Has been cancelled
Build and push Docker images / docker (push) Has been cancelled
Mirror and run GitLab CI / build (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, linux) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, macos) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, win) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (alpine) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linux) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linuxstatic) (push) Has been cancelled
Co-authored-by: Albert Yang <[email protected]>
This commit is contained in:
+78
-1
@@ -88,6 +88,14 @@ let GOTIFY_URL = '';
|
||||
// 此处填你想推送的Application的Token(不包含推送时额外添加的前缀 Bearer )
|
||||
let GOTIFY_APPKEY = '';
|
||||
|
||||
// =======================================飞书机器人通知设置区域===========================================
|
||||
// 此处填你飞书机器人的 webhook(详见文档 https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot)
|
||||
// 注:此处设置github action用户填写到Settings-Secrets里面(Name输入FS_BOT_WEBHOOK)
|
||||
let FS_BOT_WEBHOOK = '';
|
||||
// 签名密钥(如果在飞书机器人安全设置里开启了“签名校验”)
|
||||
// 注:此处设置github action用户填写到Settings-Secrets里面(Name输入FS_BOT_SECRET)
|
||||
let FS_BOT_SECRET = '';
|
||||
|
||||
//==========================云端环境变量的判断与接收=========================
|
||||
if (process.env.SCKEY) {
|
||||
SCKEY = process.env.SCKEY;
|
||||
@@ -211,6 +219,14 @@ if (process.env.GOTIFY_URL) {
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.FS_BOT_WEBHOOK) {
|
||||
FS_BOT_WEBHOOK = process.env.FS_BOT_WEBHOOK;
|
||||
}
|
||||
|
||||
if (process.env.FS_BOT_SECRET) {
|
||||
FS_BOT_SECRET = process.env.FS_BOT_SECRET;
|
||||
}
|
||||
|
||||
//==========================云端环境变量的判断与接收=========================
|
||||
|
||||
async function sendNotify(text, desp, params = {}) {
|
||||
@@ -246,7 +262,9 @@ async function sendNotify(text, desp, params = {}) {
|
||||
//电子邮件
|
||||
email(text, desp),
|
||||
// Gotify
|
||||
gotifyNotify(text, desp)
|
||||
gotifyNotify(text, desp),
|
||||
// 飞书机器人
|
||||
feishuNotify(text, desp)
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -885,6 +903,65 @@ function gotifyNotify(text, desp) {
|
||||
});
|
||||
}
|
||||
|
||||
function feishuNotify(text, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (FS_BOT_WEBHOOK) {
|
||||
const payload = {
|
||||
msg_type: 'text',
|
||||
content: {
|
||||
text: `${text}\n\n${desp}`
|
||||
}
|
||||
};
|
||||
|
||||
if (FS_BOT_SECRET) {
|
||||
const crypto = require('crypto');
|
||||
const timestamp = Math.floor(Date.now() / 1000);
|
||||
const signStr = `${timestamp}\n${FS_BOT_SECRET}`;
|
||||
const sign = crypto
|
||||
.createHmac('sha256', FS_BOT_SECRET)
|
||||
.update(signStr)
|
||||
.digest('base64');
|
||||
payload.timestamp = `${timestamp}`;
|
||||
payload.sign = sign;
|
||||
}
|
||||
|
||||
send({
|
||||
method: 'POST',
|
||||
url: FS_BOT_WEBHOOK,
|
||||
contents: payload,
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
headers: {
|
||||
accept: 'application/json, text/plain, */*',
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
success: res => {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.code === 0) {
|
||||
log.info('发送通知', '飞书机器人发送通知消息完成。');
|
||||
} else {
|
||||
log.error('发送通知', `${data.msg || '飞书机器人发送通知异常'}`);
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('发送通知', e);
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
log.error('发送通知', '飞书机器人发送通知消息失败!!' + err);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
log.debug('发送通知', '您未提供飞书机器人推送所需的FS_BOT_WEBHOOK,取消飞书机器人推送消息通知');
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function qmsg(text, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (QMSG_KEY) {
|
||||
|
||||
Reference in New Issue
Block a user