mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Move the dispatch schema to a function (examples/purchase.rs
)
This commit is contained in:
parent
056b6df3eb
commit
51d00ec351
1 changed files with 16 additions and 12 deletions
|
@ -13,7 +13,10 @@
|
|||
// ```
|
||||
|
||||
use teloxide::{
|
||||
dispatching::dialogue::{self, InMemStorage},
|
||||
dispatching::{
|
||||
dialogue::{self, InMemStorage},
|
||||
UpdateHandler,
|
||||
},
|
||||
prelude::*,
|
||||
types::{InlineKeyboardButton, InlineKeyboardMarkup},
|
||||
utils::command::BotCommands,
|
||||
|
@ -53,6 +56,15 @@ async fn main() {
|
|||
|
||||
let bot = Bot::from_env().auto_send();
|
||||
|
||||
Dispatcher::builder(bot, schema())
|
||||
.dependencies(dptree::deps![InMemStorage::<State>::new()])
|
||||
.build()
|
||||
.setup_ctrlc_handler()
|
||||
.dispatch()
|
||||
.await;
|
||||
}
|
||||
|
||||
fn schema() -> UpdateHandler<Box<dyn std::error::Error + Send + Sync + 'static>> {
|
||||
let command_handler = teloxide::filter_command::<Command, _>()
|
||||
.branch(
|
||||
teloxide::handler![State::Start]
|
||||
|
@ -71,17 +83,9 @@ async fn main() {
|
|||
.endpoint(receive_product_selection),
|
||||
);
|
||||
|
||||
Dispatcher::builder(
|
||||
bot,
|
||||
dialogue::enter::<Update, InMemStorage<State>, State, _>()
|
||||
.branch(message_handler)
|
||||
.branch(callback_query_handler),
|
||||
)
|
||||
.dependencies(dptree::deps![InMemStorage::<State>::new()])
|
||||
.build()
|
||||
.setup_ctrlc_handler()
|
||||
.dispatch()
|
||||
.await;
|
||||
dialogue::enter::<Update, InMemStorage<State>, State, _>()
|
||||
.branch(message_handler)
|
||||
.branch(callback_query_handler)
|
||||
}
|
||||
|
||||
async fn start(bot: AutoSend<Bot>, msg: Message, dialogue: MyDialogue) -> HandlerResult {
|
||||
|
|
Loading…
Reference in a new issue