Identify the current consumer
Telegram stores the webhook registration against the bot token. Stopping an HTTP server leaves that registration in place. A polling worker using the same token can start successfully as a process and still fail to receive updates. Decide which deployment should own the bot and stop any development copy using its token.
If the existing webhook still works, send exactly /start from a private chat and note the reply. On the supplied example, GET /healthz only reaches the listener. Checking both gives you a baseline for the migration. Keep its project files, including .telegram-state, when changing delivery modes.
Move the existing deployment to polling
- Stop the webhook deployment. In Settings, change to the Telegram polling profile for the same language, keeping the current files. Check
MAIN_FILEand the savedTELEGRAM_BOT_TOKEN. - Start the deployment. The supplied starter reads its saved registration and checks Telegram’s current webhook URL. If the two match, it deletes the webhook with pending updates preserved, then begins polling.
- If a different deployment registered the webhook, remove it using that integration or Telegram’s
deleteWebhookmethod. Keepdrop_pending_updatesfalse if messages in transit should still arrive. Restart the polling worker.
Use a fresh private /start message after the switch. Look for “Your bot is running.” A group command or arbitrary text is a poor test for this starter because its sample reply handler matches only that private command.
Account for duplicate messages
The examples remember recent update IDs in the deployment volume. Keeping the state directory lets the new process recognize an update its predecessor already handled. A crash between sending a reply and saving the ID leaves a small window where an incoming update can trigger another reply.
For a bot that records orders or accepts registrations, use the update ID when recording the result of the operation. On a retry, check the stored result before repeating the action. A bounded list of recent IDs is sufficient for the demonstration reply, while durable application records can cover a longer retry window.
Move back to webhook delivery
Stop polling, switch to the matching webhook profile with files kept, and confirm the HTTPS address in Settings. Set the full TELEGRAM_WEBHOOK_URL ending in /telegram and a separate TELEGRAM_WEBHOOK_SECRET. Start the process and send a fresh message. The starter registers its own endpoint and validates Telegram’s secret header on every delivery.
For the exact variable formats and starter downloads, see Telegram deployment setup. Telegram documents pending update handling in the deleteWebhook method.