MyGit

telegram-rs/telegram-bot

Fork: 157 Star: 943 (更新于 2024-12-12 11:59:16)

license: MIT

Language: Rust .

Rust Library for creating a Telegram Bot

最后发布版本: v0.8.0 ( 2020-11-15 07:17:11)

GitHub网址

Rust Telegram Bot Library

Build Status Tests Tests License Crates.io

Documentation: Latest crates.io version master

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.

最近版本更新:(数据更新于 2024-10-02 20:14:09)

2020-11-15 07:17:11 v0.8.0

2018-02-17 16:11:15 0.6.1

2018-01-09 12:14:48 v0.6.0

2016-10-22 00:11:13 v0.5.0

2016-02-26 11:02:59 v0.4.1

2016-02-18 20:04:52 v0.4.0

2016-02-17 20:38:33 v0.3.0

2015-08-13 17:17:06 v0.2.0

2015-07-30 07:58:50 v0.1.2

2015-07-27 01:13:27 v0.1.1

主题(topics):

telegram, telegram-bot, tokio

telegram-rs/telegram-bot同语言 Rust最近更新仓库

2024-12-22 10:23:54 rustdesk/rustdesk

2024-12-22 08:48:41 lapce/lapce

2024-12-21 23:25:36 tw93/Pake

2024-12-19 19:31:32 dashpay/platform

2024-12-18 10:31:25 DioxusLabs/dioxus

2024-12-17 17:18:34 lanyeeee/jmcomic-downloader