Files
OutFleet/src/services/telegram/bot.rs

48 lines
1.3 KiB
Rust
Raw Normal View History

2025-10-18 15:49:49 +03:00
use teloxide::{Bot, prelude::*};
use tokio::sync::oneshot;
use crate::database::DatabaseManager;
2025-10-19 15:23:17 +03:00
use crate::config::AppConfig;
2025-10-19 04:13:36 +03:00
use super::handlers::{self, Command};
2025-10-18 15:49:49 +03:00
/// Run the bot polling loop
pub async fn run_polling(
bot: Bot,
db: DatabaseManager,
2025-10-19 15:23:17 +03:00
app_config: AppConfig,
2025-10-18 15:49:49 +03:00
mut shutdown_rx: oneshot::Receiver<()>,
) {
tracing::info!("Starting Telegram bot polling...");
2025-10-19 04:13:36 +03:00
let handler = dptree::entry()
2025-10-18 15:49:49 +03:00
.branch(
2025-10-19 04:13:36 +03:00
Update::filter_message()
.branch(
dptree::entry()
.filter_command::<Command>()
.endpoint(handlers::handle_command)
)
.branch(
dptree::endpoint(handlers::handle_message)
)
2025-10-18 15:49:49 +03:00
)
.branch(
2025-10-19 04:13:36 +03:00
Update::filter_callback_query()
.endpoint(handlers::handle_callback_query)
2025-10-18 15:49:49 +03:00
);
let mut dispatcher = Dispatcher::builder(bot.clone(), handler)
2025-10-19 15:23:17 +03:00
.dependencies(dptree::deps![db, app_config])
2025-10-18 15:49:49 +03:00
.enable_ctrlc_handler()
.build();
// Run dispatcher with shutdown signal
tokio::select! {
_ = dispatcher.dispatch() => {
tracing::info!("Telegram bot polling stopped");
}
_ = shutdown_rx => {
tracing::info!("Telegram bot received shutdown signal");
}
}
}