2020-07-26 23:47:02 +06:00
|
|
|
// The version of ngrok ping-pong-bot, which uses a webhook to receive updates
|
|
|
|
// from Telegram, instead of long polling.
|
2020-03-31 00:57:19 +06:00
|
|
|
|
2022-04-05 16:36:22 +04:00
|
|
|
use teloxide::{dispatching::update_listeners::webhooks, prelude::*};
|
2020-03-31 00:57:19 +06:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2022-03-21 18:53:59 +04:00
|
|
|
pretty_env_logger::init();
|
2022-04-27 01:00:08 +06:00
|
|
|
log::info!("Starting ngrok ping-pong bot...");
|
2021-12-27 21:13:46 +06:00
|
|
|
|
2022-09-29 09:37:20 +06:00
|
|
|
let bot = Bot::from_env();
|
2021-12-27 21:13:46 +06:00
|
|
|
|
2022-04-05 16:36:22 +04:00
|
|
|
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");
|
|
|
|
|
2022-03-24 17:25:42 +06:00
|
|
|
teloxide::repl_with_listener(
|
2022-04-05 16:36:22 +04:00
|
|
|
bot,
|
2022-10-03 17:54:06 +06:00
|
|
|
|bot: Bot, msg: Message| async move {
|
2022-02-02 15:40:22 +06:00
|
|
|
bot.send_message(msg.chat.id, "pong").await?;
|
2022-10-02 21:44:04 +06:00
|
|
|
Ok(())
|
2021-12-27 21:13:46 +06:00
|
|
|
},
|
2022-04-05 16:36:22 +04:00
|
|
|
listener,
|
2021-12-27 21:13:46 +06:00
|
|
|
)
|
|
|
|
.await;
|
2020-03-31 00:57:19 +06:00
|
|
|
}
|