mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Update examples/simple_dialogue
This commit is contained in:
parent
26d721d928
commit
3aeb9c4295
2 changed files with 16 additions and 10 deletions
|
@ -1,19 +1,21 @@
|
|||
use teloxide::prelude::*;
|
||||
|
||||
use std::env::{set_var, var};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Configure a fancy logger. Let this bot print everything, but restrict
|
||||
// teloxide to only log errors.
|
||||
std::env::set_var("RUST_LOG", "ping_pong_bot=trace");
|
||||
std::env::set_var("RUST_LOG", "teloxide=error");
|
||||
set_var("RUST_LOG", "ping_pong_bot=trace");
|
||||
set_var("RUST_LOG", "teloxide=error");
|
||||
pretty_env_logger::init();
|
||||
log::info!("Starting the ping-pong bot!");
|
||||
|
||||
// Creates a dispatcher of updates with the specified bot. Don't forget to
|
||||
// replace `MyAwesomeToken` with yours.
|
||||
Dispatcher::<RequestError>::new(Bot::new("MyAwesomeToken"))
|
||||
// Registers a message handler. Inside a body of the closure, answer
|
||||
// `"pong"` to an incoming message.
|
||||
let bot = Bot::new(var("TELOXIDE_TOKEN").unwrap());
|
||||
|
||||
// Create a dispatcher with a single message handler that answers "pong" to
|
||||
// each incoming message.
|
||||
Dispatcher::<RequestError>::new(bot)
|
||||
.message_handler(&|ctx: DispatcherHandlerCtx<Message>| async move {
|
||||
ctx.answer("pong").send().await?;
|
||||
Ok(())
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#[macro_use]
|
||||
extern crate smart_default;
|
||||
|
||||
use std::env::{set_var, var};
|
||||
|
||||
use teloxide::{
|
||||
prelude::*,
|
||||
types::{KeyboardButton, ReplyKeyboardMarkup},
|
||||
|
@ -173,12 +175,14 @@ async fn handle_message(ctx: Ctx<Dialogue>) -> Res {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
std::env::set_var("RUST_LOG", "simple_dialogue=trace");
|
||||
std::env::set_var("RUST_LOG", "teloxide=error");
|
||||
set_var("RUST_LOG", "simple_dialogue=trace");
|
||||
set_var("RUST_LOG", "teloxide=error");
|
||||
pretty_env_logger::init();
|
||||
log::info!("Starting the simple_dialogue bot!");
|
||||
|
||||
Dispatcher::new(Bot::new("MyAwesomeToken"))
|
||||
let bot = Bot::new(var("TELOXIDE_TOKEN").unwrap());
|
||||
|
||||
Dispatcher::new(bot)
|
||||
.message_handler(&DialogueDispatcher::new(|ctx| async move {
|
||||
handle_message(ctx)
|
||||
.await
|
||||
|
|
Loading…
Reference in a new issue