telegram-rs/telegram-bot

Rust Library for creating a Telegram Bot

Rust

942

602 commits

updated Mar 2, 2023

See the code

README

Rust Telegram Bot Library

Build Status Tests Tests License Crates.io

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

Example

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

use std::env;

use futures::StreamExt;
use telegram_bot::*;

#[tokio::main]
async fn main() -> Result<(), Error> {
    let token = env::var("TELEGRAM_BOT_TOKEN").expect("TELEGRAM_BOT_TOKEN not set");
    let api = Api::new(token);

    // Fetch new updates via long poll method
    let mut stream = api.stream();
    while let Some(update) = stream.next().await {
        // If the received update contains a new message...
        let update = update?;
        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.send(message.text_reply(format!(
                    "Hi, {}! You just wrote '{}'",
                    &message.from.first_name, data
                )))
                .await?;
            }
        }
    }
    Ok(())
}

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 = "0.7"

The library allows you to do E2E-testing of your bot easily: just specify TELEGRAM_API_URL environment variable to point to your fake Telegram test server. A lot of diagnostic information can be collected with tracing framework, see example/tracing.rs).

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.

telegram
telegram-bot
tokio

Project health

Overall

3.4/10

Maintained

0/10

Code review

3/10
OpenSSF Scorecard

crates.io

Latest release

0.8.0 · Nov 14, 2020

Releases this year

0

Significant stargazers

Tyler Neely

2,540 followers · starred Mar 2022

Zeyi (Rice) Fan

688 followers · starred Aug 2018

Igor Aleksanov

260 followers · starred Jun 2018

Paul Colomiets

521 followers · starred Mar 2021

telegram-rs/telegram-bot

Rust Library for creating a Telegram Bot

Rust

942

602 commits

updated Mar 2, 2023

See the code

README

Rust Telegram Bot Library

Build Status Tests Tests License Crates.io

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

Example

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

use std::env;

use futures::StreamExt;
use telegram_bot::*;

#[tokio::main]
async fn main() -> Result<(), Error> {
    let token = env::var("TELEGRAM_BOT_TOKEN").expect("TELEGRAM_BOT_TOKEN not set");
    let api = Api::new(token);

    // Fetch new updates via long poll method
    let mut stream = api.stream();
    while let Some(update) = stream.next().await {
        // If the received update contains a new message...
        let update = update?;
        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.send(message.text_reply(format!(
                    "Hi, {}! You just wrote '{}'",
                    &message.from.first_name, data
                )))
                .await?;
            }
        }
    }
    Ok(())
}

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 = "0.7"

The library allows you to do E2E-testing of your bot easily: just specify TELEGRAM_API_URL environment variable to point to your fake Telegram test server. A lot of diagnostic information can be collected with tracing framework, see example/tracing.rs).

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.

telegram
telegram-bot
tokio

Project health

Overall

3.4/10

Maintained

0/10

Code review

3/10
OpenSSF Scorecard

crates.io

Latest release

0.8.0 · Nov 14, 2020

Releases this year

0

Significant stargazers

Tyler Neely

2,540 followers · starred Mar 2022

Zeyi (Rice) Fan

688 followers · starred Aug 2018

Igor Aleksanov

260 followers · starred Jun 2018

Paul Colomiets

521 followers · starred Mar 2021