From d5344e244ec59970418b62be8a961a79aab22362 Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Sat, 7 Feb 2026 17:07:54 +0000 Subject: [PATCH] Update: Add multi-channel support via tags --- AGENTS.md | 5 +++-- docs/plans/2026-02-07-design.md | 40 ++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index d60a9ec..0455d00 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -40,6 +40,7 @@ id: INTEGER PRIMARY KEY name: TEXT NOT NULL -- 通道名称,如 "告警群" type: TEXT NOT NULL -- apprise 协议,如 "discord", "telegram" config: JSON -- 配置参数(URL、token 等) +tags: JSON DEFAULT [] -- 标签,如 ["alerts", "production"] is_active: BOOLEAN DEFAULT 1 created_at: TIMESTAMP updated_at: TIMESTAMP @@ -68,8 +69,8 @@ variables: JSON ``` ### 核心功能 -1. **通道管理**: 增删改查通知通道 -2. **发送通知**: POST /api/notify 接收通知请求 +1. **通道管理**: 增删改查通知通道,支持标签分类 +2. **发送通知**: POST /api/notify 支持批量发送到多个通道或按标签发送 3. **历史记录**: 查看发送历史和统计 4. **手动发送**: Web 界面手动触发通知 diff --git a/docs/plans/2026-02-07-design.md b/docs/plans/2026-02-07-design.md index ccfc230..be026e1 100644 --- a/docs/plans/2026-02-07-design.md +++ b/docs/plans/2026-02-07-design.md @@ -68,11 +68,14 @@ class Channel(Base): name = Column(String, nullable=False, unique=True) # 通道名称,如 "告警群" type = Column(String, nullable=False) # apprise 协议,如 "discord" config = Column(JSON, nullable=False) # 配置参数 + tags = Column(JSON, default=list) # 标签,如 ["alerts", "urgent"] is_active = Column(Boolean, default=True) created_at = Column(DateTime, default=datetime.utcnow) updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) ``` +**tags 字段示例**: `["production", "alerts", "discord"]` - 用于批量选择通道 + **config 字段示例**: ```json { @@ -132,25 +135,45 @@ class Template(Base): ### 4.1 通知发送 API #### POST /api/notify -发送通知到指定通道。 +发送通知到指定通道(支持批量发送)。 **请求体**: ```json { - "channel": "告警群", // 通道名称或 ID - "title": "服务器告警", // 可选 + "channels": ["告警群", "运维群"], // 通道名称列表(与 tags 二选一) + "tags": ["alerts", "production"], // 标签列表,发送到所有匹配的通道 + "title": "服务器告警", // 可选 "body": "CPU 使用率超过 90%", - "priority": "high" // 可选,默认 normal + "priority": "high" // 可选,默认 normal } ``` +**说明**: +- `channels` 和 `tags` 二选一,不能同时为空 +- 使用 `channels`: 精确指定通道名称列表 +- 使用 `tags`: 发送到包含任一标签的所有通道 + **响应**: ```json { "success": true, - "notification_id": 123, - "channel": "告警群", - "status": "sent" + "results": [ + { + "channel": "告警群", + "channel_id": 1, + "status": "sent", + "notification_id": 123 + }, + { + "channel": "运维群", + "channel_id": 2, + "status": "sent", + "notification_id": 124 + } + ], + "total": 2, + "sent": 2, + "failed": 0 } ``` @@ -159,7 +182,8 @@ class Template(Base): **请求**: ``` -GET /api/notify?channel=告警群&body=测试消息&priority=normal +GET /api/notify?channels=告警群,运维群&body=测试消息&priority=normal +GET /api/notify?tags=alerts,urgent&body=测试消息&priority=high ``` ### 4.2 通道管理 API