feat: automatic Telegram bot creation via managed-bot pairing#600
feat: automatic Telegram bot creation via managed-bot pairing#600mrubens wants to merge 2 commits into
Conversation
Adds a pairing service (Bot API 9.6 Managed Bots) so the setup wizard can create a deployment's Telegram bot with one tap in Telegram instead of manual BotFather token copy-paste. The bot token goes straight from the pairing service to the deployment server and never touches the browser.
|
No new code issues found. See task
Reviewed 494338c |
- Reserve the manager-bot token and webhook secret (and the manager username) as control-plane env vars so they never reach task sandboxes or the generic env editor; the manager token can export tokens for every managed child bot. - Stash the one-shot pairing token in Redis before persisting, so a failed save no longer strands a freshly created bot; the wizard keeps polling and the retry recovers from the stash.
|
Both review findings addressed in 494338c:
|
What
Adds an automatic path to Telegram setup using Telegram's Managed Bots feature (Bot API 9.6). Instead of walking through BotFather and copy-pasting a token, the setup wizard shows a QR code / deep link; the admin taps Create Bot once in Telegram, and Roomote receives the new bot's token directly, saves it, registers the webhook, and continues to the existing account-link step.
The bot token never passes through the browser: the wizard's server polls the pairing service with a server-side bearer token and feeds the result straight into the existing
saveAuthConfigpath.How it works
POST /api/webhooks/telegram-pairing(on a deployment configured with a manager bot) mints a pairing: a high-entropy suggested bot username (roomote_<slug>_bot, the correlation key), a secret poll token (stored hashed), and at.me/newbot/<manager>/<username>deep link.managed_botupdate to/api/webhooks/telegram-manager(secret-token verified); the service fetches the child bot's token viagetManagedBotTokenand marks the pairing ready.GET /api/webhooks/telegram-pairing/:idand receives the token exactly once (one-shot retrieval, 15-minute TTL in Redis).Configuration
R_TELEGRAM_PAIRING_URL=<public origin of a deployment running the pairing service>lights up the wizard's automatic path. Unset = manual token entry, unchanged.R_TELEGRAM_MANAGER_BOT_TOKEN,R_TELEGRAM_MANAGER_BOT_USERNAME,R_TELEGRAM_MANAGER_WEBHOOK_SECRET(manager bot needs Bot Management Mode enabled in BotFather). All endpoints 404 when unset.Changes
packages/communication:telegram-managed-botprotocol helpers (deep link, username slugs, update parsing,getManagedBotToken, manager webhook registration); mock Telegram server support forgetManagedBotToken.apps/api: pairing service handlers + Redis store, route policy entries with rate limits, token-auth bypass for the pairing paths (they authenticate with their own bearer poll token). Mounted under/api/webhooks/so the web app's existing webhook proxy exposes them.apps/web:comms.startTelegramPairing/comms.checkTelegramPairingcommands,telegramPairingAvailableon comms status, wizard UI with QR code (newqrcode.reactdep) and a manual-entry escape hatch both ways.apps/docs: Telegram provider page documents both paths.Testing
packages/communication)apps/api)apps/web)lint:fast,check-types, andknipclean.Notes
getManagedBotToken's response shape; the parser accepts both a bare string and{token}, and the manager webhook returns 500 on fetch failure so Telegram redelivers. Worth watching logs on the first live pairing.R_TELEGRAM_PAIRING_URLpoints at it; a follow-up can bake in a default URL.