pub struct TelegramContext {
pub init_data: TelegramInitData,
pub theme_params: TelegramThemeParams,
pub raw_init_data: String,
}Expand description
Global context of the Telegram Mini App, initialized once per app session.
Fields§
§init_data: TelegramInitData§theme_params: TelegramThemeParams§raw_init_data: StringImplementations§
Source§impl TelegramContext
impl TelegramContext
Sourcepub fn init(
init_data: TelegramInitData,
theme_params: TelegramThemeParams,
raw_init_data: String,
) -> Result<(), &'static str>
pub fn init( init_data: TelegramInitData, theme_params: TelegramThemeParams, raw_init_data: String, ) -> Result<(), &'static str>
Initializes the global Telegram context.
§Errors
Returns an error if the context was already initialized.
Sourcepub fn get<F, R>(f: F) -> Option<R>where
F: FnOnce(&TelegramContext) -> R,
pub fn get<F, R>(f: F) -> Option<R>where
F: FnOnce(&TelegramContext) -> R,
Access the global context if it has been initialized.
Accepts a closure and returns the result of applying it to the context.
Sourcepub fn get_raw_init_data() -> Result<String, &'static str>
pub fn get_raw_init_data() -> Result<String, &'static str>
Returns the raw initData string as provided by Telegram.
This is the URL-encoded initData string suitable for server-side signature validation. The string is captured during SDK initialization and remains unchanged.
§Errors
Returns an error if the SDK has not been initialized via
crate::core::init::init_sdk.
§Examples
use telegram_webapp_sdk::core::context::TelegramContext;
match TelegramContext::get_raw_init_data() {
Ok(raw) => {
// Send to backend for validation
println!("Raw initData: {}", raw);
}
Err(e) => eprintln!("Error: {}", e)
}Trait Implementations§
Source§impl Clone for TelegramContext
impl Clone for TelegramContext
Source§fn clone(&self) -> TelegramContext
fn clone(&self) -> TelegramContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TelegramContext
impl RefUnwindSafe for TelegramContext
impl Send for TelegramContext
impl Sync for TelegramContext
impl Unpin for TelegramContext
impl UnwindSafe for TelegramContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more