Repository navigation
新增 Slack 通知渠道(Incoming Webhooks) - #130
Merged
todosdev[bot] merged 1 commit intoOct 20, 2026
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /api/notify与渠道测试推送均可送达 Slack 频道。webhook_url一个字段,按密钥处理(前端password、后端返回••••••并在保存时保留旧值);请求体用JSON.stringify({ text })构造,避免 title/body 中的引号或换行拼出非法 JSON。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 脱敏名单与 PUTsecretFields加入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未使用导入等既有告警,本次未触碰该文件。_标题_消息、item 仅勾 Slack 时只发 Slack、未启用时不发送、GET /api/me/notifications返回掩码且再次保存后测试仍成功。