pub struct CallbackQueryHandler { /* private fields */ }Expand description
Handler for Update.callback_query.
When no pattern is set, any callback query matches. When a Data pattern
is set, only queries with matching .data are accepted (queries with only
.game_short_name are rejected, and vice versa).
Named capture groups in the regex pattern are exposed via
context.named_matches (a HashMap<String, String>), while all captures
(positional) are available as context.matches. This mirrors Python’s
behaviour of putting the full re.Match object into context.matches.
§Example
use rust_tg_bot_ext::handlers::callback_query::{CallbackQueryHandler, CallbackPattern};
use rust_tg_bot_ext::handlers::base::*;
use regex::Regex;
use std::sync::Arc;
// Regex-based matching:
let handler = CallbackQueryHandler::new(
Arc::new(|update, mr| Box::pin(async move { HandlerResult::Continue })),
Some(CallbackPattern::Data(Regex::new(r"^btn_(\d+)$").unwrap())),
true,
);
// Predicate-based matching (covers callable/type patterns):
let handler2 = CallbackQueryHandler::new(
Arc::new(|update, mr| Box::pin(async move { HandlerResult::Continue })),
Some(CallbackPattern::Predicate(Arc::new(|data| data.starts_with("action_")))),
true,
);Implementations§
Source§impl CallbackQueryHandler
impl CallbackQueryHandler
Sourcepub fn new(
callback: Arc<dyn Fn(Arc<Update>, MatchResult) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>> + Sync + Send>,
pattern: Option<CallbackPattern>,
block: bool,
) -> CallbackQueryHandler
pub fn new( callback: Arc<dyn Fn(Arc<Update>, MatchResult) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>> + Sync + Send>, pattern: Option<CallbackPattern>, block: bool, ) -> CallbackQueryHandler
Create a new CallbackQueryHandler.
Trait Implementations§
Source§impl Handler for CallbackQueryHandler
impl Handler for CallbackQueryHandler
Source§fn collect_additional_context(
&self,
context: &mut CallbackContext,
match_result: &MatchResult,
)
fn collect_additional_context( &self, context: &mut CallbackContext, match_result: &MatchResult, )
Populate context.matches (positional) and context.named_matches
(named groups) from the regex match result.
Mirrors Python’s CallbackQueryHandler.collect_additional_context
which injects the re.Match object into context.matches.
Source§fn check_update(&self, update: &Update) -> Option<MatchResult>
fn check_update(&self, update: &Update) -> Option<MatchResult>
update. Read moreSource§fn handle_update(
&self,
update: Arc<Update>,
match_result: MatchResult,
) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>>
fn handle_update( &self, update: Arc<Update>, match_result: MatchResult, ) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>>
check_update
returned Some.Source§fn block(&self) -> bool
fn block(&self) -> bool
Source§fn handle_update_with_context(
&self,
update: Arc<Update>,
match_result: MatchResult,
_context: CallbackContext,
) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>>
fn handle_update_with_context( &self, update: Arc<Update>, match_result: MatchResult, _context: CallbackContext, ) -> Pin<Box<dyn Future<Output = HandlerResult> + Send>>
CallbackContext. Read more