8 releases

Uses old Rust 2015

0.7.8 May 17, 2019
0.7.7 Nov 23, 2018

#271 in Web programming

Download history 14/week @ 2020-10-05 6/week @ 2020-10-12 13/week @ 2020-10-19 6/week @ 2020-10-26 9/week @ 2020-11-02 6/week @ 2020-11-09 4/week @ 2020-11-16 15/week @ 2020-11-23 16/week @ 2020-11-30 11/week @ 2020-12-07 2/week @ 2020-12-14 2/week @ 2020-12-21 2/week @ 2020-12-28 4/week @ 2021-01-04 6/week @ 2021-01-11 16/week @ 2021-01-18

63 downloads per month

MIT license

170KB
4.5K SLoC

Rust Telegram Bot Library

Build Status License Crates.io

Documentation: Latest crates.io version

A library for writing your own Telegram bots. More information here. Official API here.

Example

Here is a simple example (see example/simple.rs):

extern crate futures;
extern crate telegram_bot_fork;
extern crate tokio;

use std::env;

use futures::{Stream, future::lazy};

use telegram_bot_fork::*;

fn main() {
    tokio::runtime::current_thread::Runtime::new().unwrap().block_on(lazy(|| {
        let token = env::var("TELEGRAM_BOT_TOKEN").unwrap();
        let api = Api::new(token).unwrap();

        // Convert stream to the stream with errors in result
        let stream = api.stream().then(|mb_update| {
            let res: Result<Result<Update, Error>, ()> = Ok(mb_update);
            res
        });

        // Print update or error for each update.
        stream.for_each(move |update| {
            match update {
                Ok(update) => {
                    // If the received update contains a new message...
                    if let UpdateKind::Message(message) = update.kind {
                        if let MessageKind::Text { ref data, .. } = message.kind {
                            // Print received text message to stdout.
                            println!("<{}>: {}", &message.from.first_name, data);

                            // Answer message with "Hi".
                            api.spawn(message.text_reply(format!(
                                "Hi, {}! You just wrote '{}'",
                                &message.from.first_name, data
                            )));
                        }
                    }
                }
                Err(_) => {}
            }

            Ok(())
        })
    })).unwrap();
}

You can find a bigger examples in the examples.

Usage

This library is available via crates.io. In order to use it, just add this to your Cargo.toml:

telegram-bot-fork = "0.7"

Collaboration

Yes please! Every type of contribution is welcome: Create issues, hack some code or make suggestions. Don't know where to start? Good first issues are tagged with up for grab.

Dependencies

~4–6MB
~109K SLoC