25 releases

Uses new Rust 2021

0.7.5 Dec 2, 2021
0.7.4 Oct 7, 2021
0.7.1 Sep 11, 2021
0.7.0 Jul 15, 2021
0.5.3 Jun 9, 2019

#185 in Web programming

Download history 6/week @ 2022-03-09 56/week @ 2022-03-16 81/week @ 2022-03-23 5/week @ 2022-03-30 12/week @ 2022-04-06 4/week @ 2022-04-13 7/week @ 2022-04-20 190/week @ 2022-04-27 163/week @ 2022-05-04 380/week @ 2022-05-11 105/week @ 2022-05-18 130/week @ 2022-05-25 206/week @ 2022-06-01 57/week @ 2022-06-08 7/week @ 2022-06-15 7/week @ 2022-06-22

303 downloads per month

MIT license

10MB
3K SLoC

rutebot

Crates.io doc.rs License MIT

Rust Telegram Bot. A framework offering Telegram Bot API bindings for the Rust programming language.

For details see the docs.

Example

A simple greetings bot. Replies to all messages with text "Hello %USERNAME%"

You can run the following example with cargo run --example simplebot.

use std::env;

use futures_util::StreamExt;
use rutebot::client::Rutebot;
use rutebot::requests::{SendMessage};
use rutebot::responses::Update;
use std::error::Error;


#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let token_env = env::var_os("TELEGRAM_TOKEN")
        .expect("Please specify your bot's token in the TELEGRAM_TOKEN environment variable.");
    let token = token_env.to_string_lossy();

    let rutebot = Rutebot::new(token);
    let mut updates_stream = Box::pin(rutebot.incoming_updates(None, None));
    while let Some(update) = updates_stream.next().await.transpose()? {
        let create_reply_request = |update: Update| {
            let message = update.message?;
            let response_message = format!("Hello {}", message.from?.first_name);
            let reply =
                SendMessage::new_reply(message.chat.id, &response_message, message.message_id);
            Some(rutebot.prepare_api_request(reply))
        };

        if let Some(reply) = create_reply_request(update) {
            tokio::spawn(reply.send());
        }
    }
    Ok(())
}

Dependencies

~6–15MB
~267K SLoC