Telegram bots2 minutes to read

Should my Telegram bot use polling or a webhook?

Long polling needs no domain and suits most bots. Webhooks need HTTPS and suit high traffic or serverless setups. How to choose and switch safely.

Use polling unless you have a reason not to

Use long polling for most Telegram bots. It needs no domain, no open port and no TLS certificate, and it works on a free always-on worker. Use a webhook when the bot already lives inside a web app, when you expect heavy traffic, or when your platform only wakes up for HTTP requests. Telegram delivers to one mode per token. While a webhook is set, getUpdates returns an error.

Polling and webhooks side by side

Delivery modes for one bot token
Long pollingWebhook
How updates arriveYour bot calls getUpdates and waitsTelegram sends an HTTPS POST to your URL
Needs a public URLNoYes, HTTPS on port 443, 80, 88 or 8443
ProcessAlways-on workerWeb server; can sleep between requests
Typical librariesaiogram, python-telegram-bot, grammY, TelegrafSame libraries in webhook mode, or FastAPI and Express
Bothosting profileNode.js or Python polling botNode.js or Python webhook bot

Telegram documents both methods in the Bot API.

Running each mode on Bothosting

For polling, pick a polling profile, save TELEGRAM_BOT_TOKEN and start. Nothing else is needed. For a webhook, pick a webhook profile. Set TELEGRAM_WEBHOOK_URL to the deployment’s HTTPS address ending in /telegram, and set TELEGRAM_WEBHOOK_SECRET so the bot can reject requests that do not come from Telegram. A free Spark site can use your own domain for the webhook too. See custom webhook domains.

Switching without losing messages

Stop the old deployment first. When moving to polling, call deleteWebhook with drop_pending_updates left false so queued messages still arrive. Then start the poller. The step-by-step version is in switching from webhook to polling. For hosting options, see free Telegram bot hosting compared.