pub struct BotBuilder { /* private fields */ }Expand description
Builder for constructing bots with handlers
Implementations§
Source§impl BotBuilder
impl BotBuilder
Sourcepub fn command<H, Args>(self, name: impl Into<String>, handler: H) -> Selfwhere
H: IntoHandler<Args>,
pub fn command<H, Args>(self, name: impl Into<String>, handler: H) -> Selfwhere
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)Sourcepub fn command_with_description<H, Args>(
self,
name: impl Into<String>,
description: impl Into<String>,
handler: H,
) -> Selfwhere
H: IntoHandler<Args>,
pub fn command_with_description<H, Args>(
self,
name: impl Into<String>,
description: impl Into<String>,
handler: H,
) -> Selfwhere
H: IntoHandler<Args>,
Register a command handler with a description
The description is used for slash command menus (e.g., Telegram’s /command list).
Register a button handler with pattern matching
Pattern can end with * for prefix matching (e.g., “confirm_*”)
Sourcepub fn message<H, Args>(self, handler: H) -> Selfwhere
H: IntoHandler<Args>,
pub fn message<H, Args>(self, handler: H) -> Selfwhere
H: IntoHandler<Args>,
Register a catch-all message handler
Sourcepub fn commands(&self) -> impl Iterator<Item = (&str, &str)>
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.
Sourcepub fn find_handler(
&self,
event_type: &str,
value: &str,
) -> Option<BoxedHandler>
pub fn find_handler( &self, event_type: &str, value: &str, ) -> Option<BoxedHandler>
Find a handler matching the event type and value
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BotBuilder
impl !RefUnwindSafe for BotBuilder
impl Send for BotBuilder
impl Sync for BotBuilder
impl Unpin for BotBuilder
impl UnsafeUnpin for BotBuilder
impl !UnwindSafe for BotBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more