mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-22 06:45:37 +01:00
Return examples/ping_pong_bot.rs back
This commit is contained in:
parent
1821e1f703
commit
2b77087aac
2 changed files with 38 additions and 1 deletions
|
@ -12,7 +12,7 @@ serde = { version = "1.0.101", features = ["derive"] }
|
||||||
tokio = { version = "0.2.6", features = ["full"] }
|
tokio = { version = "0.2.6", features = ["full"] }
|
||||||
tokio-util = { version = "0.2.0", features = ["full"] }
|
tokio-util = { version = "0.2.0", features = ["full"] }
|
||||||
|
|
||||||
reqwest = { version = "0.10", features = ["json", "stream"] }
|
reqwest = { version = "0.10", features = ["json", "stream", "native-tls-vendored"] }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
bytes = "0.5.3"
|
bytes = "0.5.3"
|
||||||
|
|
||||||
|
|
37
examples/ping_pong_bot.rs
Normal file
37
examples/ping_pong_bot.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
use futures::stream::StreamExt;
|
||||||
|
use teloxide::{
|
||||||
|
dispatching::{
|
||||||
|
chat::{ChatUpdate, ChatUpdateKind, Dispatcher},
|
||||||
|
update_listeners::polling_default,
|
||||||
|
SessionState,
|
||||||
|
},
|
||||||
|
requests::Request,
|
||||||
|
Bot,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let bot = &Bot::new("1061598315:AAErEDodTsrqD3UxA_EvFyEfXbKA6DT25G0");
|
||||||
|
let mut updater = Box::pin(polling_default(bot));
|
||||||
|
let handler = |s, upd: ChatUpdate| async move {
|
||||||
|
match upd.kind {
|
||||||
|
ChatUpdateKind::Message(m) => {
|
||||||
|
let msg = bot.send_message(m.chat.id, "pong");
|
||||||
|
msg.send().await.unwrap();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
SessionState::Continue(s)
|
||||||
|
};
|
||||||
|
let mut dp = Dispatcher::<'_, (), _>::new(handler);
|
||||||
|
println!("Starting the message handler.");
|
||||||
|
loop {
|
||||||
|
let u = updater.next().await.unwrap();
|
||||||
|
match u {
|
||||||
|
Err(e) => eprintln!("Error: {}", e),
|
||||||
|
Ok(u) => {
|
||||||
|
let _ = dp.dispatch(u).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue