Add dialogue::{TransitionIn, TransitionOut}

This commit is contained in:
Temirkhan Myrzamadi 2020-05-26 15:35:28 +06:00
parent bf01d2bf8f
commit 7fc58421b0
3 changed files with 13 additions and 8 deletions

View file

@ -2,17 +2,17 @@ use teloxide::prelude::*;
use super::{favourite_music::FavouriteMusic, states::*};
pub type Cx<State> = DialogueWithCx<Message, State, std::convert::Infallible>;
pub type Res = ResponseResult<DialogueStage<Wrapper>>;
pub type In<State> = TransitionIn<State>;
pub type Out = TransitionOut<Wrapper>;
pub async fn start(cx: Cx<StartState>) -> Res {
pub async fn start(cx: In<StartState>) -> Out {
let (cx, dialogue) = cx.unpack();
cx.answer("Let's start! First, what's your full name?").send().await?;
next(dialogue.up())
}
pub async fn receive_full_name(cx: Cx<ReceiveFullNameState>) -> Res {
pub async fn receive_full_name(cx: In<ReceiveFullNameState>) -> Out {
let (cx, dialogue) = cx.unpack();
match cx.update.text_owned() {
@ -27,7 +27,7 @@ pub async fn receive_full_name(cx: Cx<ReceiveFullNameState>) -> Res {
}
}
pub async fn receive_age(cx: Cx<ReceiveAgeState>) -> Res {
pub async fn receive_age(cx: In<ReceiveAgeState>) -> Out {
let (cx, dialogue) = cx.unpack();
match cx.update.text().map(str::parse) {
@ -46,8 +46,8 @@ pub async fn receive_age(cx: Cx<ReceiveAgeState>) -> Res {
}
pub async fn receive_favourite_music(
cx: Cx<ReceiveFavouriteMusicState>,
) -> Res {
cx: In<ReceiveFavouriteMusicState>,
) -> Out {
let (cx, dialogue) = cx.unpack();
match cx.update.text().map(str::parse) {

View file

@ -49,6 +49,7 @@ mod dialogue_with_cx;
mod get_chat_id;
mod storage;
use crate::{requests::ResponseResult, types::Message};
pub use dialogue_dispatcher::DialogueDispatcher;
pub use dialogue_dispatcher_handler::DialogueDispatcherHandler;
pub use dialogue_stage::{exit, next, DialogueStage, DialogueWrapper};
@ -218,3 +219,7 @@ macro_rules! up {
)+
};
}
pub type TransitionIn<State> =
DialogueWithCx<Message, State, std::convert::Infallible>;
pub type TransitionOut<DWrapper> = ResponseResult<DialogueStage<DWrapper>>;

View file

@ -5,7 +5,7 @@ pub use crate::{
dispatching::{
dialogue::{
exit, next, DialogueDispatcher, DialogueStage, DialogueWithCx,
DialogueWrapper, GetChatId,
DialogueWrapper, GetChatId, TransitionIn, TransitionOut,
},
Dispatcher, DispatcherHandlerRx, DispatcherHandlerRxExt, UpdateWithCx,
},