Expand description
Telegram Bot API REST client — getUpdates long-polling plus
sendMessage/editMessageText for outbound delivery.
Rate limiting: v1 implements only per-chat 1 msg/s spacing (enforced by
the caller in poller.rs) and reactive 429/retry_after backoff. Full
token-bucket accounting for the 20/min-per-group and ~30/s-global tiers is
explicitly out of scope (spec §2.5) — mirrors Discord’s rest.rs, which
logs 429s and returns an error rather than doing header-driven throttling.
Never log the full request URL: the bot token is embedded in the path
(https://api.telegram.org/bot{TOKEN}/...), unlike Discord’s
Authorization header. Log method names only, never the URL.
Structs§
- Telegram
ApiError - Error from a Telegram Bot API call, carrying enough of the
429envelope for the caller to implement per-chat backoff (spec §2.5).
Constants§
- POLL_
CLIENT_ 🔒TIMEOUT_ SECS - HTTP client timeout for
getUpdates— must exceedPOLL_TIMEOUT_SECSwith margin, or the client aborts the request right as data would have arrived (spec §9 — long-poll timeout vs HTTP client timeout mismatch). - POLL_
TIMEOUT_ 🔒SECS - Telegram’s own long-poll wait, in seconds (passed as the
timeoutquery param). - SEND_
TIMEOUT_ 🔒SECS - Per-request timeout for send/edit calls. Inbound polling and outbound sending run as fully independent tasks (poller.rs), so a stuck send can no longer block polling — this timeout instead bounds how long a single outbound send can delay the next queued send on the same task.
- TELEGRAM_
API 🔒
Functions§
- build_
poll_ client - Build a dedicated client for
getUpdateswith a timeout that safely exceeds Telegram’s own 30s long-poll wait. Kept distinct from the client used for sends (spec §9). - edit_
message_ text - POST /bot{token}/editMessageText
- escape_
html - Escapes the three characters HTML
parse_modetreats specially. Per spec §2.2, Telegram’s HTML mode only requires escaping<,>,&— simpler than MarkdownV2. Order matters:&must be escaped first so the escape sequences for</>aren’t themselves re-escaped. - get_
updates - GET /bot{token}/getUpdates
- post_
for_ 🔒message - redact 🔒
- Strips the bot token out of an error message before it’s ever logged or
returned.
reqwest::Error’sDisplayembeds the request URL on send/connection failures, and the URL containsbot{token}— so{e}must never reach a log line or aResult<_, String>unredacted. This is the single choke point every error-construction site routes through, so callers can’t accidentally skip it. - send_
message - POST /bot{token}/sendMessage
- send_
or_ edit - Dispatches to
send_messageoredit_message_textdepending on whetheredit_message_idis set (spec §2.3 — streaming-output simulation).