use teloxide::{Bot, types::Update};
use super::{AppState, process_update, telegram_requests};
#[derive(Clone)]
pub(super) struct UpdateDispatcher {
inner: kcode_telegram_update_dispatch::UpdateDispatcher,
}
impl UpdateDispatcher {
pub(super) fn new(bot: Bot, state: AppState) -> Self {
let inner = kcode_telegram_update_dispatch::UpdateDispatcher::new(move |update: Update| {
let bot = bot.clone();
let state = state.clone();
async move {
let update_id = i64::from(update.id.0);
if let Err(error) = process_update(&bot, &state, update).await {
tracing::warn!(
update_id,
error_class = telegram_requests::anyhow_error_class(&error),
"Telegram update failed locally; later work will continue"
);
}
Ok(())
}
});
Self { inner }
}
pub(super) async fn enqueue(&self, update: Update) -> anyhow::Result<()> {
self.inner.enqueue(update).await
}
}