pub struct TelegramBot { /* private fields */ }Expand description
Telegram bot builder
Create a bot with command and button handlers, then call build() to get
a webhook handler that implements skyzen’s Endpoint trait.
§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 build(self) -> TelegramWebhook
pub fn build(self) -> TelegramWebhook
Build the webhook handler (for use with skyzen’s Endpoint)
Sourcepub async fn run_polling(self) -> Result<(), BotError>
pub async fn run_polling(self) -> Result<(), BotError>
Run the bot using long-polling (no server needed)
This method polls Telegram’s API for updates and processes them using the registered handlers. It runs forever until interrupted.
§Example
ⓘ
use botkit_telegram::TelegramBot;
async fn ping() -> &'static str { "Pong!" }
TelegramBot::new(token)
.command("ping", ping)
.run_polling()
.await;Auto Trait Implementations§
impl !RefUnwindSafe for TelegramBot
impl !UnwindSafe for TelegramBot
impl Freeze for TelegramBot
impl Send for TelegramBot
impl Sync for TelegramBot
impl Unpin for TelegramBot
impl UnsafeUnpin for TelegramBot
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