From a1534b3a14f5c59b8ee5a9f652fa5213e501ae3a Mon Sep 17 00:00:00 2001 From: p0lunin Date: Sun, 26 Jan 2020 23:36:36 +0200 Subject: [PATCH 01/58] added part of `getting started` --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/README.md b/README.md index 218ec6aa..39a7ab9f 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,61 @@ 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. + +# Getting started + +Library requires rustc version more than 1.40.0. You can check your rustc version with command: +```shell script +rustup -V +``` +If your rustc version lower than 1.40.0, update it with: +```shell script +rustup update stable +``` +Than create Cargo project and write +```toml +teloxide = "0.1.0" +``` +in your Cargo.toml file. + +### Writing first bot +First, create bot with [@botfather](https://t.me/botfather). After creating, botfather give you +token in format `123456789:somemanyletters`. + +Next, open yout `main.rs` file. Let's create a simple echo bot: +```rust +use futures::stream::StreamExt; +use teloxide::{ + dispatching::{ + chat::{ChatUpdate, ChatUpdateKind, Dispatcher}, + update_listeners::polling_default, + SessionState, + }, + requests::Request, + Bot, +}; + +#[tokio::main] +async fn main() { + let bot = &Bot::new("1061598315:AAErEDodTsrqD3UxA_EvFyEfXbKA6DT25G0"); + let mut updater = Box::pin(polling_default(bot)); + let handler = |_, upd: ChatUpdate| async move { + if let ChatUpdateKind::Message(m) = upd.kind { + let msg = bot.send_message(m.chat.id, m.text); + msg.send().await.unwrap(); + } + SessionState::Continue(()) + }; + let mut dp = Dispatcher::<'_, (), _>::new(handler); + println!("Starting the message handler."); + loop { + let u = updater.next().await.unwrap(); + match u { + Err(e) => eprintln!("Error: {}", e), + Ok(u) => { + let _ = dp.dispatch(u).await; + } + } + } +} +``` From c4ccf76455196223654d3a1920a367ef71238de8 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:09:53 +0600 Subject: [PATCH 02/58] Update README.md --- README.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 39a7ab9f..03106f90 100644 --- a/README.md +++ b/README.md @@ -18,20 +18,16 @@ # Getting started + 1. Be sure that you are up to date: +```bash +$ rustup update stable +``` -Library requires rustc version more than 1.40.0. You can check your rustc version with command: -```shell script -rustup -V -``` -If your rustc version lower than 1.40.0, update it with: -```shell script -rustup update stable -``` -Than create Cargo project and write + 2. To create a new bot, execute `cargo new` and put the following lines into your `Cargo.toml`: ```toml +[dependencies] teloxide = "0.1.0" ``` -in your Cargo.toml file. ### Writing first bot First, create bot with [@botfather](https://t.me/botfather). After creating, botfather give you From 8f1c3d4f4e9a03b38bcb7c800de39222a81270ab Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:17:20 +0600 Subject: [PATCH 03/58] Update README.md --- README.md | 52 +++++++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 03106f90..50f2d55b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ 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. -# Getting started +## Getting started 1. Be sure that you are up to date: ```bash $ rustup update stable @@ -29,44 +29,26 @@ $ rustup update stable teloxide = "0.1.0" ``` -### Writing first bot -First, create bot with [@botfather](https://t.me/botfather). After creating, botfather give you -token in format `123456789:somemanyletters`. +## Writing your first bot +First, create a new bot using [@botfather](https://t.me/botfather), and after that you'll get a token in format `123456789:somemanyletters`. -Next, open yout `main.rs` file. Let's create a simple echo bot: +Next, open `main.rs` file, because we're gonna write a ping-pong-bot! ```rust -use futures::stream::StreamExt; -use teloxide::{ - dispatching::{ - chat::{ChatUpdate, ChatUpdateKind, Dispatcher}, - update_listeners::polling_default, - SessionState, - }, - requests::Request, - Bot, -}; +use teloxide::prelude::*; #[tokio::main] async fn main() { - let bot = &Bot::new("1061598315:AAErEDodTsrqD3UxA_EvFyEfXbKA6DT25G0"); - let mut updater = Box::pin(polling_default(bot)); - let handler = |_, upd: ChatUpdate| async move { - if let ChatUpdateKind::Message(m) = upd.kind { - let msg = bot.send_message(m.chat.id, m.text); - msg.send().await.unwrap(); - } - SessionState::Continue(()) - }; - let mut dp = Dispatcher::<'_, (), _>::new(handler); - println!("Starting the message handler."); - loop { - let u = updater.next().await.unwrap(); - match u { - Err(e) => eprintln!("Error: {}", e), - Ok(u) => { - let _ = dp.dispatch(u).await; - } - } - } + 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::::new(Bot::new("MyAwesomeToken")) + .message_handler(&|ctx: DispatcherHandlerCtx| async move { + ctx.answer("pong").send().await?; + Ok(()) + }) + .dispatch() + .await; } ``` From ab358601e20964a994ce62987fb7d72a62c97f76 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:17:35 +0600 Subject: [PATCH 04/58] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 50f2d55b..39c3e008 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -> WARNING: this library is still in active development under v0.1.0, use it at your own risk! -

teloxide

From 687c5e4cd10848820164e3532c9483affa647085 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:18:41 +0600 Subject: [PATCH 05/58] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 39c3e008..476bc072 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,11 @@ $ rustup update stable teloxide = "0.1.0" ``` -## Writing your first bot -First, create a new bot using [@botfather](https://t.me/botfather), and after that you'll get a token in format `123456789:somemanyletters`. + 3. Create a new bot using [@botfather](https://t.me/botfather), and after that you'll get a token in format `123456789:somemanyletters`. + +## Writing your first bot +Open `main.rs` file, because we're gonna write a ping-pong-bot! -Next, open `main.rs` file, because we're gonna write a ping-pong-bot! ```rust use teloxide::prelude::*; From 5d331fc705ca1e1ceee7e027340ca94f7c0c9b1f Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:19:38 +0600 Subject: [PATCH 06/58] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 476bc072..d64262c6 100644 --- a/README.md +++ b/README.md @@ -16,19 +16,18 @@
## Getting started - 1. Be sure that you are up to date: + 1. Create a new bot using [@botfather](https://t.me/botfather) to get a token in the format `123456789:somemanyletters`. + 2. Be sure that you are up to date: ```bash $ rustup update stable ``` - 2. To create a new bot, execute `cargo new` and put the following lines into your `Cargo.toml`: + 3. To create a new bot, execute `cargo new` and put the following lines into your `Cargo.toml`: ```toml [dependencies] teloxide = "0.1.0" ``` - 3. Create a new bot using [@botfather](https://t.me/botfather), and after that you'll get a token in format `123456789:somemanyletters`. - ## Writing your first bot Open `main.rs` file, because we're gonna write a ping-pong-bot! From cb175bc34e7e52a10906235ea79b2ad09d22e531 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:19:54 +0600 Subject: [PATCH 07/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d64262c6..976e1874 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Getting started - 1. Create a new bot using [@botfather](https://t.me/botfather) to get a token in the format `123456789:somemanyletters`. + 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:somemanyletters`. 2. Be sure that you are up to date: ```bash $ rustup update stable From 84e277d151a56123e66df9d080bee500969f8dc8 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:20:15 +0600 Subject: [PATCH 08/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 976e1874..26862959 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Getting started - 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:somemanyletters`. + 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. 2. Be sure that you are up to date: ```bash $ rustup update stable From b8210392142218c5f670e67a18744fe96a1c15ed Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:20:37 +0600 Subject: [PATCH 09/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 26862959..5f7eb3a6 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ rustup update stable ``` - 3. To create a new bot, execute `cargo new` and put the following lines into your `Cargo.toml`: + 3. Execute `cargo new` and put the following lines into your `Cargo.toml`: ```toml [dependencies] teloxide = "0.1.0" From e15b7251fe8351a6fa43fe0fc47f769bc299709e Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:21:30 +0600 Subject: [PATCH 10/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f7eb3a6..781d2130 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ rustup update stable ``` - 3. Execute `cargo new` and put the following lines into your `Cargo.toml`: + 3. Execute `cargo new my_bot && cd my_bot` and put the following lines into your `Cargo.toml`: ```toml [dependencies] teloxide = "0.1.0" From 968c8b0d386ec8b89cfbd00c74c0e1dfc866b836 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:21:59 +0600 Subject: [PATCH 11/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 781d2130..5ca8622f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ rustup update stable ``` - 3. Execute `cargo new my_bot && cd my_bot` and put the following lines into your `Cargo.toml`: + 3. Execute `cargo new my_bot` and put the following lines into your `Cargo.toml`: ```toml [dependencies] teloxide = "0.1.0" From be6ca83d6772888c21a50828ab68fd4d2a7102a4 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:22:26 +0600 Subject: [PATCH 12/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ca8622f..4e66498b 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ rustup update stable ``` - 3. Execute `cargo new my_bot` and put the following lines into your `Cargo.toml`: + 3. Execute `cargo new my_bot`, enter the directory and put the following lines into your `Cargo.toml`: ```toml [dependencies] teloxide = "0.1.0" From e2a8592c0d164e1cf2145b2b83f803cabcd51582 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:23:08 +0600 Subject: [PATCH 13/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e66498b..0616c44f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ rustup update stable ``` - 3. Execute `cargo new my_bot`, enter the directory and put the following lines into your `Cargo.toml`: + 3. Execute `cargo new my_bot`, enter the directory and put this into your `Cargo.toml`: ```toml [dependencies] teloxide = "0.1.0" From c8231dc342276ab62e8e4e436aea7f25415a7a48 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:23:46 +0600 Subject: [PATCH 14/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0616c44f..28a44590 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ rustup update stable ``` - 3. Execute `cargo new my_bot`, enter the directory and put this into your `Cargo.toml`: + 3. Execute `cargo new my_bot`, enter the directory and put these lines into your `Cargo.toml`: ```toml [dependencies] teloxide = "0.1.0" From 016904fdb917d527d1f0074e3d38b1275253f47e Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:34:20 +0600 Subject: [PATCH 15/58] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 28a44590..85d6e19f 100644 --- a/README.md +++ b/README.md @@ -36,12 +36,18 @@ use teloxide::prelude::*; #[tokio::main] async fn main() { + // Configure a fancy logger. Let this bot print everything, but restrict + // teloxide to only log errors. 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!"); + // Creates a dispatcher of updates with the specified bot. Don't forget to + // replace `MyAwesomeToken` with yours. Dispatcher::::new(Bot::new("MyAwesomeToken")) + // Registers a message handler. Inside a body of the closure, answer + // `"pong"` to an incoming message. .message_handler(&|ctx: DispatcherHandlerCtx| async move { ctx.answer("pong").send().await?; Ok(()) From da05ec478cc46ff62437a7c65722b514873496a5 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:35:41 +0600 Subject: [PATCH 16/58] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 85d6e19f..d73e5af3 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,7 @@ $ rustup update stable teloxide = "0.1.0" ``` -## Writing your first bot -Open `main.rs` file, because we're gonna write a ping-pong-bot! - +## The ping-pong bott! ```rust use teloxide::prelude::*; From 9d7989468ed491d48a84a172b24ba6b574080947 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:35:51 +0600 Subject: [PATCH 17/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d73e5af3..470c0019 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ $ rustup update stable teloxide = "0.1.0" ``` -## The ping-pong bott! +## The ping-pong bot ```rust use teloxide::prelude::*; From b15c6192ebaa4704d5f3584c3bf2bc45383d43d5 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:47:51 +0600 Subject: [PATCH 18/58] Update README.md --- README.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 470c0019..79b2a6e0 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ ## Getting started 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. + 2. Initialise the `TELOXIDE_TOKEN` environmental variable to your token: +```bash +export TELOXIDE_TOKEN=MyAwesomeToken +``` 2. Be sure that you are up to date: ```bash $ rustup update stable @@ -32,20 +36,22 @@ teloxide = "0.1.0" ```rust use teloxide::prelude::*; +use std::env::{set_var, var}; + #[tokio::main] async fn main() { // Configure a fancy logger. Let this bot print everything, but restrict // teloxide to only log errors. - std::env::set_var("RUST_LOG", "ping_pong_bot=trace"); - std::env::set_var("RUST_LOG", "teloxide=error"); + set_var("RUST_LOG", "ping_pong_bot=trace"); + set_var("RUST_LOG", "teloxide=error"); pretty_env_logger::init(); log::info!("Starting the ping-pong bot!"); - // Creates a dispatcher of updates with the specified bot. Don't forget to - // replace `MyAwesomeToken` with yours. - Dispatcher::::new(Bot::new("MyAwesomeToken")) - // Registers a message handler. Inside a body of the closure, answer - // `"pong"` to an incoming message. + let bot = Bot::new(var("TELOXIDE_TOKEN").unwrap()); + + // Create a dispatcher with a single message handler that answers "pong" to + // each incoming message. + Dispatcher::::new(bot) .message_handler(&|ctx: DispatcherHandlerCtx| async move { ctx.answer("pong").send().await?; Ok(()) From 6cd162df0538326f7b955dfc8f349b77c9ff9a91 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 16:49:59 +0600 Subject: [PATCH 19/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 79b2a6e0..b1237b3d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. 2. Initialise the `TELOXIDE_TOKEN` environmental variable to your token: ```bash -export TELOXIDE_TOKEN=MyAwesomeToken +$ export TELOXIDE_TOKEN=MyAwesomeToken ``` 2. Be sure that you are up to date: ```bash From 81e4ebcfcf11eb4ddb872bf5d0dfff5b9a9c9295 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 21:37:57 +0600 Subject: [PATCH 20/58] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b1237b3d..bc322f46 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,12 @@ ```bash $ export TELOXIDE_TOKEN=MyAwesomeToken ``` - 2. Be sure that you are up to date: + 3. Be sure that you are up to date: ```bash $ rustup update stable ``` - 3. Execute `cargo new my_bot`, enter the directory and put these lines into your `Cargo.toml`: + 4. Execute `cargo new my_bot`, enter the directory and put these lines into your `Cargo.toml`: ```toml [dependencies] teloxide = "0.1.0" From 092edab987305441ca66981a29e3c3f14141bd61 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 21:58:27 +0600 Subject: [PATCH 21/58] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bc322f46..2851f9e4 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ $ rustup update stable ```toml [dependencies] teloxide = "0.1.0" +tokio = { version = "0.2.11", features = ["full"] } ``` ## The ping-pong bot From 4e6a536872570d6cf0d81762b8728679d3253c81 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 22:00:54 +0600 Subject: [PATCH 22/58] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2851f9e4..df835b85 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ $ rustup update stable ```toml [dependencies] teloxide = "0.1.0" +pretty_env_logger = "0.3.1" +log = "0.4.8" tokio = { version = "0.2.11", features = ["full"] } ``` From b3a9a7c6984ed15c2ee68e491132a8532d44b240 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 12 Feb 2020 23:21:29 +0600 Subject: [PATCH 23/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index df835b85..b3eec8c8 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ $ rustup update stable teloxide = "0.1.0" pretty_env_logger = "0.3.1" log = "0.4.8" -tokio = { version = "0.2.11", features = ["full"] } +tokio = "0.2.11" ``` ## The ping-pong bot From ddc0b69481b134afb2fa63c2c977ee4e7c67cf23 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 13 Feb 2020 14:50:01 +0600 Subject: [PATCH 24/58] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b3eec8c8..9d61cffd 100644 --- a/README.md +++ b/README.md @@ -39,18 +39,18 @@ tokio = "0.2.11" ```rust use teloxide::prelude::*; -use std::env::{set_var, var}; - #[tokio::main] async fn main() { - // Configure a fancy logger. Let this bot print everything, but restrict - // teloxide to only log errors. - set_var("RUST_LOG", "ping_pong_bot=trace"); - set_var("RUST_LOG", "teloxide=error"); - pretty_env_logger::init(); - log::info!("Starting the ping-pong bot!"); + run().await; +} - let bot = Bot::new(var("TELOXIDE_TOKEN").unwrap()); +async fn run() { + // Configure the fancy logger. + std::env::set_var("RUST_LOG", "info"); + pretty_env_logger::init(); + log::info!("Starting ping_pong_bot!"); + + let bot = Bot::new(std::env::var("TELOXIDE_TOKEN").unwrap()); // Create a dispatcher with a single message handler that answers "pong" to // each incoming message. From 18588850f8fb92c42714f898ac54606b82cb4818 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 13 Feb 2020 20:03:23 +0600 Subject: [PATCH 25/58] Update README.md --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 9d61cffd..d621c6d0 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,9 @@ async fn main() { } async fn run() { - // Configure the fancy logger. - std::env::set_var("RUST_LOG", "info"); - pretty_env_logger::init(); + let bot = Bot::from_env().enable_logging(crate_name!()).build(); log::info!("Starting ping_pong_bot!"); - let bot = Bot::new(std::env::var("TELOXIDE_TOKEN").unwrap()); - // Create a dispatcher with a single message handler that answers "pong" to // each incoming message. Dispatcher::::new(bot) From a01a7b959acce197d1a37e4bff7606d18a0756e3 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 13 Feb 2020 20:14:17 +0600 Subject: [PATCH 26/58] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index d621c6d0..bf5184d5 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ $ rustup update stable ```toml [dependencies] teloxide = "0.1.0" -pretty_env_logger = "0.3.1" log = "0.4.8" tokio = "0.2.11" ``` From 57e5469a3cf62f1164a636e9451f5df343163fa8 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 13 Feb 2020 23:07:28 +0600 Subject: [PATCH 27/58] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bf5184d5..c0b03358 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ tokio = "0.2.11" ``` ## The ping-pong bot +This bot has a single handler, which answers "pong" on each incoming message: + ```rust use teloxide::prelude::*; @@ -44,11 +46,11 @@ async fn main() { } async fn run() { - let bot = Bot::from_env().enable_logging(crate_name!()).build(); + teloxide::enable_logging!(); log::info!("Starting ping_pong_bot!"); - // Create a dispatcher with a single message handler that answers "pong" to - // each incoming message. + let bot = Bot::from_env(); + Dispatcher::::new(bot) .message_handler(&|ctx: DispatcherHandlerCtx| async move { ctx.answer("pong").send().await?; From 12b6cf5955d9a2262dac1ce37788dc4301d3f2af Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 13 Feb 2020 23:08:50 +0600 Subject: [PATCH 28/58] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c0b03358..b50452aa 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ $ rustup update stable teloxide = "0.1.0" log = "0.4.8" tokio = "0.2.11" +pretty_env_logger = "0.4.0" ``` ## The ping-pong bot From fbacf5a2ed93fabc18b6176f60a1dee1eb4cec9d Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 13 Feb 2020 23:15:40 +0600 Subject: [PATCH 29/58] Update README.md --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index b50452aa..12ed642f 100644 --- a/README.md +++ b/README.md @@ -36,17 +36,13 @@ pretty_env_logger = "0.4.0" ``` ## The ping-pong bot -This bot has a single handler, which answers "pong" on each incoming message: +This bot has a single handler, which answers "pong" to each incoming message: ```rust use teloxide::prelude::*; #[tokio::main] async fn main() { - run().await; -} - -async fn run() { teloxide::enable_logging!(); log::info!("Starting ping_pong_bot!"); From ff53fca49a2b54ccadb01cafb75714e2e6acd60e Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 13 Feb 2020 23:27:07 +0600 Subject: [PATCH 30/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 12ed642f..acad2689 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ use teloxide::prelude::*; #[tokio::main] async fn main() { teloxide::enable_logging!(); - log::info!("Starting ping_pong_bot!"); + log::info!("Starting the ping-pong bot!"); let bot = Bot::from_env(); From b6021d05cacc297f8331cf72d40359fe2beb154a Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 02:19:08 +0600 Subject: [PATCH 31/58] Update README.md --- README.md | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/README.md b/README.md index acad2689..98dc6586 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ 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. +## Features + - **Type-safe.** teloxide leverages the rich Rust's type system with two implications: resistance to human mistakes and very nice integration with IDEs. Write fast, avoid debugging. + ## Getting started 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. 2. Initialise the `TELOXIDE_TOKEN` environmental variable to your token: @@ -38,6 +41,7 @@ pretty_env_logger = "0.4.0" ## The ping-pong bot This bot has a single handler, which answers "pong" to each incoming message: +([Full](https://github.com/teloxide/teloxide/blob/dev/examples/ping_pong_bot/src/main.rs)) ```rust use teloxide::prelude::*; @@ -57,3 +61,85 @@ async fn main() { .await; } ``` + +## Guess a number +Wanna see more? This is a bot, which starts a game on each incoming message. You must guess a number from 1 to 10 (inclusively): + +([Full](https://github.com/teloxide/teloxide/blob/dev/examples/guess_a_number_bot/src/main.rs)) +```rust +// Imports are omitted... + +#[derive(SmartDefault)] +enum Dialogue { + #[default] + Start, + ReceiveAttempt(u8), +} + +async fn handle_message( + ctx: DialogueHandlerCtx, +) -> Result, RequestError> { + match ctx.dialogue { + Dialogue::Start => { + ctx.answer( + "Let's play a game! Guess a number from 1 to 10 (inclusively).", + ) + .send() + .await?; + next(Dialogue::ReceiveAttempt(thread_rng().gen_range(1, 11))) + } + Dialogue::ReceiveAttempt(secret) => match ctx.update.text() { + None => { + ctx.answer("Oh, please, send me a text message!") + .send() + .await?; + next(ctx.dialogue) + } + Some(text) => match text.parse::() { + Ok(attempt) => match attempt { + x if !(1..=10).contains(&x) => { + ctx.answer( + "Oh, please, send me a number in the range [1; \ + 10]!", + ) + .send() + .await?; + next(ctx.dialogue) + } + x if x == secret => { + ctx.answer("Congratulations! You won!").send().await?; + exit() + } + _ => { + ctx.answer("No.").send().await?; + next(ctx.dialogue) + } + }, + Err(_) => { + ctx.answer("Oh, please, send me a number!").send().await?; + next(ctx.dialogue) + } + }, + }, + } +} + +#[tokio::main] +async fn main() { + teloxide::enable_logging!(); + log::info!("Starting guess_a_number_bot!"); + + let bot = Bot::from_env(); + + Dispatcher::new(bot) + .message_handler(&DialogueDispatcher::new(|ctx| async move { + handle_message(ctx) + .await + .expect("Something wrong with the bot!") + })) + .dispatch() + .await; +} +``` + +This is how easy and type-safe to write dialogues using teloxide. Our [finite automaton](https://en.wikipedia.org/wiki/Finite-state_machine), designating a user dialogue, cannot be in an invalid state. See [examples/dialogue_bot](https://github.com/teloxide/teloxide/blob/dev/examples/dialogue_bot/src/main.rs) to see a bit more complicated bot with dialogues. From b083caf0dafe930dd47f2aa8f76a56eb0cf80053 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 02:19:35 +0600 Subject: [PATCH 32/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 98dc6586..c5545d00 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Features - - **Type-safe.** teloxide leverages the rich Rust's type system with two implications: resistance to human mistakes and very nice integration with IDEs. Write fast, avoid debugging. + - **Type-safe.** teloxide leverages the rich Rust's type system with two serious implications: resistance to human mistakes and very nice integration with IDEs. Write fast, avoid debugging. ## Getting started 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. From b305e6485e0838e7a8b4ea6a3ff8bd840e4ccd5f Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 02:19:49 +0600 Subject: [PATCH 33/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c5545d00..5b7ed49d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Features - - **Type-safe.** teloxide leverages the rich Rust's type system with two serious implications: resistance to human mistakes and very nice integration with IDEs. Write fast, avoid debugging. + - **Type-safe.** teloxide leverages the rich Rust's type system with two serious implications: resistance to human mistakes and really nice integration with IDEs. Write fast, avoid debugging. ## Getting started 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. From 59345c80e48efdd42cf4d698f51e1261d89c411a Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 02:22:04 +0600 Subject: [PATCH 34/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b7ed49d..eef7c623 100644 --- a/README.md +++ b/README.md @@ -142,4 +142,4 @@ async fn main() { } ``` -This is how easy and type-safe to write dialogues using teloxide. Our [finite automaton](https://en.wikipedia.org/wiki/Finite-state_machine), designating a user dialogue, cannot be in an invalid state. See [examples/dialogue_bot](https://github.com/teloxide/teloxide/blob/dev/examples/dialogue_bot/src/main.rs) to see a bit more complicated bot with dialogues. +Our [finite automaton](https://en.wikipedia.org/wiki/Finite-state_machine), designating a user dialogue, cannot be in an invalid state. See [examples/dialogue_bot](https://github.com/teloxide/teloxide/blob/dev/examples/dialogue_bot/src/main.rs) to see a bit more complicated bot with dialogues. From 85891b85c4926a548db93bd75c822d3dda022ba4 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 02:24:36 +0600 Subject: [PATCH 35/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eef7c623..6c151f0f 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Features - - **Type-safe.** teloxide leverages the rich Rust's type system with two serious implications: resistance to human mistakes and really nice integration with IDEs. Write fast, avoid debugging. + - **Type-safe.** teloxide leverages the Rust's type system with two serious implications: resistance to human mistakes and really nice integration with IDEs. Write fast, avoid debugging. ## Getting started 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. From 106fb984fde2309ff2b5ceb35b003514cbf89803 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 02:25:05 +0600 Subject: [PATCH 36/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c151f0f..95b64b79 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Features - - **Type-safe.** teloxide leverages the Rust's type system with two serious implications: resistance to human mistakes and really nice integration with IDEs. Write fast, avoid debugging. + - **Type-safe.** teloxide leverages the Rust's type system with two serious implications: resistance to human mistakes and tight integration with IDEs. Write fast, avoid debugging. ## Getting started 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. From 33919ade8966694e7b97eefb0d3b40e9f1708b49 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 02:38:58 +0600 Subject: [PATCH 37/58] Update README.md --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 95b64b79..2b5dec54 100644 --- a/README.md +++ b/README.md @@ -143,3 +143,28 @@ async fn main() { ``` Our [finite automaton](https://en.wikipedia.org/wiki/Finite-state_machine), designating a user dialogue, cannot be in an invalid state. See [examples/dialogue_bot](https://github.com/teloxide/teloxide/blob/dev/examples/dialogue_bot/src/main.rs) to see a bit more complicated bot with dialogues. + +## Recommendations + - Use this pattern: + + ```rust + #[tokio::main] + async fn main() { + run().await; + } + + async fn run() { + // Your logic here... + } + ``` + + Instead of this: + + ```rust +#[tokio::main] + async fn main() { + // Your logic here... + } + ``` + +The second one produces very strange compiler messages because of the `#[tokio::main]` macro. The examples in this README uses the first one for brevity. From 7ab3f70efae67c0f185ad0daed6703de0c5bdb31 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 03:49:49 +0600 Subject: [PATCH 38/58] Update README.md --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/README.md b/README.md index 2b5dec54..1316c8bd 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,62 @@ async fn main() { } ``` +## Commands +teloxide has a few handy macros to define a type of your commands and their descriptions (similar to [serde_json](https://github.com/serde-rs/json)): + +([Full](https://github.com/teloxide/teloxide/blob/dev/examples/simple_commands_bot/src/main.rs)) +```rust +// Imports are omitted... + +#[derive(BotCommand)] +#[command(rename = "lowercase", description = "These commands are supported:")] +enum Command { + #[command(description = "display this text.")] + Help, + #[command(description = "be a cat.")] + Meow, + #[command(description = "be a dog.")] + Woof, + #[command(description = "be a cow.")] + Moo, +} + +async fn handle_command( + ctx: DispatcherHandlerCtx, +) -> Result<(), RequestError> { + let text = match ctx.update.text() { + Some(text) => text, + None => { + log::info!("Received a message, but not text."); + Ok(()) + } + }; + + let command = match Command::parse(text) { + Some((command, _)) => command, + None => { + log::info!("Received a text message, but not a command."); + Ok(()) + } + }; + + match command { + Command::Help => ctx.answer(Command::descriptions()).send().await?, + Command::Meow => ctx.answer("I am a cat! Meow!").send().await?, + Command::Woof => ctx.answer("I am a dog! Woof!").send().await?, + Command::Moo => ctx.answer("I am a cow! Moo!").send().await?, + }; + + Ok(()) +} + +#[tokio::main] +async fn main() { + // Setup is omitted... +} + +``` + ## Guess a number Wanna see more? This is a bot, which starts a game on each incoming message. You must guess a number from 1 to 10 (inclusively): From 5d0177e1a8b00533321205a8558f239aa5822a27 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 03:57:22 +0600 Subject: [PATCH 39/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1316c8bd..a7f0b5ab 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ async fn main() { ``` ## Commands -teloxide has a few handy macros to define a type of your commands and their descriptions (similar to [serde_json](https://github.com/serde-rs/json)): +Commands are defined similar to how we define CLI using [structopt](https://docs.rs/structopt/0.3.9/structopt/): ([Full](https://github.com/teloxide/teloxide/blob/dev/examples/simple_commands_bot/src/main.rs)) ```rust From 2f42bd53e1a0fd670718c3181452b80c080da882 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:00:01 +0600 Subject: [PATCH 40/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a7f0b5ab..23f8d4dc 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ pretty_env_logger = "0.4.0" ``` ## The ping-pong bot -This bot has a single handler, which answers "pong" to each incoming message: +This bot just answers "pong" to each incoming message: ([Full](https://github.com/teloxide/teloxide/blob/dev/examples/ping_pong_bot/src/main.rs)) ```rust From bea4d7c57fb1faf50332fcdc599d7d5c686dc7fc Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:00:37 +0600 Subject: [PATCH 41/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 23f8d4dc..a027bc92 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ pretty_env_logger = "0.4.0" ``` ## The ping-pong bot -This bot just answers "pong" to each incoming message: +This bot has a single message handler, which answers "pong" to each incoming message: ([Full](https://github.com/teloxide/teloxide/blob/dev/examples/ping_pong_bot/src/main.rs)) ```rust From 9c005dc0e23440955eb6505eba1d0c2057b4748c Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:11:29 +0600 Subject: [PATCH 42/58] Update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a027bc92..22962af0 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,6 @@ enum Dialogue { Start, ReceiveAttempt(u8), } - async fn handle_message( ctx: DialogueHandlerCtx, ) -> Result, RequestError> { @@ -172,7 +171,11 @@ async fn handle_message( } }, Err(_) => { - ctx.answer("Oh, please, send me a number!").send().await?; + ctx.answer( + "Oh, please, send me a number in the range [1; 10]!", + ) + .send() + .await?; next(ctx.dialogue) } }, From 222e703cfac510d103008f092e743e8871f71976 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:25:42 +0600 Subject: [PATCH 43/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22962af0..ac6d3845 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Features - - **Type-safe.** teloxide leverages the Rust's type system with two serious implications: resistance to human mistakes and tight integration with IDEs. Write fast, avoid debugging. + - **Type-safe.** teloxide leverages the Rust's type system with two serious implications: resistance to human mistakes and tight integration with IDEs. Write fast, avoid debugging as possible. ## Getting started 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. From 89bf6872b6b0ec221004b9c2a6aa6f22bcc426a0 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:36:57 +0600 Subject: [PATCH 44/58] Update README.md --- README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ac6d3845..9ad98acd 100644 --- a/README.md +++ b/README.md @@ -76,10 +76,8 @@ enum Command { Help, #[command(description = "be a cat.")] Meow, - #[command(description = "be a dog.")] - Woof, - #[command(description = "be a cow.")] - Moo, + #[command(description = "generate a random number within [0; 1).")] + Generate, } async fn handle_command( @@ -89,7 +87,7 @@ async fn handle_command( Some(text) => text, None => { log::info!("Received a message, but not text."); - Ok(()) + return Ok(()); } }; @@ -97,15 +95,18 @@ async fn handle_command( Some((command, _)) => command, None => { log::info!("Received a text message, but not a command."); - Ok(()) + return Ok(()); } }; match command { Command::Help => ctx.answer(Command::descriptions()).send().await?, + Command::Generate => { + ctx.answer(thread_rng().gen_range(0.0, 1.0).to_string()) + .send() + .await? + } Command::Meow => ctx.answer("I am a cat! Meow!").send().await?, - Command::Woof => ctx.answer("I am a dog! Woof!").send().await?, - Command::Moo => ctx.answer("I am a cow! Moo!").send().await?, }; Ok(()) From 61d3243109da0dd6c19f6e3a03aa3f7e2b38ebe2 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:39:08 +0600 Subject: [PATCH 45/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ad98acd..307b66e4 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ async fn main() { ``` ## Commands -Commands are defined similar to how we define CLI using [structopt](https://docs.rs/structopt/0.3.9/structopt/): +Commands are defined similar to how we define CLI using [structopt](https://docs.rs/structopt/0.3.9/structopt/). This bot says "I am a cat! Meow!" on `/meow` and generates a random number within [0; 1) on `/generate`: ([Full](https://github.com/teloxide/teloxide/blob/dev/examples/simple_commands_bot/src/main.rs)) ```rust From 07bab1977064fa028585b4c199ed8ef5cf7d3b3d Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:40:17 +0600 Subject: [PATCH 46/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 307b66e4..1cea9221 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ async fn main() { ``` ## Commands -Commands are defined similar to how we define CLI using [structopt](https://docs.rs/structopt/0.3.9/structopt/). This bot says "I am a cat! Meow!" on `/meow` and generates a random number within [0; 1) on `/generate`: +Commands are defined similar to how we define CLI using [structopt](https://docs.rs/structopt/0.3.9/structopt/). This bot says "I am a cat! Meow!" on `/meow`, generates a random number within [0; 1) on `/generate`, and shows the usage guide on `/help`: ([Full](https://github.com/teloxide/teloxide/blob/dev/examples/simple_commands_bot/src/main.rs)) ```rust From ab7d130cf292e91360d98b2054b8facf2e49efc9 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:47:38 +0600 Subject: [PATCH 47/58] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1cea9221..aeddbdbb 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ ## Features - **Type-safe.** teloxide leverages the Rust's type system with two serious implications: resistance to human mistakes and tight integration with IDEs. Write fast, avoid debugging as possible. + - **Persistency.** By default, teloxide stores all user dialogues in RAM, but you can store them somewhere else (for example, in DB) just by implementing 2 functions. ## Getting started 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. From 017138fd1873c70d2073087ede595ee456581e85 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:47:53 +0600 Subject: [PATCH 48/58] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index aeddbdbb..b103987b 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ ## Features - **Type-safe.** teloxide leverages the Rust's type system with two serious implications: resistance to human mistakes and tight integration with IDEs. Write fast, avoid debugging as possible. + - **Persistency.** By default, teloxide stores all user dialogues in RAM, but you can store them somewhere else (for example, in DB) just by implementing 2 functions. ## Getting started From 0d39fe4d401747104b6b48786bccd36ebe182e90 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:52:44 +0600 Subject: [PATCH 49/58] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b103987b..670d0e5d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ - **Type-safe.** teloxide leverages the Rust's type system with two serious implications: resistance to human mistakes and tight integration with IDEs. Write fast, avoid debugging as possible. - **Persistency.** By default, teloxide stores all user dialogues in RAM, but you can store them somewhere else (for example, in DB) just by implementing 2 functions. + + - **Convenient API.** Automatic conversions are used to avoid boilerplate. For example, often functions accept `Into`, rather than `&str` or `String`, so you can call them without `.to_string()`/`.as_str()`/etc. ## Getting started 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. From 30b5c9e7f97bcc8e6bb4f44aab7f643fff4696c6 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:53:22 +0600 Subject: [PATCH 50/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 670d0e5d..36f470a4 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ - **Persistency.** By default, teloxide stores all user dialogues in RAM, but you can store them somewhere else (for example, in DB) just by implementing 2 functions. - - **Convenient API.** Automatic conversions are used to avoid boilerplate. For example, often functions accept `Into`, rather than `&str` or `String`, so you can call them without `.to_string()`/`.as_str()`/etc. + - **Convenient API.** Automatic conversions are used to avoid boilerplate. For example, functions accept `Into`, rather than `&str` or `String`, so you can call them without `.to_string()`/`.as_str()`/etc. ## Getting started 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. From 4a64bf513a6db4a408544790fb1e4fed0198e754 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 04:58:36 +0600 Subject: [PATCH 51/58] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 36f470a4..f6c753d0 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ - **Type-safe.** teloxide leverages the Rust's type system with two serious implications: resistance to human mistakes and tight integration with IDEs. Write fast, avoid debugging as possible. - **Persistency.** By default, teloxide stores all user dialogues in RAM, but you can store them somewhere else (for example, in DB) just by implementing 2 functions. + + - **Convenient dialogues system.** Define a type-safe [finite automaton](https://en.wikipedia.org/wiki/Finite-state_machine) + and transition functions to drive a user dialogue with ease (see the examples below). - **Convenient API.** Automatic conversions are used to avoid boilerplate. For example, functions accept `Into`, rather than `&str` or `String`, so you can call them without `.to_string()`/`.as_str()`/etc. From 54a8e5741d80ab7f7ac8ceb30b2a53d8571c2861 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 05:01:40 +0600 Subject: [PATCH 52/58] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f6c753d0..95b26e07 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,8 @@ async fn main() { Our [finite automaton](https://en.wikipedia.org/wiki/Finite-state_machine), designating a user dialogue, cannot be in an invalid state. See [examples/dialogue_bot](https://github.com/teloxide/teloxide/blob/dev/examples/dialogue_bot/src/main.rs) to see a bit more complicated bot with dialogues. +[See more examples](https://github.com/teloxide/teloxide/tree/dev/examples). + ## Recommendations - Use this pattern: From 0358001b844625efd3abc9dc3c1c531b18463e5b Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 13:31:42 +0600 Subject: [PATCH 53/58] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 95b26e07..815ae536 100644 --- a/README.md +++ b/README.md @@ -193,10 +193,7 @@ async fn handle_message( #[tokio::main] async fn main() { - teloxide::enable_logging!(); - log::info!("Starting guess_a_number_bot!"); - - let bot = Bot::from_env(); + // Setup is omitted... Dispatcher::new(bot) .message_handler(&DialogueDispatcher::new(|ctx| async move { From 6dba649988703eb104111c953d66b11d7d56dbfa Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 13:55:51 +0600 Subject: [PATCH 54/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 815ae536..ce3c8060 100644 --- a/README.md +++ b/README.md @@ -233,4 +233,4 @@ Our [finite automaton](https://en.wikipedia.org/wiki/Finite-state_machine), desi } ``` -The second one produces very strange compiler messages because of the `#[tokio::main]` macro. The examples in this README uses the first one for brevity. +The second one produces very strange compiler messages because of the `#[tokio::main]` macro. The examples in this README use the first one for brevity. From ca66fd161f26728bde0a3b8da8cbf5c823369fa8 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 14:45:12 +0600 Subject: [PATCH 55/58] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ce3c8060..eb77e0f0 100644 --- a/README.md +++ b/README.md @@ -234,3 +234,6 @@ Our [finite automaton](https://en.wikipedia.org/wiki/Finite-state_machine), desi ``` The second one produces very strange compiler messages because of the `#[tokio::main]` macro. The examples in this README use the first one for brevity. + +## Contributing +See [CONRIBUTING.md](https://github.com/teloxide/teloxide/blob/dev/CONTRIBUTING.md). From cfd1170c372a2f277bd161260654087520c6ab06 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 15:53:14 +0600 Subject: [PATCH 56/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb77e0f0..bb8ed51f 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ Our [finite automaton](https://en.wikipedia.org/wiki/Finite-state_machine), desi } ``` -The second one produces very strange compiler messages because of the `#[tokio::main]` macro. The examples in this README use the first one for brevity. +The second one produces very strange compiler messages because of the `#[tokio::main]` macro. However, the examples in this README use the second variant for brevity. ## Contributing See [CONRIBUTING.md](https://github.com/teloxide/teloxide/blob/dev/CONTRIBUTING.md). From 16b0941f60efbb12a6c07cf39009b74f939d6e65 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 15:57:14 +0600 Subject: [PATCH 57/58] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bb8ed51f..53e659be 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,7 @@ enum Dialogue { Start, ReceiveAttempt(u8), } + async fn handle_message( ctx: DialogueHandlerCtx, ) -> Result, RequestError> { From 5cf565eddf6c451064d7ab9389d3f98721bc94f9 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 16:28:35 +0600 Subject: [PATCH 58/58] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 53e659be..cd2367c7 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,11 @@ 1. Create a new bot using [@Botfather](https://t.me/botfather) to get a token in the format `123456789:blablabla`. 2. Initialise the `TELOXIDE_TOKEN` environmental variable to your token: ```bash +# Unix $ export TELOXIDE_TOKEN=MyAwesomeToken + +# Windows +$ set TELOXITE_TOKEN=MyAwesomeToken ``` 3. Be sure that you are up to date: ```bash