Files
rongtongjin/test-feishu-summary.ts
T

69 lines
1.7 KiB
TypeScript
Raw Normal View History

import { AlertService } from './src/utils/alert.js';
/**
* 测试飞书汇总报告功能
*/
async function testFeishuSummary() {
console.log('========================================');
console.log('测试飞书汇总报告功能');
console.log('========================================\n');
// 检查环境变量
const webhookUrl = process.env.WEBHOOK_URL;
if (!webhookUrl) {
console.error('❌ 错误: 未设置 WEBHOOK_URL 环境变量');
console.log('请在 .env 文件中配置 Webhook 地址');
process.exit(1);
}
console.log('✅ 飞书 Webhook 已配置');
console.log(`Webhook URL: ${webhookUrl}\n`);
// 创建告警服务实例
const alertService = new AlertService();
await alertService.init();
// 模拟汇总数据
const summaryData = {
runCount: 60,
totalPrices: 1250,
totalChanges: 15,
riseCount: 8,
fallCount: 7,
currentPrice: {
usSilver: '32.50',
londonSilver: '32.20',
spread: 0.300
},
recentChanges: [
{
timestamp: Date.now() - 3600000, // 1小时前
changeType: 'RISE',
currentSpread: 0.250
},
{
timestamp: Date.now() - 1800000, // 30分钟前
changeType: 'FALL',
currentSpread: -0.150
},
{
timestamp: Date.now() - 900000, // 15分钟前
changeType: 'RISE',
currentSpread: 0.300
}
]
};
console.log('发送测试报告...\n');
try {
await alertService.sendFeishuSummary(webhookUrl, summaryData);
console.log('\n✅ 测试完成!请检查飞书是否收到消息');
} catch (error) {
console.error('\n❌ 测试失败:', error);
process.exit(1);
}
}
// 运行测试
testFeishuSummary();