Skip to main content

HandlerExt

Trait HandlerExt 

Source
pub trait HandlerExt<Output> {
    // Required methods
    fn filter_command<C>(self) -> Self
       where C: BotCommands + Send + Sync + 'static;
    fn filter_mention_command<C>(self) -> Self
       where C: BotCommands + Send + Sync + 'static;
    fn enter_dialogue<Upd, S, D>(self) -> Self
       where S: Storage<D> + ?Sized + Send + Sync + 'static,
             <S as Storage<D>>::Error: Debug + Send,
             D: Default + Clone + Send + Sync + 'static,
             Upd: GetChatId + Clone + Send + Sync + 'static;
}
Expand description

Extension methods for working with dptree handlers.

Required Methods§

Source

fn filter_command<C>(self) -> Self
where C: BotCommands + Send + Sync + 'static,

Returns a handler that accepts a parsed command C.

§Dependency requirements
Source

fn filter_mention_command<C>(self) -> Self
where C: BotCommands + Send + Sync + 'static,

Returns a handler that accepts a parsed command C if the command contains a bot mention, for example /start@my_bot.

§Dependency requirements
Source

fn enter_dialogue<Upd, S, D>(self) -> Self
where S: Storage<D> + ?Sized + Send + Sync + 'static, <S as Storage<D>>::Error: Debug + Send, D: Default + Clone + Send + Sync + 'static, Upd: GetChatId + Clone + Send + Sync + 'static,

Passes Dialogue<D, S> and D as handler dependencies.

It does so by the following steps:

  1. If an incoming update has no chat ID (GetChatId::chat_id returns None), the rest of the chain will not be executed. Otherwise, passes Dialogue::new(storage, chat_id) forwards.
  2. If Dialogue::get_or_default on the passed dialogue returns Ok, passes the dialogue state forwards. Otherwise, logs an error and the rest of the chain is not executed.

If TELOXIDE_DIALOGUE_BEHAVIOUR environmental variable exists and is equal to “default”, this function will not panic if it can’t get the dialogue (if, for example, the state enum was updated). Setting the value to “panic” will return the initial behaviour.

§Dependency requirements
  • Arc<S>
  • Upd

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Output> HandlerExt<Output> for Handler<'static, Output, DpHandlerDescription>
where Output: Send + Sync + 'static,