Module teloxide::dispatching[][src]

Expand description

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::*;
use tokio_stream::wrappers::UnboundedReceiverStream;

async fn handle_messages(rx: DispatcherHandlerRx<AutoSend<Bot>, Message>) {
    UnboundedReceiverStream::new(rx)
        .for_each_concurrent(None, |message| async move {
            dbg!(message.update);
        })
        .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:

Since they implement DispatcherHandler too.

See the examples.

Modules

Dealing with dialogues.

A stop token used to stop a listener.

Receiving updates from Telegram.

Structs

One dispatcher to rule them all.

This error is returned from ShutdownToken::shutdown when trying to shutdown an idle Dispatcher.

A token which used to shutdown Dispatcher.

A Dispatcher’s handler’s context of a bot and an update.

Traits

An asynchronous handler of a stream of updates used in Dispatcher.

An extension trait to be used with DispatcherHandlerRx.

Type Definitions

A type of a stream, consumed by Dispatcher’s handlers.