[−][src]Module teloxide::dispatching
Updates dispatching.
The key type here is Dispatcher
. It encapsulates Bot
and handlers
for all the update kinds.
Every handler accept tokio::sync::mpsc::UnboundedReceiver
(the RX halve
of an asynchronous channel). Inside a body of your handler, you typically
asynchronously concurrently iterate through updates like this:
use teloxide::prelude::*; async fn handle_messages(rx: DispatcherHandlerRx<Message>) { rx.for_each_concurrent(None, |message| async move { dbg!(message); }) .await; }
When Update
is received from Telegram, Dispatcher
pushes it into an
appropriate handler, depending on its kind. That's simple!
Note that handlers must implement DispatcherHandler
, which means
that:
- You are able to supply
DialogueDispatcher
as a handler. - You are able to supply functions that accept
tokio::sync::mpsc::UnboundedReceiver
and returnFuture<Output = ()
as a handler.
Since they implement DispatcherHandler
too.
Modules
dialogue | Dealing with dialogues. |
update_listeners | Receiving updates from Telegram. |
Structs
Dispatcher | One dispatcher to rule them all. |
UpdateWithCx | A |
Traits
DispatcherHandler | An asynchronous handler of a stream of updates used in |
DispatcherHandlerRxExt | An extension trait to be used with |
Type Definitions
DispatcherHandlerRx | A type of a stream, consumed by |