pub struct CallbackContext {
pub matches: Option<Vec<String>>,
pub named_matches: Option<HashMap<String, String>>,
pub args: Option<Vec<String>>,
pub error: Option<Arc<dyn Error + Sync + Send>>,
/* private fields */
}Expand description
A context object passed to handler callbacks.
Fields§
§matches: Option<Vec<String>>Positional regex match results (populated by regex-based handlers).
named_matches: Option<HashMap<String, String>>Named regex capture groups (populated by regex-based handlers when the pattern contains at least one named group).
Mirrors Python’s context.matches which exposes the full re.Match
object including match.groupdict().
args: Option<Vec<String>>Arguments to a command (populated by CommandHandler).
error: Option<Arc<dyn Error + Sync + Send>>The error that was raised. Only present in error handler contexts.
Implementations§
Source§impl CallbackContext
impl CallbackContext
Sourcepub fn new(
bot: Arc<ExtBot>,
chat_id: Option<i64>,
user_id: Option<i64>,
user_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>,
chat_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>,
bot_data: Arc<RwLock<HashMap<String, Value>>>,
) -> CallbackContext
pub fn new( bot: Arc<ExtBot>, chat_id: Option<i64>, user_id: Option<i64>, user_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>, chat_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>, bot_data: Arc<RwLock<HashMap<String, Value>>>, ) -> CallbackContext
Creates a new CallbackContext.
Sourcepub fn from_update(
update: &Update,
bot: Arc<ExtBot>,
user_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>,
chat_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>,
bot_data: Arc<RwLock<HashMap<String, Value>>>,
) -> CallbackContext
pub fn from_update( update: &Update, bot: Arc<ExtBot>, user_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>, chat_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>, bot_data: Arc<RwLock<HashMap<String, Value>>>, ) -> CallbackContext
Constructs a context from a typed Update.
Sourcepub fn from_error(
update: Option<&Update>,
error: Arc<dyn Error + Sync + Send>,
bot: Arc<ExtBot>,
user_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>,
chat_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>,
bot_data: Arc<RwLock<HashMap<String, Value>>>,
) -> CallbackContext
pub fn from_error( update: Option<&Update>, error: Arc<dyn Error + Sync + Send>, bot: Arc<ExtBot>, user_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>, chat_data_store: Arc<RwLock<HashMap<i64, HashMap<String, Value>>>>, bot_data: Arc<RwLock<HashMap<String, Value>>>, ) -> CallbackContext
Constructs a context for an error handler.
Sourcepub fn chat_id(&self) -> Option<i64>
pub fn chat_id(&self) -> Option<i64>
Returns the chat ID extracted from the update, if available.
Sourcepub fn user_id(&self) -> Option<i64>
pub fn user_id(&self) -> Option<i64>
Returns the user ID extracted from the update, if available.
Sourcepub async fn bot_data(&self) -> DataReadGuard<'_>
pub async fn bot_data(&self) -> DataReadGuard<'_>
Acquire a read lock on the bot-wide data store, returning a typed guard.
Sourcepub async fn bot_data_mut(&self) -> DataWriteGuard<'_>
pub async fn bot_data_mut(&self) -> DataWriteGuard<'_>
Acquire a write lock on the bot-wide data store, returning a typed guard.
Sourcepub async fn user_data(&self) -> Option<HashMap<String, Value>>
pub async fn user_data(&self) -> Option<HashMap<String, Value>>
Returns a cloned snapshot of the current user’s data, if a user ID is set.
Sourcepub async fn chat_data(&self) -> Option<HashMap<String, Value>>
pub async fn chat_data(&self) -> Option<HashMap<String, Value>>
Returns a cloned snapshot of the current chat’s data, if a chat ID is set.
Sourcepub async fn set_user_data(&self, key: String, value: Value) -> bool
pub async fn set_user_data(&self, key: String, value: Value) -> bool
Insert a key-value pair into the current user’s data store. Returns false if no user ID.
Sourcepub async fn set_chat_data(&self, key: String, value: Value) -> bool
pub async fn set_chat_data(&self, key: String, value: Value) -> bool
Insert a key-value pair into the current chat’s data store. Returns false if no chat ID.
Sourcepub fn match_result(&self) -> Option<&str>
pub fn match_result(&self) -> Option<&str>
Returns the first positional regex match, if available.
Sourcepub fn extra(&self) -> Option<&HashMap<String, Value>>
pub fn extra(&self) -> Option<&HashMap<String, Value>>
Returns a reference to the extra data map, if any data has been set.
Sourcepub fn extra_mut(&mut self) -> &mut HashMap<String, Value>
pub fn extra_mut(&mut self) -> &mut HashMap<String, Value>
Returns a mutable reference to the extra data map, creating it if needed.
Sourcepub fn set_extra(&mut self, key: String, value: Value)
pub fn set_extra(&mut self, key: String, value: Value)
Insert a key-value pair into the extra data map.
Sourcepub fn get_extra(&self, key: &str) -> Option<&Value>
pub fn get_extra(&self, key: &str) -> Option<&Value>
Get a value from the extra data map by key.
Sourcepub async fn drop_callback_data(
&self,
callback_query_id: &str,
) -> Result<(), InvalidCallbackData>
pub async fn drop_callback_data( &self, callback_query_id: &str, ) -> Result<(), InvalidCallbackData>
Drop the cached callback data for a given callback query ID.
Sourcepub async fn reply_text(
&self,
update: &Update,
text: &str,
) -> Result<Message, TelegramError>
pub async fn reply_text( &self, update: &Update, text: &str, ) -> Result<Message, TelegramError>
Send a text reply to the chat associated with the given update.
This is a convenience method that mirrors python-telegram-bot’s
update.message.reply_text(text) / context.bot.send_message(...).
§Errors
Returns TelegramError if the chat cannot be determined from the
update or if the Telegram API call fails.
Sourcepub async fn reply_html(
&self,
update: &Update,
text: &str,
) -> Result<Message, TelegramError>
pub async fn reply_html( &self, update: &Update, text: &str, ) -> Result<Message, TelegramError>
Send an HTML-formatted text reply to the chat associated with the given update.
Equivalent to reply_text with parse_mode("HTML").
§Errors
Returns TelegramError if the chat cannot be determined from the
update or if the Telegram API call fails.
Sourcepub async fn reply_markdown_v2(
&self,
update: &Update,
text: &str,
) -> Result<Message, TelegramError>
pub async fn reply_markdown_v2( &self, update: &Update, text: &str, ) -> Result<Message, TelegramError>
Send a MarkdownV2-formatted text reply to the chat associated with the given update.
Equivalent to reply_text with parse_mode("MarkdownV2").
§Errors
Returns TelegramError if the chat cannot be determined from the
update or if the Telegram API call fails.
Sourcepub async fn reply_photo(
&self,
update: &Update,
photo: InputFile,
) -> Result<Message, TelegramError>
pub async fn reply_photo( &self, update: &Update, photo: InputFile, ) -> Result<Message, TelegramError>
Send a photo reply to the chat associated with the given update.
§Errors
Returns TelegramError if the chat cannot be determined from the
update or if the Telegram API call fails.
Sourcepub async fn reply_document(
&self,
update: &Update,
document: InputFile,
) -> Result<Message, TelegramError>
pub async fn reply_document( &self, update: &Update, document: InputFile, ) -> Result<Message, TelegramError>
Send a document reply to the chat associated with the given update.
§Errors
Returns TelegramError if the chat cannot be determined from the
update or if the Telegram API call fails.
Sourcepub async fn reply_sticker(
&self,
update: &Update,
sticker: InputFile,
) -> Result<Message, TelegramError>
pub async fn reply_sticker( &self, update: &Update, sticker: InputFile, ) -> Result<Message, TelegramError>
Send a sticker reply to the chat associated with the given update.
§Errors
Returns TelegramError if the chat cannot be determined from the
update or if the Telegram API call fails.
Sourcepub async fn reply_location(
&self,
update: &Update,
latitude: f64,
longitude: f64,
) -> Result<Message, TelegramError>
pub async fn reply_location( &self, update: &Update, latitude: f64, longitude: f64, ) -> Result<Message, TelegramError>
Send a location reply to the chat associated with the given update.
§Errors
Returns TelegramError if the chat cannot be determined from the
update or if the Telegram API call fails.
Sourcepub async fn answer_callback_query(
&self,
update: &Update,
) -> Result<bool, TelegramError>
pub async fn answer_callback_query( &self, update: &Update, ) -> Result<bool, TelegramError>
Answer the callback query from the given update.
Automatically extracts the callback query ID from the update. This is
a convenience shortcut that eliminates the common boilerplate of
extracting update.callback_query.id manually.
§Errors
Returns TelegramError if the update does not contain a callback query
or if the Telegram API call fails.
Sourcepub async fn edit_callback_message_text(
&self,
update: &Update,
text: &str,
) -> Result<MessageOrBool, TelegramError>
pub async fn edit_callback_message_text( &self, update: &Update, text: &str, ) -> Result<MessageOrBool, TelegramError>
Edit the text of the message that originated the callback query.
Automatically determines whether to use chat_id + message_id or
inline_message_id based on the callback query contents.
§Errors
Returns TelegramError if the update does not contain a callback query,
the callback query has no associated message, or the Telegram API call fails.
Trait Implementations§
Source§impl Clone for CallbackContext
impl Clone for CallbackContext
Source§fn clone(&self) -> CallbackContext
fn clone(&self) -> CallbackContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more