Commit Graph

39 Commits

Author SHA1 Message Date
ryan a9b6234208 feat(通知模板): 支持 case 取值映射与事件名匹配渲染
Motivation:
让通知模板能够将 action、event 等原始枚举值映射为可读中文文案,并支持按事件名后缀匹配;同时简化 SafeW 消息发送格式,避免 Markdown 转义引入的显示问题。

Changes:

* 新增 `case` 模板函数,按值匹配 key/文案并支持末尾奇数参数作为默认值
* `case` 匹配兼容事件名后缀(如 trade.close 匹配 .close)
* `line` 前缀自动去除末尾冒号,避免重复冒号
* 模板渲染前自动注入 event 字段,便于模板按事件名取值
* SafeW 消息改为纯文本发送,移除 MarkdownV2 转义
2026-08-16 00:45:27 +08:00
ryan ae25409e56 feat(通知模板): 支持缺字段按空值渲染与空行省略
Motivation:
统一 crypto-strategy 与 trade-signal 两类交易信号的模板字段,使同一套通知模板可复用;字段缺失或为空时不再导致渲染报错或输出空行,通知内容更整洁。

Changes:

* 渲染器缺失字段改为按空值处理,新增 line 函数实现空值整行省略
* crypto-strategy 信号补充止盈价、止损价、平均价、收益额等模板字段
* trade-signal 信号保留原始报文中的额外字段以适配统一模板
* 修复结构化日志将 error 作为值直接输出导致的格式问题
2026-08-16 00:19:50 +08:00
ryan de7a52e81f feat(规则匹配): 事件名支持通配符匹配
Motivation:
通知规则的事件名此前仅支持精确匹配,无法用一条规则覆盖多类事件(如 trade.* 下的全部交易事件),规则配置维护成本高。本次引入通配符匹配,让规则可按模式批量命中事件,同时保证精确规则优先。

Changes:

* 事件名支持 * 和 ? 通配符匹配
* 匹配优先级:精确匹配 > 更具体的通配 > 泛匹配,同分时取更小 ID
* 精确命中未命中时回退为列出源下启用规则并按优先级挑选
* 抽取缓存预热逻辑为独立方法
* 更新文档说明事件名通配规则
2026-08-15 23:39:00 +08:00
ryan dc313fda13 feat(订阅): 新增 crypto-strategy 信号格式化器
Motivation:
crypto-strategy 交易信号采用 envelope 外壳与字符串化/嵌套的 payload,原有 trade_signal 格式化器无法解析,需要独立的转换逻辑以生成通知文本和事件数据。

Changes:

* 新增 crypto_strategy 消息转换器,解析 envelope 及嵌套、字符串化、扁平三种 payload 形态
* 根据平仓/止盈/卖出等标志推断交易动作,生成对应事件类型与中文通知文本
* 提取订单号、策略代码、价格、杠杆等字段用于通知数据
* 将消息转换器抽象为接口,订阅器按 formatter 配置选择对应实现
* 更新配置校验以支持 crypto_strategy 格式化器,并补充单元测试
2026-08-15 23:04:39 +08:00
ryan 0210b70bda perf(日志): 空轮询时不输出 Info 日志以减少噪音
Motivation:
轮询安全网关更新时,绝大多数周期没有新消息,持续输出 Info 日志会产生大量噪音并带来不必要的开销。仅在确有更新时才记录日志,便于聚焦真实事件。

Changes:

* 仅在存在更新时输出 getUpdates 日志
* 仅在拉取到群聊数据时输出 poll 日志
2026-08-15 18:19:41 +08:00
ryan 6bdd3eb786 feat(订阅配置): 支持环境变量展开并校验订阅连接地址
Motivation:
订阅连接地址中的敏感凭据不应硬编码到配置文件,改为通过环境变量注入,并自动跳过未配置或非 AMQP 协议的订阅,避免无效连接导致启动失败。

Changes:

* 订阅 URL 加载时展开环境变量并去除首尾空白
* 新增 AMQP 协议校验,仅 amqp/amqps 地址视为有效连接
* 非 AMQP 协议的订阅(如未配置的占位符)不再参与激活
* docker-compose 环境变量改用映射格式并加引号,规避特殊字符解析问题
* 补充环境变量展开与占位符跳过相关的单元测试
2026-08-15 17:57:09 +08:00
ryan 4fe9f83b89 chore(订阅): 重连错误日志补充 Broker 地址
Motivation:
多 Broker 部署场景下,订阅者重连失败时仅记录错误名称,难以快速定位是哪一台 Broker 连接异常。补充 Broker 地址并规范化错误字段,提升故障排查效率。

Changes:

* 重连失败日志新增 broker host 字段
* 新增 brokerHost 函数,从连接 URL 解析并输出主机地址
* 错误字段改为记录错误信息字符串,避免直接序列化 error 对象
2026-08-15 17:49:31 +08:00
ryan ab295d6d28 feat: log raw MQ body after dedup
Keep the original payload on post-dedup handling logs so accepted, filtered, and error paths can be traced.
2026-08-15 17:37:14 +08:00
ryan 6f846a0a3c feat: subscribe to RabbitMQ trade signals and notify by rules
Consume configurable queues, format signals (including period), share NotifyService with HTTP, and drop duplicate bodies within 1h.
2026-08-15 17:34:49 +08:00
ryan a07963e150 feat: enhance Safew chat handling and testing
- Updated `GroupsFromUpdates` function to return the number of updates processed, improving the polling mechanism.
- Added a new test `TestGroupsFromUpdatesCallbackAndJoinRequest` to validate handling of callback queries and join requests.
- Introduced `safewAllowedUpdates` to specify allowed update types in the polling request, enhancing chat management.
- Implemented `ensureWebhookCleared` method to manage webhook state before polling, improving reliability.
2026-08-15 01:56:12 +08:00
ryan 2000908bac feat: enhance Safew watcher initialization and token management
- Added functionality to list and start Safew tokens in the main server function, ensuring proper initialization of the Safew watcher.
- Introduced `ensureSafewWatcher` method in the ChannelHandler to manage Safew tokens during channel creation and updates.
- Implemented `StartTokens` method in the Watcher to handle multiple tokens efficiently.
- Enhanced error handling and logging for Safew watcher operations to improve observability.
2026-08-15 01:28:51 +08:00
ryan 5e783adf7a feat: implement chat merging and logging in Safew
- Introduced a new function `mergeAndLog` in the Watcher to handle merging Safew chats and logging newly discovered chats.
- Added a test `TestNewSafewChatsSkipsKnownIDs` to ensure that known chat IDs are skipped during the merging process.
- Enhanced the polling mechanism to improve chat management and reduce duplicates.
2026-08-15 01:10:35 +08:00
ryan e369f398d8 feat: enhance Safew error handling and polling mechanism
- Added error_msg field to safewAPIResponse for better error descriptions.
- Updated safewErrorDescription function to include error_msg in the output.
- Introduced a new test to verify that error messages are included in Safew error descriptions.
- Improved the polling mechanism in the Watcher to handle conflicts and ensure no overlapping polls occur.
2026-08-15 01:07:01 +08:00
ryan bd8a9ff96d feat: 增加 SafeW 已监控群列表接口
通过 getUpdates 将群写入 Redis,供创建/编辑渠道时选择 chat_id,避免前端重复传递 token。
2026-08-15 00:40:40 +08:00
ryan 0d0cd0c510 feat: 新增 SafeW 出站通知渠道
通过 Bot API sendMessage 投递渲染后的通知,MarkdownV2 自动转义标题与正文。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-14 00:58:44 +08:00
ryan 39f3774940 feat: 配置列表分页与钉钉机器人分钟级排队限流
统一 sources/templates/channels/rules 列表为分页响应,避免配置增多时全量返回;按钉钉 access_token 限制每分钟发送并在超限时等待下一分钟,降低触发官方封禁风险。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-10 00:34:26 +08:00
ryan c74bab3033 fix(数据存储): 确保列表查询返回空数组而非 null,并补充 HTTPie/Postman API 文档
Motivation:
当数据库查询无结果时,Go 的 `var slice []Type` 声明会使 JSON 序列化输出 `null`,而非 `[]`。这在 API 响应中造成不一致,也增加了客户端的空值处理负担。改为 `make([]Type, 0)` 后空结果统一输出为 `[]`,提升 API 规范性。

Changes:

* 统一 store 层所有 List 方法使用 `make([]Type, 0)` 初始化切片,覆盖 Sources、Channels、Templates、Rules、MessageLogs 及 RuleChannels 查询
* 新增完整的 cURL 示例文档,覆盖全部 API 端点(通知、Source、Template、Channel、Rule、消息记录)
* 新增 Postman Collection JSON 文件,可直接导入 HTTPie 使用,包含环境变量配置
2026-07-31 22:09:39 +08:00
ryan cecf8e72f5 fix(邮件发送): 适配 MailerSend SMTP 并迁移基础设施至 1Panel
Motivation:
将通知服务部署到 1Panel 生产环境,集成 MailerSend 邮件服务,修复 SMTP 协议中 MAIL FROM 命令因携带显示名而导致的发送失败问题。

Changes:

* 修复 SMTP MAIL FROM 命令传入带显示名的完整地址导致发送失败的问题,新增 extractEmailAddr 提取裸地址
* 更新 SMTP 配置为 MailerSend 真实凭证,From 地址适配其域名验证要求
* 移除 docker-compose 中内置的 MySQL/Redis 服务,改为依赖外部 1Panel 基础设施
* 更新环境变量为生产环境实际凭据
2026-07-31 17:28:35 +08:00
ryan a0d26fa3a3 refactor: rename database tables for notification entities to improve clarity and consistency 2026-07-02 16:04:18 +08:00
ryan c5225d8c97 feat: add Logbull remote logging via slog handler, tee to stdout 2026-06-27 15:17:59 +08:00
ryan 835b92ec00 fix: wire retry into router, fix Docker config path, fix condition error handling, remove dead code 2026-06-27 13:32:33 +08:00
ryan 2271a54139 feat: retry mechanism with exponential backoff 2026-06-27 13:26:13 +08:00
ryan 8e0c95edd9 feat: rule CRUD with enable/disable and message log query 2026-06-27 13:23:37 +08:00
ryan 682ca3df81 feat: management handlers — source, template, channel CRUD 2026-06-27 13:23:10 +08:00
ryan 2cf6601be0 feat: notify handler — parse, match, evaluate, render, route 2026-06-27 13:22:14 +08:00
ryan 127cf12656 feat: auth and rate limit middleware 2026-06-27 13:20:56 +08:00
ryan 83c4166f0c feat: engine — template renderer, rule matcher, channel router 2026-06-27 13:19:15 +08:00
ryan 49b2384cf7 feat: email adapter with SMTP TLS support 2026-06-27 13:17:32 +08:00
ryan 414c8c7cbf feat: channel adapters — dingtalk, wecom, bark 2026-06-27 13:15:57 +08:00
ryan 54af29e4fc feat: condition evaluator for rule filtering 2026-06-27 13:15:02 +08:00
ryan d7ae840d9a fix: atomic rate limiter and error handling in cache invalidation 2026-06-27 13:12:37 +08:00
ryan 69e32cb3ec feat: message parser with json/regex/text modes 2026-06-27 13:11:05 +08:00
ryan d030f0f0df fix: error handling in rule store 2026-06-27 13:09:34 +08:00
ryan 3f75699431 feat: redis cache layer with rule/channel caching and rate limiter 2026-06-27 13:07:56 +08:00
ryan a8e939da40 feat: rule and message_log store CRUD 2026-06-27 13:06:54 +08:00
ryan 236105ea9c feat: template and channel store CRUD 2026-06-27 13:04:57 +08:00
ryan 7cd84c8468 feat: store connection and source CRUD 2026-06-27 13:02:17 +08:00
ryan 3d0b91fe23 feat: data models and database migration 2026-06-27 12:59:33 +08:00
ryan 976ec3ca70 feat: project scaffold, config loading, skeleton main 2026-06-27 12:57:11 +08:00