mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-08 19:33:53 +01:00
Add dialogue::{TransitionIn, TransitionOut}
This commit is contained in:
parent
bf01d2bf8f
commit
7fc58421b0
3 changed files with 13 additions and 8 deletions
|
@ -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) {
|
||||
|
|
|
@ -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>>;
|
||||
|
|
|
@ -5,7 +5,7 @@ pub use crate::{
|
|||
dispatching::{
|
||||
dialogue::{
|
||||
exit, next, DialogueDispatcher, DialogueStage, DialogueWithCx,
|
||||
DialogueWrapper, GetChatId,
|
||||
DialogueWrapper, GetChatId, TransitionIn, TransitionOut,
|
||||
},
|
||||
Dispatcher, DispatcherHandlerRx, DispatcherHandlerRxExt, UpdateWithCx,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue