pub struct Dispatcher { /* private fields */ }Expand description
Routes incoming updates to the first matching handler.
§Concurrency
Each update is dispatched in its own tokio::spawn task so handlers run
concurrently. The dispatcher itself is cheaply cloneable (all state is
Arc-backed).
Routes incoming updates to the first matching handler.
Build a dispatcher with Dispatcher::builder or the convenience
method crate::bot::Bot::dispatcher. Once built, start receiving updates with
polling or webhook.
§Concurrency
Dispatcher is cheaply cloneable — all state is Arc-backed.
Each update is dispatched in its own tokio::spawn task so handlers
run concurrently.
Implementations§
Source§impl Dispatcher
impl Dispatcher
Sourcepub fn builder(client: BotClient) -> DispatcherBuilder
pub fn builder(client: BotClient) -> DispatcherBuilder
Creates a new DispatcherBuilder for the given client.
Sourcepub async fn dispatch(&self, update: Update)
pub async fn dispatch(&self, update: Update)
Dispatches a single update.
Finds the first matching route and spawns its handler. If no route matches and a fallback is registered, the fallback is called.
Sourcepub async fn polling(self) -> BotResult<()>
pub async fn polling(self) -> BotResult<()>
Starts a long-polling loop, blocking until a fatal error occurs.
Transient network errors (timeouts, connection resets) are retried
automatically after a short delay. Rate-limit responses (HTTP 429)
honour the retry_after value from Telegram. Only non-recoverable
errors (invalid token, unexpected API error) propagate to the caller.
§Errors
Returns a BotError on unrecoverable failure.
Sourcepub async fn webhook(self, addr: SocketAddr) -> BotResult<()>
pub async fn webhook(self, addr: SocketAddr) -> BotResult<()>
Starts an axum-based webhook server on addr, blocking until shutdown.
Telegram must already be configured to deliver updates to your server.
Call rustigram_api::BotClient::set_webhook once before starting this server, or
use update_listener::webhook::WebhookServer directly for more control.
§Errors
Returns a BotError if the TCP listener cannot be bound.
Trait Implementations§
Source§impl Clone for Dispatcher
impl Clone for Dispatcher
Source§fn clone(&self) -> Dispatcher
fn clone(&self) -> Dispatcher
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more