diff --git a/README.md b/README.md index 124c80e2..c6bf09b7 100644 --- a/README.md +++ b/README.md @@ -309,8 +309,6 @@ Finally, the `main` function looks like this: ```rust // Imports are omitted... -type In = DialogueWithCx; - #[tokio::main] async fn main() { teloxide::enable_logging!(); @@ -318,15 +316,10 @@ async fn main() { let bot = Bot::from_env(); - Dispatcher::new(bot) - .messages_handler(DialogueDispatcher::new( - |DialogueWithCx { cx, dialogue }: In| async move { - let dialogue = dialogue.expect("std::convert::Infallible"); - handle_message(cx, dialogue).await.expect("Something wrong with the bot!") - }, - )) - .dispatch() - .await; + teloxide::dialogues_repl(bot, |message, dialogue| async move { + handle_message(message, dialogue).await.expect("Something wrong with the bot!") + }) + .await; } async fn handle_message(cx: UpdateWithCx, dialogue: Dialogue) -> TransitionOut { @@ -338,7 +331,6 @@ async fn handle_message(cx: UpdateWithCx, dialogue: Dialogue) -> Transi Some(ans) => dialogue.react(cx, ans).await, } } - ```
diff --git a/examples/dialogue_bot/src/main.rs b/examples/dialogue_bot/src/main.rs index e738eaa1..e2c64b07 100644 --- a/examples/dialogue_bot/src/main.rs +++ b/examples/dialogue_bot/src/main.rs @@ -23,11 +23,8 @@ extern crate frunk; mod dialogue; use crate::dialogue::Dialogue; -use std::convert::Infallible; use teloxide::prelude::*; -type In = DialogueWithCx; - #[tokio::main] async fn main() { run().await; @@ -39,15 +36,10 @@ async fn run() { let bot = Bot::from_env(); - Dispatcher::new(bot) - .messages_handler(DialogueDispatcher::new( - |DialogueWithCx { cx, dialogue }: In| async move { - let dialogue = dialogue.expect("std::convert::Infallible"); - handle_message(cx, dialogue).await.expect("Something wrong with the bot!") - }, - )) - .dispatch() - .await; + teloxide::dialogues_repl(bot, |message, dialogue| async move { + handle_message(message, dialogue).await.expect("Something wrong with the bot!") + }) + .await; } async fn handle_message(cx: UpdateWithCx, dialogue: Dialogue) -> TransitionOut { diff --git a/src/dispatching/repls/dialogues_repl.rs b/src/dispatching/repls/dialogues_repl.rs index b03d110d..e608c725 100644 --- a/src/dispatching/repls/dialogues_repl.rs +++ b/src/dispatching/repls/dialogues_repl.rs @@ -27,7 +27,7 @@ pub async fn dialogues_repl<'a, H, D, Fut>(bot: Bot, handler: H) where H: Fn(UpdateWithCx, D) -> Fut + Send + Sync + 'static, D: Default + Send + 'static, - Fut: Future> + Send + Sync + 'static, + Fut: Future> + Send + 'static, { let cloned_bot = bot.clone(); @@ -54,7 +54,7 @@ pub async fn dialogues_repl_with_listener<'a, H, D, Fut, L, ListenerE>( ) where H: Fn(UpdateWithCx, D) -> Fut + Send + Sync + 'static, D: Default + Send + 'static, - Fut: Future> + Send + Sync + 'static, + Fut: Future> + Send + 'static, L: UpdateListener + Send + 'a, ListenerE: Debug + Send + 'a, {