guanghulab/webhook.js
Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

81 lines
2.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 之秋秋机器人 - webhook处理器
const { queryDeveloper, queryModule, queryRecentSyslogs, queryStats } = require('./utils/queryApi');
module.exports = async (req, res) => {
try {
const { text, senderStaffId, conversationId } = req.body;
if (text && text.content) {
// 先处理查询指令
const command = text.content.trim();
let reply = null;
// 查询指令判断
if (command.startsWith('查DEV-')) {
const match = command.match(/DEV-\d+/);
if (match) {
const result = await queryDeveloper(match[0]);
reply = result.message;
} else {
reply = '❌ 格式不对试试查DEV-004';
}
}
else if (command.startsWith('查M-')) {
const match = command.match(/M-[A-Z]+/);
if (match) {
const result = await queryModule(match[0]);
reply = result.message;
} else {
reply = '❌ 格式不对试试查M-DINGTALK';
}
}
else if (command === '查最近') {
const result = await queryRecentSyslogs(5);
reply = result.message;
}
else if (command === '查全部' || command === '全局统计') {
const result = await queryStats();
reply = result.message;
}
else if (command === '帮助' || command === 'help') {
reply = `📚 秋秋机器人指令帮助:
• 查DEV-004 - 查询开发者状态
• 查M-DINGTALK - 查询模块进度
• 查最近 - 查看最近5条SYSLOG
• 查全部 / 全局统计 - 查看全局统计
• 帮助 - 显示本帮助`;
}
// 如果不是查询指令才交给AI处理
if (!reply) {
// 这里调用原来的AI处理函数
const { processWithAI } = require('./ai');
reply = await processWithAI(text.content);
}
// 返回回复
res.json({
msgtype: 'text',
text: {
content: reply
}
});
} else {
res.json({
msgtype: 'text',
text: {
content: '收到'
}
});
}
} catch (error) {
console.error('webhook处理错误:', error);
res.json({
msgtype: 'text',
text: {
content: '❌ 服务器开小差了,稍后再试'
}
});
}
};