Long polling
Start polling
Section titled “Start polling”Bot::new(token)?.command(start).run_polling().await?;run_polling() listens for Ctrl-C. For a custom shutdown signal:
bot.run_polling_until(shutdown_future).await?;Repository example:
cargo run -p jingzhe --example pollingConfiguration
Section titled “Configuration”PollingConfig supports:
- Wait time
- Batch size
- Non-negative recovery offset
allowed_updates
The library limits wait time to 0–50 seconds and batch size to 1–100. The HTTP timeout for long polling is at least the wait time plus 10 seconds so a normal wait is not cut off by the default request timeout.
Processing order
Section titled “Processing order”Updates are processed in response order with a concurrency of 1; the runtime does not create an unbounded task set.
The runner stops when a handler fails, and the failed event’s offset does not advance. Successful events advance the in-memory offset first and are confirmed to Telegram on the next getUpdates request. A shutdown signal stops fetching and finishes the current batch. Updates that were not yet confirmed may be delivered again after restart.
Errors and retries
Section titled “Errors and retries”- Only idempotent long-polling rate-limit errors wait according to
retry_after, and that wait can be cancelled by shutdown. - Other failures propagate to the caller; they are not retried automatically.
- Send and edit requests are never retried implicitly.
Switching from webhooks
Section titled “Switching from webhooks”The library checks webhook state before polling. If a webhook is configured, polling refuses to start and does not delete the webhook automatically.
Call DeleteWebhook::new() explicitly before switching. Pending updates are preserved by default; only drop_pending_updates(true) discards them.