Skip to main content

BotBuilder

Struct BotBuilder 

Source
pub struct BotBuilder { /* private fields */ }
Expand description

Builder for constructing bots with handlers

Implementations§

Source§

impl BotBuilder

Source

pub fn new() -> Self

Create a new bot builder

Source

pub fn command<H, Args>(self, name: impl Into<String>, handler: H) -> Self
where H: IntoHandler<Args>,

Register a command handler

Handlers use the extractor/responder pattern:

// Simple handler
async fn ping() -> &'static str {
    "Pong!"
}

// With extractors
async fn greet(user: User) -> String {
    format!("Hello, {}!", user.name)
}

bot.command("ping", ping)
   .command("greet", greet)
Source

pub fn command_with_description<H, Args>( self, name: impl Into<String>, description: impl Into<String>, handler: H, ) -> Self
where H: IntoHandler<Args>,

Register a command handler with a description

The description is used for slash command menus (e.g., Telegram’s /command list).

Source

pub fn button<H, Args>(self, pattern: impl Into<String>, handler: H) -> Self
where H: IntoHandler<Args>,

Register a button handler with pattern matching

Pattern can end with * for prefix matching (e.g., “confirm_*”)

Source

pub fn message<H, Args>(self, handler: H) -> Self
where H: IntoHandler<Args>,

Register a catch-all message handler

Source

pub fn commands(&self) -> impl Iterator<Item = (&str, &str)>

Get all registered commands with their descriptions

Returns an iterator of (name, description) pairs. Commands without descriptions are included with an empty string.

Source

pub fn find_handler( &self, event_type: &str, value: &str, ) -> Option<BoxedHandler>

Find a handler matching the event type and value

Trait Implementations§

Source§

impl Default for BotBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ChatActionSenderBounds for T
where T: Send + Sync + ?Sized,