📦 Notification System — 多通道通知
v1.0.1统一管理 WhatsApp、Telegram、邮件等外发通知,支持模板、定时、投递追踪与限速,一站式完成多渠道消息分发。
详细分析 ▾
运行时依赖
版本
- 更新了待处理通知队列 (queue/pending.json) - 文档或逻辑无变更;底层通知系统及用法保持不变
安装命令
点击复制技能文档
# 通知系统 Agent 所有渠道(WhatsApp、Telegram、Email)的统一外发通知管理。 ## 架构 `` notification-system/ ├── SKILL.md # This file ├── templates/ # Message templates by channel & type │ ├── whatsapp/ # WhatsApp templates │ ├── telegram/ # Telegram templates │ └── email/ # Email templates ├── queue/ # Pending notification queue ├── logs/ # Delivery logs ├── rate-limiters.json # Rate limit configuration └── config/ # Channel configs ` ## 支持的渠道 | Channel | Config | Rate Limits | |---------|--------|-------------| | WhatsApp | channels.whatsapp | 60 msg/min, 1000/day | | Telegram | channels.telegram | 30 msg/sec, 20 msg/min | | Email (Outlook) | office365-connector | 30 msg/hour, 300/day | ## 速率限制 各渠道默认限制: - WhatsApp:1 消息/秒(安全),突发 5 条 - Telegram:API 硬限制 30 消息/秒 - Email:60 邮件/小时,防止被判为垃圾邮件 速率限制配置:notification-system/rate-limiters.json ## 模板变量 所有模板均支持: ` {{recipient}} - 目标名称/ID {{date}} - 当前日期 {{time}} - 当前时间 {{subject}} - 消息主题 {{body}} - 消息正文 {{cta_url}} - 行动按钮链接 {{sender_name}} - 商家/发送者名称 {{company}} - 公司名称 ` ## 发送通知 ### WhatsApp `bash # Via message tool message send --channel whatsapp --target "+18184389562" --message "Your appointment is confirmed for {{date}}" ` ### Telegram `bash # Via message tool message send --channel telegram --target "655641853" --message "System alert: {{subject}}" ` ### Email `bash # Via outlook skill outlook send --to "recipient@email.com" --subject "{{subject}}" --body "{{body}}" ` ## 队列系统 通知排队于 notification-system/queue/pending.json: `json { "id": "uuid", "channel": "whatsapp|telegram|email", "target": "recipient-id", "template": "template-name", "variables": {}, "scheduled_at": "ISO8601 or null", "created_at": "ISO8601", "priority": "high|normal|low", "status": "pending|sent|failed|delivered", "attempts": 0, "last_error": null } ` ## 调度 定时通知保存在 notification-system/queue/scheduled.json,采用类 cron 调度。使用 cron 作业运行 notification-system/process-queue.js 处理定时项。 ## 投递跟踪 日志保存在 notification-system/logs/delivery-YYYY-MM-DD.json: `json { "id": "notification-uuid", "timestamp": "ISO8601", "channel": "whatsapp", "target": "+1...", "template": "appointment-confirm", "status": "delivered|sent|failed", "latency_ms": 450, "error": null } ` ## 模板管理 模板保存在 notification-system/templates/{channel}/{type}.md: ` templates/ ├── whatsapp/ │ ├── appointment-confirm.md │ ├── appointment-reminder.md │ ├── payment-received.md │ ├── status-update.md │ ├── broadcast-promotion.md │ └── support-acknowledged.md ├── telegram/ │ ├── system-alert.md │ ├── status-report.md │ ├── daily-brief.md │ └── broadcast.md └── email/ ├── invoice.md ├── welcome.md └── notification.md ` ## 处理队列 处理待发送通知: `bash node notification-system/process-queue.js ` ## 状态命令 - 列出待发送:Get-Content queue/pending.json | ConvertFrom-Json - 查看速率限制:Get-Content rate-limiters.json - 查看最近日志:Get-Content logs/delivery-$(Get-Date -Format 'yyyy-MM-dd').json ## 最佳实践 1. 合理批量:对同类通知分组,尊重安静时段 2. 备用渠道:WhatsApp 失败时转 Telegram,再转 Email 3. 去重:24 小时内不重复发送同一通知 4. 退订处理:立即响应 STOP/退订请求 5. 个性化:使用收件人姓名及相关变量 6. 监控投递:检查日志以发现失败并重试 ## 优先级处理 - high:系统警报、紧急项 → 跳过速率限制队列 - normal:普通通知 → 正常速率限制 - low`:营销、非紧急 → 最严格速率限制