telegram-rs/telegram-bot
Fork: 157 Star: 942 (更新于 2024-11-19 08:01:04)
license: MIT
Language: Rust .
Rust Library for creating a Telegram Bot
最后发布版本: v0.8.0 ( 2020-11-15 07:17:11)
Rust Telegram Bot Library
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-11-20 07:29:29 lanyeeee/jmcomic-downloader
2024-11-19 23:39:15 gleam-lang/gleam
2024-11-19 08:50:55 lapce/lapce
2024-11-11 22:51:00 tauri-apps/tauri
2024-11-11 07:55:30 dani-garcia/vaultwarden
2024-11-09 16:42:37 rustdesk/rustdesk