pub struct Context { /* private fields */ }Expand description
Context for handling bot events
Provides access to event data and platform client. Platform-specific details are abstracted away - handlers work with a unified API.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new<T: ContextData>(data: T) -> Self
pub fn new<T: ContextData>(data: T) -> Self
Create a new context (called by platform implementations)
Sourcepub fn channel_id(&self) -> &str
pub fn channel_id(&self) -> &str
Get the channel/chat ID
Sourcepub fn command_name(&self) -> Option<&str>
pub fn command_name(&self) -> Option<&str>
Get the command name if this is a command event
Sourcepub fn command_args(&self) -> Option<&str>
pub fn command_args(&self) -> Option<&str>
Get command arguments as a string (for Telegram-style commands)
Sourcepub fn option(&self, name: &str) -> Option<OptionValue>
pub fn option(&self, name: &str) -> Option<OptionValue>
Get a command option value by name
Get the button/callback custom_id if this is a button event
Sourcepub fn message_content(&self) -> Option<&str>
pub fn message_content(&self) -> Option<&str>
Get the message content if available
Sourcepub fn platform<T: 'static>(&self) -> Option<&T>
pub fn platform<T: 'static>(&self) -> Option<&T>
Access platform-specific raw data (for advanced use cases)
Returns Some(&T) if the underlying platform data is of type T.
Sourcepub fn data(&self) -> &dyn ContextData
pub fn data(&self) -> &dyn ContextData
Get the inner context data for platform implementations
Sourcepub fn typing(&self) -> Option<ChatActionGuard>
pub fn typing(&self) -> Option<ChatActionGuard>
Start a typing indicator that auto-renews until the guard is dropped
Returns None if the platform doesn’t support typing indicators
or if the context doesn’t have the necessary client.
§Example
async fn slow_command(ctx: Context) -> String {
let _typing = ctx.typing();
// Do slow work...
expensive_computation().await;
"Done!"
}Trait Implementations§
Source§impl FromContext for Context
Extract the full context (for advanced use cases)
impl FromContext for Context
Extract the full context (for advanced use cases)