Trying to compile examples/dialogue_bot...

This commit is contained in:
Temirkhan Myrzamadi 2020-07-24 01:04:42 +06:00
parent 324f0afaf4
commit 462b42c526
4 changed files with 14 additions and 16 deletions

View file

@ -13,6 +13,7 @@ pretty_env_logger = "0.4.0"
smart-default = "0.6.0"
derive_more = "0.99.9"
teloxide = { path = "../../" }
teloxide-macros = { git = "http://github.com/teloxide/teloxide-macros", branch = "master" }
[profile.release]
lto = true

View file

@ -21,6 +21,8 @@
extern crate smart_default;
#[macro_use]
extern crate derive_more;
#[macro_use]
extern crate teloxide_macros;
mod states;
mod transitions;
@ -46,7 +48,10 @@ async fn run() {
.messages_handler(DialogueDispatcher::new(
|input: TransitionIn<Dialogue, Infallible>| async move {
// Unwrap without panic because of std::convert::Infallible.
dispatch(input.cx, input.dialogue.unwrap())
input
.dialogue
.unwrap()
.dispatch(input.cx)
.await
.expect("Something wrong with the bot!")
},

View file

@ -1,5 +1,7 @@
use teloxide::prelude::*;
use super::transitions::*;
#[derive(Default)]
pub struct StartState;
@ -29,11 +31,16 @@ up!(
ReceiveGandalfAlternativeNameState + [gandalf_alternative_name: String] -> ExitState,
);
#[bot_dialogue]
#[derive(SmartDefault, From)]
pub enum Dialogue {
#[default]
#[handler(start)]
Start(StartState),
#[handler(receive_days_of_week)]
ReceiveDaysOfWeek(ReceiveDaysOfWeekState),
#[handler(receive_10x5_answer)]
Receive10x5Answer(Receive10x5AnswerState),
#[handler(receive_gandalf_alternative_name)]
ReceiveGandalfAlternativeName(ReceiveGandalfAlternativeNameState),
}

View file

@ -55,18 +55,3 @@ async fn receive_gandalf_alternative_name(
}
}
}
pub async fn dispatch(cx: Cx, dialogue: Dialogue) -> Out {
match dialogue {
Dialogue::Start(state) => start(cx, state).await,
Dialogue::ReceiveDaysOfWeek(state) => {
receive_days_of_week(cx, state).await
}
Dialogue::Receive10x5Answer(state) => {
receive_10x5_answer(cx, state).await
}
Dialogue::ReceiveGandalfAlternativeName(state) => {
receive_gandalf_alternative_name(cx, state).await
}
}
}