Skip to content

新增 Slack 通知渠道(Incoming Webhooks) - #130

Merged
todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a15844-833e-7008-9025-dd9102e40caa
Oct 20, 2026
Merged

todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a15844-833e-7008-9025-dd9102e40caa

Conversation

@todosdev

@todosdev todosdev Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 新增第 10 个通知渠道 Slack(Incoming Webhooks),定时提醒、POST /api/notify 与渠道测试推送均可送达 Slack 频道。
  • 配置仅 webhook_url 一个字段,按密钥处理(前端 password、后端返回 •••••• 并在保存时保留旧值);请求体用 JSON.stringify({ text }) 构造,避免 title/body 中的引号或换行拼出非法 JSON。
  • 新装实例与存量 D1 数据库都会获得 slack_config 列,生产库通过幂等迁移自动升级。

Changes

后端

  • worker/src/services/notify/slack.ts:新增 sendSlack,复用 validateOutboundUrl(禁止私有/内网地址),并额外强制 hostname 为 hooks.slack.com;文本格式为 _{title}_ + body + 可选 url。
  • worker/src/services/notify/index.ts:注册 slack: sendSlack,沿用既有 15s 超时与通知历史记录。
  • worker/src/types.ts:VALID_CHANNELS 加入 slack,NotificationConfig 加入 slack_config。
  • worker/src/db/queries/notifications.ts:upsertNotificationConfig 列名单加入 slack_config。
  • worker/src/db/schema.sql、worker/src/lib/setup.ts:建表 SQL 加入 slack_config TEXT NOT NULL DEFAULT '{}';runMigrations() 增加基于 PRAGMA table_info 的幂等 ALTER TABLE 迁移。
  • worker/src/routes/me.ts:GET 脱敏名单与 PUT secretFields 加入 webhook_url,防止 Slack Webhook URL 明文回传或被掩码覆盖。

前端

  • web/src/pages/channels/ChannelPage.tsx:新增 Slack 渠道卡片,webhook_url 使用密码输入框。
  • web/src/lib/channels.ts:item 渠道选择器加入 Slack。
  • web/src/locales/zh.json、web/src/locales/en.json:补充 channels.slack。
  • README.md、README.en.md:渠道数量从 9 更新为 10。

测试

  • worker/test/slack.test.ts:覆盖请求 URL/method/Content-Type、JSON 转义回环、空 URL、非 Slack 域名、内网地址、Slack 400 响应。
  • worker/test/migrations.test.ts:使用 node:sqlite 构造不含 slack_config 的旧 schema(带 en_ 前缀与既有数据),验证迁移后列存在、默认 '{}'、旧数据保留且重复执行幂等。

Testing

  • worker:vitest run — 4 个文件、29 个用例全部通过(含新增 9 个)。
  • worker:tsc --noEmit 通过;web:tsc -b 通过;web:vite build 通过。
  • biome format . 无差异;biome lint . 仅剩 items.ts 未使用导入等既有告警,本次未触碰该文件。
  • 未执行真实 Slack 工作区端到端验证(需要用户自己的 Slack App 与 Webhook URL)。建议合并前/后手工验证:渠道测试推送收到 _标题_ 消息、item 仅勾 Slack 时只发 Slack、未启用时不发送、GET /api/me/notifications 返回掩码且再次保存后测试仍成功。

备注:通用 Webhook 的 url 与企业微信的 webhook 仍未脱敏,属既有行为,本次按规格未改动。

- Add sendSlack using JSON.stringify-built mrkdwn text and enforce a
  hooks.slack.com hostname on top of validateOutboundUrl
- Register the slack sender, VALID_CHANNELS entry and slack_config type,
  and redact webhook_url in GET/PUT /api/me/notifications
- Add slack_config to both schemas plus an idempotent ALTER TABLE
  migration so existing D1 databases pick up the column
- Expose Slack in channel management, per-item channel selection and
  locales, and update the README channel count
- Cover request shape, JSON escaping, URL rejection, error status and
  the schema migration with tests

Checkpoint: VS9pA4yqaDBelmXiJbO6T
@todosdev
todosdev Bot merged commit 628b337 into main Oct 20, 2026
1 check passed
@mapxn
mapxn deleted the tds/conv-01a15844-833e-7008-9025-dd9102e40caa branch November 8, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants