Expand description
Async Rust framework for the Telegram Bot API.
rustigram re-exports all sub-crates through a single dependency and a
convenient prelude module covering the most common types.
§Getting started
Add to Cargo.toml:
[dependencies]
rustigram = "0.9.5"
tokio = { version = "1", features = ["full"] }ⓘ
use rustigram::prelude::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let bot = Bot::new(std::env::var("BOT_TOKEN")?)?;
bot.dispatcher()
.on(filters::command("start"), handler_fn(start))
.on(filters::message(), handler_fn(echo))
.build()
.polling()
.await?;
Ok(())
}
async fn start(ctx: Context) -> BotResult<()> {
if let Some(r) = ctx.reply("Hello!") { r.await?; }
Ok(())
}
async fn echo(ctx: Context) -> BotResult<()> {
if let (Some(text), Some(chat_id)) = (ctx.text(), ctx.chat_id()) {
ctx.bot.send_message(chat_id, text).await?;
}
Ok(())
}§Crate structure
Re-exports§
pub use rustigram_api as api;pub use rustigram_bot as bot;pub use rustigram_types as types;
Modules§
- prelude
- Commonly used types and traits from all sub-crates.