2019-09-02 09:28:56 +02:00
< div align = "center" >
2020-01-06 11:25:37 +01:00
< img src = "ICON.png" width = "250" / >
2019-12-07 20:30:15 +01:00
< h1 > teloxide< / h1 >
2019-10-15 07:53:51 +02:00
2019-12-07 20:30:15 +01:00
< a href = "https://docs.rs/teloxide/" >
2020-01-06 09:27:05 +01:00
< img src = "https://img.shields.io/badge/docs.rs-v0.1.0-blue.svg" >
2019-10-14 19:07:58 +02:00
< / a >
2019-12-08 07:57:53 +01:00
< a href = "https://github.com/teloxide/teloxide/actions" >
< img src = "https://github.com/teloxide/teloxide/workflows/Continuous%20integration/badge.svg" >
2019-09-02 09:28:56 +02:00
< / a >
2019-12-07 20:30:15 +01:00
< a href = "https://crates.io/crates/teloxide" >
2019-10-14 19:04:55 +02:00
< img src = "https://img.shields.io/badge/crates.io-v0.1.0-orange.svg" >
< / a >
2019-10-14 19:10:41 +02:00
2019-10-15 08:03:40 +02:00
A full-featured framework that empowers you to easily build [Telegram bots ](https://telegram.org/blog/bot-revolution ) using the [`async`/`.await` ](https://rust-lang.github.io/async-book/01_getting_started/01_chapter.html ) syntax in [Rust ](https://www.rust-lang.org/ ). It handles all the difficult stuff so you can focus only on your business logic.
2019-09-02 09:28:56 +02:00
< / div >
2020-01-26 22:36:36 +01:00
2020-02-12 11:17:20 +01:00
## Getting started
2020-02-12 11:20:15 +01:00
1. Create a new bot using [@Botfather ](https://t.me/botfather ) to get a token in the format `123456789:blablabla` .
2020-02-12 11:19:38 +01:00
2. Be sure that you are up to date:
2020-02-12 11:09:53 +01:00
```bash
$ rustup update stable
2020-01-26 22:36:36 +01:00
```
2020-02-12 11:09:53 +01:00
2020-02-12 11:23:46 +01:00
3. Execute `cargo new my_bot` , enter the directory and put these lines into your `Cargo.toml` :
2020-01-26 22:36:36 +01:00
```toml
2020-02-12 11:09:53 +01:00
[dependencies]
2020-01-26 22:36:36 +01:00
teloxide = "0.1.0"
```
2020-02-12 11:17:20 +01:00
## Writing your first bot
2020-02-12 11:18:41 +01:00
Open `main.rs` file, because we're gonna write a ping-pong-bot!
2020-01-26 22:36:36 +01:00
```rust
2020-02-12 11:17:20 +01:00
use teloxide::prelude::*;
2020-01-26 22:36:36 +01:00
#[tokio::main]
async fn main() {
2020-02-12 11:17:20 +01:00
std::env::set_var("RUST_LOG", "ping_pong_bot=trace");
std::env::set_var("RUST_LOG", "teloxide=error");
pretty_env_logger::init();
log::info!("Starting the ping-pong bot!");
Dispatcher::< RequestError > ::new(Bot::new("MyAwesomeToken"))
.message_handler(& |ctx: DispatcherHandlerCtx< Message > | async move {
ctx.answer("pong").send().await?;
Ok(())
})
.dispatch()
.await;
2020-01-26 22:36:36 +01:00
}
```