Skip to main content

rust_tg_bot_ext/handlers/
shipping_query.rs

1//! [`ShippingQueryHandler`] -- handles shipping query updates.
2//!
3//! Ported from `python-telegram-bot`'s `ShippingQueryHandler`. Matches any
4//! update with `Update.shipping_query` set.
5
6use std::future::Future;
7use std::pin::Pin;
8use std::sync::Arc;
9
10use rust_tg_bot_raw::types::update::Update;
11
12use super::base::{Handler, HandlerCallback, HandlerResult, MatchResult};
13
14/// Handler for `Update.shipping_query`.
15///
16/// Only applicable to invoices with flexible pricing.
17pub struct ShippingQueryHandler {
18    callback: HandlerCallback,
19    block: bool,
20}
21
22impl ShippingQueryHandler {
23    /// Create a new `ShippingQueryHandler`.
24    pub fn new(callback: HandlerCallback, block: bool) -> Self {
25        Self { callback, block }
26    }
27}
28
29impl Handler for ShippingQueryHandler {
30    fn check_update(&self, update: &Update) -> Option<MatchResult> {
31        if update.shipping_query().is_some() {
32            Some(MatchResult::Empty)
33        } else {
34            None
35        }
36    }
37
38    fn handle_update(
39        &self,
40        update: Arc<Update>,
41        match_result: MatchResult,
42    ) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>> {
43        (self.callback)(update, match_result)
44    }
45
46    fn block(&self) -> bool {
47        self.block
48    }
49}