Skip to content

feat: 支持 ntfy 一等通知渠道(P6-A) - #1271

Merged
ZhuLinsen merged 4 commits into
ZhuLinsen:mainfrom
massif-01:feat/1200-p6-ntfy-notification
May 13, 2026
Merged

feat: 支持 ntfy 一等通知渠道(P6-A)#1271
ZhuLinsen merged 4 commits into
ZhuLinsen:mainfrom
massif-01:feat/1200-p6-ntfy-notification

Conversation

@massif-01

Copy link
Copy Markdown
Collaborator

PR Type

  • fix
  • feat
  • refactor
  • docs
  • chore
  • test

Background And Problem

Issue #1200 的 P6-A 需要补齐长尾通知渠道中的 ntfy 一等渠道支持。当前项目已有多渠道通知、配置诊断、Web 配置测试和 GitHub Actions 通知环境映射,但 ntfy 还不能作为正式渠道参与普通发送、聚合日报发送、路由校验、配置诊断和 Web 测试。

本 PR 只实现 ntfy,不混入 Gotify / WebPush / Apprise / Bark 等后续渠道。NTFY_URL 按现有 ASTRBOT_URL 风格定义为完整 topic endpoint,例如 https://ntfy.sh/my-topichttps://self-hosted:port/my-topic;发送时解析 server root 和 topic,并使用 ntfy JSON publish API,避免中文标题依赖 HTTP header 编码。

Scope Of Change

  • 新增 src/notification_sender/ntfy_sender.py,实现 ntfy JSON publish 发送、topic endpoint 解析、Bearer token、SSL verify 复用和错误处理。
  • 接入 NotificationChannel.NTFY 到普通通知发送、聚合日报 _send_notifications()、配置检测、路由白名单、诊断和系统配置服务。
  • Web/API 通知测试支持 ntfy,并对 NTFY_URL topic path 做校验与脱敏展示。
  • GitHub Actions daily analysis workflow 映射 NTFY_URL / NTFY_TOKEN,并补齐静态测试。
  • 更新 .env.exampledocs/notifications.mddocs/full-guide.mddocs/full-guide_EN.mddocs/CHANGELOG.md;未更新 README,细节保留在专题文档。
  • 新增/扩展后端、API、workflow、前端面板测试。
  • 附加两张真实 ntfy smoke 截图,作为本 PR 的人工端到端验证证据。

Issue Link

Refs #1200

Verification Commands And Results

python -m py_compile src/notification_sender/ntfy_sender.py src/notification.py src/config.py src/core/pipeline.py src/services/system_config_service.py

结果:通过。

.venv/bin/python -m pytest tests/test_notification.py tests/test_pipeline_notification_image_routing.py tests/test_notification_sender.py tests/test_notification_diagnostics.py tests/test_system_config_service.py tests/test_notification_routing.py

结果:248 passed, 43 subtests passed in 8.23s

.venv/bin/python -m pytest tests/test_notification_sender.py tests/test_notification.py tests/test_pipeline_notification_image_routing.py tests/test_notification_diagnostics.py tests/test_notification_routing.py tests/test_system_config_service.py tests/test_system_config_api.py tests/test_daily_analysis_workflow_notification_env.py

结果:277 passed, 35 warnings, 43 subtests passed

cd apps/dsa-web && npm run test -- NotificationTestPanel

结果:3 passed

cd apps/dsa-web && npm run lint

结果:通过。

cd apps/dsa-web && npm run build

结果:通过;保留既有 Vite chunk size warning。

git diff --check

结果:通过。

PATH=.venv/bin:$PATH ./scripts/ci_gate.sh

结果:1898 passed, 2 deselected, 42 warnings, 166 subtests passed in 45.97sbackend-gate: all checks passed

真实 ntfy smoke 验证

  1. 直接 curl JSON publish 到 https://ntfy.sh,topic 为 dsa,ntfy 返回 message event:

curl ntfy smoke

  1. 使用本 PR 的 NtfySender 发送,命令返回 True,手机 ntfy app 收到 DSA ntfy sender smoke / hello from DSA sender

iOS ntfy smoke

Compatibility And Risk

  • 兼容性:新增配置项默认不配置即不启用,不改变既有通知渠道默认行为。
  • NTFY_URL 必须包含 topic path;仅配置 server root(如 https://ntfy.sh)会被诊断/配置测试判定为无效,避免误发送到空 topic。
  • WEBHOOK_VERIFY_SSL 现在同时影响 custom webhook、AstrBot 和 ntfy,已在 .env.example 和通知文档中说明。
  • MARKDOWN_TO_IMAGE_CHANNELS 对既有渠道保持原语义,仅显式排除 ntfy,因为本实现只支持文本/JSON publish,不走图片发送路径。
  • 第三方 API 依据:ntfy 官方 JSON publish 文档 https://docs.ntfy.sh/publish/
  • 风险:公开 ntfy.sh topic 本身可被订阅;文档建议使用不可猜测 topic 或自建服务,并可配置 NTFY_TOKEN

Rollback Plan

如需回滚,直接 revert this PR 即可;未引入数据迁移,也不会改写已有 .env。若用户已新增 NTFY_URL / NTFY_TOKEN,回滚后这些配置会被旧版本忽略,可手动从环境变量或 GitHub Actions secrets 中移除。

EXTRACT_PROMPT Change (if applicable)

未修改 src/services/image_stock_extractor.py 中的 EXTRACT_PROMPT

展开 / Expand: Full EXTRACT_PROMPT
N/A

Checklist

  • 本 PR 有明确动机和业务价值 / This PR has a clear motivation and value
  • 已提供可复现的验证命令与结果 / Reproducible verification commands and results are included
  • 已评估兼容性与风险 / Compatibility and risk have been assessed
  • 已提供回滚方案 / A rollback plan is provided
  • 若涉及用户可见变更,已同步更新相关文档与 docs/CHANGELOG.mdREADME.md 仅在首页级信息变化时更新,细节优先写入 docs/*.md / If user-visible changes are included, relevant docs and docs/CHANGELOG.md are updated; README.md is updated only for homepage-level changes, with details kept in docs/*.md

@github-actions

github-actions Bot commented May 12, 2026

Copy link
Copy Markdown

🤖 自动审查报告

项目 结果
📊 变更文件 30 个
➕ 新增行数 681 行
➖ 删除行数 24 行
🔍 静态检查 ✅ 通过
🧠 AI 审查 ✅ 已完成

📁 修改的文件

  • 📝 .env.example (+8/-2)
  • 📝 .github/workflows/daily_analysis.yml (+5/-0)
  • 📝 api/v1/schemas/system_config.py (+1/-0)
  • 📝 apps/dsa-web/src/components/settings/NotificationTestPanel.tsx (+1/-0)
  • 📝 apps/dsa-web/src/components/settings/__tests__/NotificationTestPanel.test.tsx (+1/-0)
  • 📝 apps/dsa-web/src/types/systemConfig.ts (+1/-0)
  • 📝 docs/CHANGELOG.md (+1/-0)
  • 🆕 docs/assets/issue-1200-ntfy-curl-smoke.png (+0/-0)
  • 🆕 docs/assets/issue-1200-ntfy-ios-smoke.png (+0/-0)
  • 📝 docs/full-guide.md (+8/-4)
  • 📝 docs/full-guide_EN.md (+8/-4)
  • 📝 docs/notifications.md (+18/-4)
  • 📝 src/config.py (+27/-0)
  • 📝 src/core/config_registry.py (+35/-3)
  • 📝 src/core/pipeline.py (+6/-0)
  • 📝 src/notification.py (+14/-1)
  • 📝 src/notification_routing.py (+1/-0)
  • 📝 src/notification_sender/__init__.py (+1/-0)
  • 🆕 src/notification_sender/ntfy_sender.py (+125/-0)
  • 📝 src/services/notification_diagnostics.py (+36/-1)

... 还有 10 个文件


🧠 AI 代码审查意见

结论

Ready to Merge

审查结果

必要性

通过
理由:PR 描述明确指出这是 Issue #1200 P6-A 的一部分,旨在补齐长尾通知渠道中的 ntfy 一等渠道支持。这具有明确的业务价值和问题背景。

关联性

通过
证据:PR 描述中的 "Issue Link: Refs #1200" 明确关联了现有 Issue。

类型判定

通过
建议类型:feat, docs, test
理由:PR 标题为 feat,描述中 PR Type 也勾选了 feat, docs, test。变更范围涵盖了新增功能实现、文档更新和测试,与所选类型完全匹配。

描述完整性

完整
理由:PR 描述完整包含了背景、变更范围、详细的验证命令与结果(包括真机验证截图和 ./scripts/ci_gate.sh 的执行结果)、兼容性与风险评估、回滚方案,以及用户可见变更的文档同步情况。所有 Checklist 项均已勾选。CI 检查状态也证实了 Python 语法和关键 Flake8 检查已通过。

风险级别


关键风险:

  1. 配置项独立性与兼容性:新增配置项默认不配置即不启用,不改变既有通知渠道默认行为,兼容性良好。
  2. NTFY_URL 校验:要求 NTFY_URL 必须包含 topic path,避免误发送,并通过诊断和配置测试进行校验。
  3. WEBHOOK_VERIFY_SSL 范围:明确 WEBHOOK_VERIFY_SSL 现在同时影响 custom webhook、AstrBot 和 ntfy,并在文档中说明,用户需知情。
  4. MARKDOWN_TO_IMAGE_CHANNELS 排除ntfy 渠道被显式排除在图片发送路径之外,符合其 JSON publish 文本通知的特性。
  5. ntfy.sh Topic 公开性:已在风险评估中指出公开 ntfy.sh topic 可被订阅,并建议使用不可猜测 topic 或自建服务,并配置 NTFY_TOKEN

综上,风险评估全面,且已通过设计和文档说明进行规避或提醒。

必改项

无。

建议项

无。


总评:
此 PR 提供了 ntfy 一等通知渠道的完整支持,包括后端实现、Web 前端接入、配置管理、诊断、路由、CI/CD 环境映射和全面的文档更新。PR 描述极其详细,验证充分,风险评估和回滚方案也考虑周全。代码变更与 PR 描述高度一致,并通过了自动化 CI 检查和本地验证。这是一个高质量的 PR,可以直接合入。


💡 提示: 请确保代码已通过本地测试,并遵循项目代码规范。

@massif-01 massif-01 changed the title feat: add ntfy notification channel feat: 支持 ntfy 一等通知渠道(P6-A) May 12, 2026
@massif-01
massif-01 marked this pull request as ready for review May 12, 2026 21:09
@massif-01
massif-01 requested a review from ZhuLinsen as a code owner May 12, 2026 21:09

@ZhuLinsen ZhuLinsen left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

评审结论

  • 必要性:通过。Issue #1200 的 P6-A 明确要求补齐 ntfy 一等通知渠道,本 PR 覆盖发送、诊断、Web 测试、路由、Actions 和文档,动机成立。
  • 是否有对应 issue:有,Refs #1200
  • PR 类型:feat/docs/test。新增运行时通知渠道,同时补充配置文档、CHANGELOG 和对应后端/API/Web/workflow 测试。
  • description 完整性:完整。已包含背景、范围、兼容性与风险、验证命令与结果、外部 ntfy JSON publish 依据、README 不更新理由、回滚方案和 EXTRACT_PROMPT 说明,符合 AGENTS.md 对用户可见变更的交付要求。
  • 是否可直接合入:可。当前 CI 全部成功,文档与 .env.example / docs/CHANGELOG.md 已同步,未发现当前 diff 新引入的阻断性正确性或兼容性问题;mergeable_state=blocked 不单独构成阻断。

🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 789d040864

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/config.py Outdated
ZhuLinsen

This comment was marked as resolved.

@massif-01

massif-01 commented May 12, 2026

Copy link
Copy Markdown
Collaborator Author

已处理这轮 OpenReview 反馈:

  1. resolve_ntfy_endpoint() 现在只接受 http / https scheme。这样 NotificationService.detect_configured_channels()、notification diagnostics、Web/API 临时测试配置都会和 Config.validate_structured() / Web schema 的 URL 口径保持一致;ftp://...ntfy://... 不会再被误判为已配置 ntfy 渠道。
  2. 补了 invalid scheme 回归覆盖:sender 不发请求、runtime detector 不启用 ntfy、diagnostics 报 invalid_ntfy_url
  3. 修正了 WEBHOOK_VERIFY_SSL 文档口径,改为“读取该配置的 webhook-style HTTPS 通知请求”,避免把实际影响范围误写成 custom webhook / AstrBot / ntfy 的不完整列表。
  4. 上一条 process blocker 里提到的 CI pending 是当时状态;后续我已看到 backend-gate / web-gate / docker-build 均通过。

本地验证:

  • python -m py_compile src/notification_sender/ntfy_sender.py
  • git diff --check
  • .venv/bin/python -m pytest tests/test_notification_sender.py tests/test_notification.py tests/test_notification_diagnostics.py tests/test_config_validate_structured.py tests/test_system_config_service.py -> 285 passed, 43 subtests passed
  • PATH=.venv/bin:$PATH ./scripts/ci_gate.sh -> 1903 passed, 2 deselected, 42 warnings, 166 subtests passed

提交:93efaa7 fix: align ntfy endpoint validation

@ZhuLinsen ZhuLinsen left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

评审结论

  • 必要性:通过。Issue #1200 P6-A 明确要求补齐 ntfy 一等通知渠道,本 PR 覆盖发送、诊断、Web 测试、路由、Actions 与文档,范围匹配。
  • 是否有对应 issue:有,Refs #1200
  • PR 类型:feat。新增运行时通知渠道能力,附带必要的 docs/test 更新。
  • description 完整性:完整。缺失项:无;已包含背景、范围、验证命令与结果、兼容性风险、官方 ntfy API 依据、README 不更新理由、回滚方案和 EXTRACT_PROMPT 说明。
  • 是否可直接合入:可。当前阻断型 CI 已通过;mergeable_state=blocked 结合仓库保护策略本身不构成代码阻断,未发现必须修改项。

🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。

@ZhuLinsen
ZhuLinsen merged commit 9f56238 into ZhuLinsen:main May 13, 2026
10 checks passed
davidzhengdai pushed a commit to davidzhengdai/daily_stock_analysis that referenced this pull request May 13, 2026
* feat: add ntfy notification channel

* test: add ntfy smoke evidence images

* fix: validate ntfy endpoint in structured config

* fix: align ntfy endpoint validation
Anyone878 pushed a commit to Anyone878/daily_stock_analysis that referenced this pull request May 17, 2026
* feat: add ntfy notification channel

* test: add ntfy smoke evidence images

* fix: validate ntfy endpoint in structured config

* fix: align ntfy endpoint validation
EchoingFootsteps pushed a commit to EchoingFootsteps/daily_stock_analysis that referenced this pull request Jul 4, 2026
* feat: add ntfy notification channel

* test: add ntfy smoke evidence images

* fix: validate ntfy endpoint in structured config

* fix: align ntfy endpoint validation
bmwu pushed a commit to bmwu/daily_stock_analysis that referenced this pull request Aug 24, 2026
* feat: add ntfy notification channel

* test: add ntfy smoke evidence images

* fix: validate ntfy endpoint in structured config

* fix: align ntfy endpoint validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants