新增功能: - 在LLM趋势分析中集成历史告警上下文,提供最近3次已触发告警的记录 - LLM自动判断本次分析是否与历史告警相似,避免重复通知 - 新增shouldNotify和notifyReason字段,支持智能通知决策 技术改进: - 扩展TrendAnalysisResponse类型,增加通知决策字段 - 数据库服务新增getRecentTriggeredAnalyses()方法 - LLM客户端新增analyzeTrendWithHistory()和相关方法 - 趋势分析服务集成历史上下文获取和通知决策逻辑 测试验证: - 创建test-db-history-method.ts验证数据库方法 - 创建test-llm-history-context.ts测试历史上下文功能 - 通过TypeScript类型检查和构建验证 这个功能可以有效减少重复告警,提升告警质量,避免通知疲劳。 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
86 lines
2.4 KiB
TypeScript
86 lines
2.4 KiB
TypeScript
import 'dotenv/config';
|
|
|
|
/**
|
|
* 测试飞书 Webhook
|
|
*/
|
|
async function testFeishuWebhook() {
|
|
const webhookUrl = process.env.WEBHOOK_URL;
|
|
|
|
if (!webhookUrl) {
|
|
console.error('❌ 未配置 WEBHOOK_URL 环境变量');
|
|
return;
|
|
}
|
|
|
|
console.log('📡 Webhook URL:', webhookUrl);
|
|
console.log('🔍 开始测试...\n');
|
|
|
|
// 测试消息格式
|
|
const testMessages = [
|
|
{
|
|
name: '飞书文本消息',
|
|
message: {
|
|
msg_type: 'text',
|
|
content: {
|
|
text: '价格变化告警测试\n时间: 2026/1/13 00:31:21\n变化类型: 下跌\n美白银: 86.14\n伦敦银: 86.023\n价差: 0.117'
|
|
}
|
|
}
|
|
},
|
|
{
|
|
name: '自定义文本消息(当前代码格式)',
|
|
message: {
|
|
msgtype: 'text',
|
|
text: {
|
|
content: '价格变化告警\n时间: 2026/1/13 00:31:21\n变化类型: 下跌\n美白银: 86.14\n伦敦银: 86.023\n价差: 0.117'
|
|
}
|
|
}
|
|
}
|
|
];
|
|
|
|
for (const test of testMessages) {
|
|
console.log(`\n========================================`);
|
|
console.log(`测试: ${test.name}`);
|
|
console.log('========================================');
|
|
console.log('请求体:', JSON.stringify(test.message, null, 2));
|
|
|
|
try {
|
|
const response = await fetch(webhookUrl, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(test.message)
|
|
});
|
|
|
|
console.log(`\n状态码: ${response.status} ${response.statusText}`);
|
|
console.log(`ok: ${response.ok}`);
|
|
|
|
// 获取响应体
|
|
const responseText = await response.text();
|
|
console.log(`响应体: ${responseText || '(空)'}`);
|
|
|
|
// 尝试解析为 JSON
|
|
try {
|
|
const jsonResponse = JSON.parse(responseText);
|
|
console.log('响应 JSON:', JSON.stringify(jsonResponse, null, 2));
|
|
} catch {
|
|
// 不是 JSON
|
|
}
|
|
|
|
// 显示响应头
|
|
console.log('\n响应头:');
|
|
response.headers.forEach((value, key) => {
|
|
console.log(` ${key}: ${value}`);
|
|
});
|
|
|
|
} catch (error: any) {
|
|
console.error(`\n❌ 请求失败:`, error.message);
|
|
console.error('错误详情:', error);
|
|
}
|
|
}
|
|
|
|
console.log('\n========================================');
|
|
console.log('✅ 测试完成');
|
|
console.log('========================================');
|
|
}
|
|
|
|
// 运行测试
|
|
testFeishuWebhook().catch(console.error);
|