Files
kt-financial-system/apps/backend/utils
你的用户名 6108b9c5ed
Some checks failed
Deploy to Production / Build and Test (push) Has been cancelled
Deploy to Production / Deploy to Server (push) Has been cancelled
feat: 添加Telegram通知增强功能
 新增功能:
- 通知频率控制(防止消息轰炸)
- 消息去重机制(5分钟内相同内容不重复发送)
- 失败重试机制(最多3次重试)
- 通知历史记录(完整的发送日志)
- 优先级标识(低/普通/高/紧急)
- 批量通知支持(预留功能)

📊 数据库增强:
- telegram_notification_configs 新增字段:
  - priority: 通知优先级
  - rate_limit_seconds: 频率限制(秒)
  - batch_enabled: 批量通知开关
  - batch_interval_minutes: 批量间隔
  - retry_enabled: 重试开关
  - retry_max_attempts: 最大重试次数

- telegram_notification_history 新表:
  - 记录所有通知发送历史
  - 支持状态追踪(pending/sent/failed)
  - 支持重试计数
  - 支持错误信息记录

🔧 核心实现:
- telegram-bot-enhanced.ts: 增强版通知引擎
  - generateContentHash(): 内容hash生成
  - checkRateLimit(): 频率限制检查
  - isDuplicateMessage(): 消息去重
  - recordNotification(): 记录通知历史
  - updateNotificationStatus(): 更新通知状态
  - getPendingRetries(): 获取待重试通知
  - notifyTransactionEnhanced(): 增强版通知
  - retryFailedNotifications(): 失败重试

 测试结果:
- Bot Token: 8270297136:AAEek5CIO8RDudo8eqlg2vy4ilcyqQMoEQ8
- Chat ID: 1102887169
- Bot用户名: @ktcaiwubot
- 测试消息:  发送成功
2025-11-04 23:22:39 +08:00
..