mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Trying to compile examples/dialogue_bot...
This commit is contained in:
parent
324f0afaf4
commit
462b42c526
4 changed files with 14 additions and 16 deletions
|
@ -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
|
|
@ -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!")
|
||||
},
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue