Skip to content

feat(portal): one-click Telegram allowlist from recent senders#58

Merged
Germey merged 1 commit into
mainfrom
feat/portal-telegram-recent-senders
Jul 4, 2026
Merged

feat(portal): one-click Telegram allowlist from recent senders#58
Germey merged 1 commit into
mainfrom
feat/portal-telegram-recent-senders

Conversation

@acedatacloud-dev

Copy link
Copy Markdown
Member

What & why

Telegram 编辑器的白名单之前只能手敲数字 ID。现在加了 「Load recent senders」:一键 peek getUpdates,列出最近给 bot 发过消息的人(名字 + @username + id),点一下就加进 allowed_senders。setup 时你给 bot 发条消息,portal 一键拉到你的 id 加白名单,不用去 @userinfobot 查。

  • 后端 telegram_recent_senders() + GET /api/telegram/senders
  • 前端「Load recent senders」按钮 + 结果列表 + addTgSender(点选加到 #tgsenders textarea)。

关键设计:与 channels start 的关系

Telegram 同一时刻只允许一个 getUpdates 消费者,所以这个功能主要用于 setup 阶段(channels start 停着时)。peek 用 timeout=0不传 offset —— 纯只读,绝不 ack / 推进 offset,不会让正在跑的 poller 丢消息。若 start 正在跑 → 409 → 清晰提示「先停 channels start,或手填 ID」。token 只在 URL path,从不记日志。

Testing

  • ruff clean;全套件 490 pass / 1 skip(3 个 pre-existing Windows-only fail 与本 PR 无关)。
  • 5 个新测试:解析/去重、409→busy、空、live 路由、静态守卫。
  • Playwright:「Load recent senders」按钮渲染 + 点击链路处理(死 token → 正确错误态,不崩)。真实解析/去重/409 逻辑由后端单测覆盖。

🤖 对抗评审

Reviewer: Claude general-purpose subagent(此机无 Codex),read-only,一轮。VERDICT: CLEAN:

  1. offset 安全 — peek 不传 offset + timeout=0,只读不 ack,不会让 running poller 丢消息;并发只导致一方 409(双方都正确处理)。
  2. token 不泄露 — 错误只 exception class name,不 echo URL;日志只 path 无 secret。
  3. 解析健壮result 非 list → [];畸形 / edited_message / 缺 from / 非 int id 全跳过;去重正确;name 非空、username str|None、chat_type str|None,无 KeyError/TypeError。
  4. 前端addTgSender 用后端校验过的数字 id 字符串;guard current()/#tgrecent/token_resolvable;单编辑器无 DOM id 冲突。
  5. 隐私 — sender 信息只给 loopback + token-gated 页面,不落盘不记日志。
  6. DoSlimit:100 封顶,dedup dict ≤100,httpx timeout 15s。

RISK,无需 fix/rebut。

The Telegram editor's allowlist was manual numeric-id entry. Now a 'Load recent senders' button peeks at getUpdates and lists whoever recently messaged the bot; click a name to add its id to allowed_senders.

Peek uses timeout=0 and NO offset, so it only reads and never acknowledges/drops updates for a running poller. It can't run concurrently with 'channels start' (Telegram allows one getUpdates consumer) -> that surfaces as a clear 409 'stop channels start / add IDs by hand' message. Token stays in the URL path, never logged. Backend telegram_recent_senders() + GET /api/telegram/senders; 5 new tests (parse/dedup/409/empty/route + static guard). Full suite 490 pass/1 skip. Playwright: button renders + click path handled (dead-token error state). Adversarial (Explore subagent): VERDICT CLEAN.
@Germey Germey merged commit 0a322f8 into main Jul 4, 2026
3 checks passed
@Germey Germey deleted the feat/portal-telegram-recent-senders branch July 4, 2026 07:08
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.

2 participants