pub struct TelegramBot { /* private fields */ }Expand description
Telegram bot builder
Create a bot with command and button handlers, then either call build()
for a webhook endpoint or run() for long polling.
§Example
use botkit_core::User;
use botkit_telegram::{TelegramBot, TelegramWebhook};
// Simple handler - no Context needed!
async fn ping() -> &'static str {
"Pong!"
}
// With extractors
async fn greet(user: User) -> String {
format!("Hello, {}!", user.name)
}
// Return TelegramWebhook directly - it implements Endpoint
#[skyzen::main]
fn main() -> TelegramWebhook {
TelegramBot::new(token)
.command("ping", ping)
.command("greet", greet)
.build()
}Implementations§
Source§impl TelegramBot
impl TelegramBot
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 (e.g., /start, /help)
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 description
The description appears in Telegram’s command menu (slash command suggestions).
Register a button handler (callback query data pattern)
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 message handler
Sourcepub fn fallback<H, Args>(self, handler: H) -> Selfwhere
H: IntoHandler<Args>,
pub fn fallback<H, Args>(self, handler: H) -> Selfwhere
H: IntoHandler<Args>,
Register a handler for events nothing else claimed
Unregistered commands and unmatched callbacks reach the fallback
rather than being dropped. See BotBuilder::fallback.
Sourcepub fn skip_command_registration(self) -> Self
pub fn skip_command_registration(self) -> Self
Stop publishing the registered commands to Telegram on startup
On by default for TelegramBot::run; webhook mode never registers
commands, since build() does no I/O.
Sourcepub fn build(self) -> TelegramWebhook
pub fn build(self) -> TelegramWebhook
Build the webhook handler (for use with skyzen’s Endpoint)
Registering the command menu is a network call, so webhook deployments
should call TelegramClient::set_my_commands themselves at startup;
TelegramBot::commands renders the list to pass it.
Sourcepub fn commands(&self) -> Vec<BotCommand>
pub fn commands(&self) -> Vec<BotCommand>
The command menu entries implied by the registered handlers