mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
53be9d0e92
In reordering the parameters, I stick the following principle: place parameters from least changing to most changing. Thus, we have config and bot right from the beginning, next a dialogue with a possible payload, and next updates such as messages, inline queries, etc. This principle is used in languages with a native support for currying, although in Rust people appear to order parameters arbitrarily, so this commit is mostly for the sake of consistency.
Former-commit-id: 5922984f6c
28 lines
836 B
Rust
28 lines
836 B
Rust
// The version of ngrok ping-pong-bot, which uses a webhook to receive updates
|
|
// from Telegram, instead of long polling.
|
|
|
|
use teloxide::{dispatching::update_listeners::webhooks, prelude::*};
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
pretty_env_logger::init();
|
|
log::info!("Starting ngrok ping-pong bot...");
|
|
|
|
let bot = Bot::from_env();
|
|
|
|
let addr = ([127, 0, 0, 1], 8443).into();
|
|
let url = "Your HTTPS ngrok URL here. Get it by `ngrok http 8443`".parse().unwrap();
|
|
let listener = webhooks::axum(bot.clone(), webhooks::Options::new(addr, url))
|
|
.await
|
|
.expect("Couldn't setup webhook");
|
|
|
|
teloxide::repl_with_listener(
|
|
bot,
|
|
|bot: Bot, msg: Message| async move {
|
|
bot.send_message(msg.chat.id, "pong").await?;
|
|
Ok(())
|
|
},
|
|
listener,
|
|
)
|
|
.await;
|
|
}
|