mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
- Make TELEGRAM_BOT_TOKEN and ALLOWED_CHAT_IDS optional environment variables - Add telegramEnabled flag to conditionally initialize the bot on startup - Introduce persistent owner ID for unified user identity across web and Telegram auth - Update Telegram bot to accept configuration in constructor instead of using global config - Handle empty allowlist by showing chat ID prompt on /start command - Use owner ID instead of Telegram user ID for API authentication - Add conditional Telegram support checks in auth routes with clear error messages - Update documentation to explain optional Telegram configuration and binding workflow - Rename telegramUserId to userId in auth middleware for clarity
2.8 KiB
2.8 KiB
name, description
| name | description |
|---|---|
| telegram-optional-config | Make Telegram optional; unify owner id auth |
Plan
基于你的决策更新计划:绑定流程为“提示 chat id + 重启”,允许列表仅来自 env;统一 uid 为 owner id,确保 Web/Telegram 登录语义一致。
Requirements
- 未配置 Telegram 相关 env 时,服务端不退出,Web/CLI 正常可用。
- Telegram bot 仅在配置
TELEGRAM_BOT_TOKEN时启动;ALLOWED_CHAT_IDS仅来自 env。 - 绑定流程为:bot 提示 chat id → 用户配置 env → 重启服务。
uid统一为 owner id(accessToken 与 telegram 登录一致)。
Scope
- In: 配置解析、启动流程、auth 逻辑、owner id 持久化、文档更新。
- Out: 自动绑定、DB/动态 allowlist、复杂 UI 设置页。
Files and entry points
server/src/configuration.tsserver/src/index.tsserver/src/telegram/bot.tsserver/src/web/routes/auth.tsserver/src/web/jwtSecret.ts(或新增轻量 owner id 持久化文件)README.mdserver/README.md
Data model / API changes
- 增加“owner id”持久化(建议
dataDir/owner-id.json),用于统一 auth 的uid。 - 不新增 Telegram 绑定 API(按“提示 chat id + 重启”流程)。
Action items
[ ] 配置层改为 Telegram 可选:TELEGRAM_BOT_TOKEN/ALLOWED_CHAT_IDS 允许为空;加入 telegramEnabled,allowedChatIds 为空数组可接受。
[ ] 生成并持久化 ownerId(数值或 UUID -> 数值映射),/api/auth 的 uid 始终为 ownerId。
[ ] 启动逻辑按 telegramEnabled 分支:未启用仅启动 Web/Socket/SSE,并打印 Telegram disabled 日志。
[ ] Telegram bot 行为:
- 已启用但 ALLOWED_CHAT_IDS 未配置:仅响应 /start,提示当前 chat id 与配置示例;不开放其它命令/通知。
- 已启用且 allowlist 配置:按现有流程运行。
[ ] /api/auth 调整:
- accessToken:验证后直接使用 ownerId。
- telegram:若 Telegram 未启用,返回清晰错误;启用时校验 initData 与 allowlist,但仍签发 uid = ownerId。
[ ] 文档更新:说明 Telegram 配置可选;新增“获取 chat id 并重启绑定”的指引。
Testing and validation
- 仅设置
CLI_API_TOKEN启动:服务正常、Web 登录可用、bot 不启动。 - 设置
TELEGRAM_BOT_TOKEN且未配 allowlist:/start能提示 chat id,其它命令受限。 - 完整配置
TELEGRAM_BOT_TOKEN+ALLOWED_CHAT_IDS:通知与 Mini App 正常。 uid在两种登录方式下均为ownerId。
Risks and edge cases
ownerId生成/持久化失败会导致登录不稳定。- 只靠 env allowlist,运维更新需重启,需在文档强调。
- Telegram 未启用但 Web 侧仍可能尝试 Telegram auth(应给清晰错误)。
Open questions
- None.