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