connect Telegram
BotFather โ a supergroup with Topics โ the webhook. how the handoff channel works.
connect Telegram
Telegram is the operator's channel. every visitor maps to one forum topic in a supergroup you own, so each conversation is its own thread on your phone and you reply inline. it's optional โ without it, the chat still answers (topic ops just no-op).
the fastest path: krispy init
the wizard's first step guides this end to end and validates the token live:
it prints the BotFather steps, validates the pasted token via Telegram's getMe (green
โ @yourbot or a red retry), guides the supergroup-with-Topics + add-bot-as-admin setup,
takes the chat id, and persists botToken + chatId. do it by hand instead:
1. create the bot
- open @BotFather in Telegram.
- send
/newbot, follow the prompts (name +@username). - BotFather replies with a token like
123456:ABC-DEF....
set it as a secret: bunx wrangler secret put TELEGRAM_BOT_TOKEN.
2. create the supergroup with Topics
- create a Telegram group, then enable Topics (Group โ Edit โ Topics). enabling Topics upgrades it to a supergroup.
- add your bot to the group and make it an admin โ it needs the Manage Topics permission (that's how it creates a topic per visitor).
- get the group's chat id โ e.g. add
@RawDataBotbriefly and read it, or read it from the bot's updates. it looks like-1001234567890.
set it: bunx wrangler secret put TELEGRAM_CHAT_ID.
3. register the webhook
so your replies reach the Worker. the secret_token must equal TELEGRAM_WEBHOOK_SECRET:
how the handoff works
- a visitor's first message creates a forum topic named
<first 40 chars> ยท <session id>and stores thetopic โ sessionlink in KV. - every visitor message and every AI reply is mirrored into that topic (best-effort โ a Telegram outage never blocks the visitor's reply).
- when you type a reply in the topic, Telegram calls
POST /api/telegram/webhook. the Worker parses your reply, sets the session'shandedOffflag in the DO, and pushes your text to the visitor's browser live. the AI goes silent for that session. - the Worker ignores its own bot echoes, service messages (topic-created), and messages in the group's General topic โ only a real typed reply in a visitor topic counts.
honest about the effort: BotFather, the supergroup-with-Topics, and admin rights are a real five minutes of clicking. there's no way around a bot token if you want replies on your phone.