mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
parent
2f306fe488
commit
e7fb02e8fe
1 changed files with 19 additions and 6 deletions
|
@ -13,21 +13,30 @@
|
||||||
//! [`examples/dialogue.rs`] clearly demonstrates the typical usage of
|
//! [`examples/dialogue.rs`] clearly demonstrates the typical usage of
|
||||||
//! dialogues. Your dialogue state can be represented as an enumeration:
|
//! dialogues. Your dialogue state can be represented as an enumeration:
|
||||||
//!
|
//!
|
||||||
//! ```ignore
|
//! ```no_run
|
||||||
//! #[derive(Clone, Default)]
|
//! #[derive(Clone, Default)]
|
||||||
//! pub enum State {
|
//! pub enum State {
|
||||||
//! #[default]
|
//! #[default]
|
||||||
//! Start,
|
//! Start,
|
||||||
//! ReceiveFullName,
|
//! ReceiveFullName,
|
||||||
//! ReceiveAge { full_name: String },
|
//! ReceiveAge {
|
||||||
//! ReceiveLocation { full_name: String, age: u8 },
|
//! full_name: String,
|
||||||
|
//! },
|
||||||
|
//! ReceiveLocation {
|
||||||
|
//! full_name: String,
|
||||||
|
//! age: u8,
|
||||||
|
//! },
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Each state is associated with its respective handler: e.g., when a dialogue
|
//! Each state is associated with its respective handler: e.g., when a dialogue
|
||||||
//! state is `ReceiveAge`, `receive_age` is invoked:
|
//! state is `ReceiveAge`, `receive_age` is invoked:
|
||||||
//!
|
//!
|
||||||
//! ```ignore
|
//! ```no_run
|
||||||
|
//! # use teloxide::{dispatching::dialogue::InMemStorage, prelude::*};
|
||||||
|
//! # type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
||||||
|
//! # type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
//! # #[derive(Clone, Debug)] enum State { ReceiveLocation { full_name: String, age: u8 } }
|
||||||
//! async fn receive_age(
|
//! async fn receive_age(
|
||||||
//! bot: AutoSend<Bot>,
|
//! bot: AutoSend<Bot>,
|
||||||
//! msg: Message,
|
//! msg: Message,
|
||||||
|
@ -55,13 +64,17 @@
|
||||||
//! the dialogue, just call [`Dialogue::exit`] and it will be removed from the
|
//! the dialogue, just call [`Dialogue::exit`] and it will be removed from the
|
||||||
//! underlying storage:
|
//! underlying storage:
|
||||||
//!
|
//!
|
||||||
//! ```ignore
|
//! ```no_run
|
||||||
|
//! # use teloxide::{dispatching::dialogue::InMemStorage, prelude::*};
|
||||||
|
//! # type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
||||||
|
//! # type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
//! # #[derive(Clone, Debug)] enum State {}
|
||||||
//! async fn receive_location(
|
//! async fn receive_location(
|
||||||
//! bot: AutoSend<Bot>,
|
//! bot: AutoSend<Bot>,
|
||||||
//! msg: Message,
|
//! msg: Message,
|
||||||
//! dialogue: MyDialogue,
|
//! dialogue: MyDialogue,
|
||||||
//! (full_name, age): (String, u8), // Available from `State::ReceiveLocation`.
|
//! (full_name, age): (String, u8), // Available from `State::ReceiveLocation`.
|
||||||
//! ) -> anyhow::Result<()> {
|
//! ) -> HandlerResult {
|
||||||
//! match msg.text() {
|
//! match msg.text() {
|
||||||
//! Some(location) => {
|
//! Some(location) => {
|
||||||
//! let message =
|
//! let message =
|
||||||
|
|
Loading…
Reference in a new issue