rustigram-bot 0.9.1

High-level bot dispatcher, update listener, and handler framework for rustigram
Documentation

High-level bot framework built on top of [rustigram-api].

This crate provides everything needed to receive and route Telegram updates:

  • [Bot] — entry point, owns the [crate::bot::Bot::client] field and creates a dispatcher
  • [Dispatcher] — routes updates to handlers via composable filters
  • [Context] — passed to every handler, provides access to the update and the API client
  • [filter] — built-in and composable filter predicates
  • [handler] — the [handler::Handler] trait and [handler::handler_fn] wrapper
  • [state] — [state::StateStorage] for shared data and [state::DialogueStorage] for FSM
  • [update_listener] — long-polling and axum-based webhook implementations

Quick start

use rustigram_bot::{Bot, Context, BotResult};
use rustigram_bot::filter::filters;
use rustigram_bot::handler::handler_fn;

#[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(())
}

Concurrency model

Each incoming update is dispatched in its own [tokio::spawn] task. Handlers run concurrently — a slow handler never blocks others. The dispatcher evaluates routes in registration order and stops at the first matching filter.