pub struct TelegramWebApp { /* private fields */ }Expand description
Safe wrapper around window.Telegram.WebApp
Implementations§
Source§impl TelegramWebApp
impl TelegramWebApp
Sourcepub fn try_instance() -> Result<Self, JsValue>
pub fn try_instance() -> Result<Self, JsValue>
Sourcepub fn validate_init_data(
init_data: &str,
key: ValidationKey<'_>,
) -> Result<(), ValidationError>
pub fn validate_init_data( init_data: &str, key: ValidationKey<'_>, ) -> Result<(), ValidationError>
Validate an initData payload using either HMAC-SHA256 or Ed25519.
Pass ValidationKey::BotToken to verify the hash parameter using
the bot token. Use ValidationKey::Ed25519PublicKey to verify the
signature parameter with an Ed25519 public key.
§Errors
Returns validate_init_data::ValidationError if validation fails.
§Examples
use telegram_webapp_sdk::{TelegramWebApp, validate_init_data::ValidationKey};
let bot_token = "123456:ABC";
let query = "a=1&b=2&hash=9e5e8d7c0b1f9f3a";
TelegramWebApp::validate_init_data(query, ValidationKey::BotToken(bot_token)).unwrap();Sourcepub fn enable_closing_confirmation(&self) -> Result<(), JsValue>
pub fn enable_closing_confirmation(&self) -> Result<(), JsValue>
Sourcepub fn disable_closing_confirmation(&self) -> Result<(), JsValue>
pub fn disable_closing_confirmation(&self) -> Result<(), JsValue>
Sourcepub fn is_closing_confirmation_enabled(&self) -> bool
pub fn is_closing_confirmation_enabled(&self) -> bool
Returns whether closing confirmation is currently enabled.
§Examples
let _ = app.is_closing_confirmation_enabled();Sourcepub fn request_fullscreen(&self) -> Result<(), JsValue>
pub fn request_fullscreen(&self) -> Result<(), JsValue>
Sourcepub fn exit_fullscreen(&self) -> Result<(), JsValue>
pub fn exit_fullscreen(&self) -> Result<(), JsValue>
Sourcepub fn unlock_orientation(&self) -> Result<(), JsValue>
pub fn unlock_orientation(&self) -> Result<(), JsValue>
Sourcepub fn enable_vertical_swipes(&self) -> Result<(), JsValue>
pub fn enable_vertical_swipes(&self) -> Result<(), JsValue>
Sourcepub fn disable_vertical_swipes(&self) -> Result<(), JsValue>
pub fn disable_vertical_swipes(&self) -> Result<(), JsValue>
Sourcepub fn open_telegram_link(&self, url: &str) -> Result<(), JsValue>
pub fn open_telegram_link(&self, url: &str) -> Result<(), JsValue>
Call WebApp.openTelegramLink(url).
§Examples
app.open_telegram_link("https://t.me/telegram").unwrap();Sourcepub fn open_invoice<F>(&self, url: &str, callback: F) -> Result<(), JsValue>
pub fn open_invoice<F>(&self, url: &str, callback: F) -> Result<(), JsValue>
Call WebApp.openInvoice(url, callback).
§Examples
app.open_invoice("https://invoice", |status| {
let _ = status;
})
.unwrap();Sourcepub fn switch_inline_query(
&self,
query: &str,
choose_chat_types: Option<&JsValue>,
) -> Result<(), JsValue>
pub fn switch_inline_query( &self, query: &str, choose_chat_types: Option<&JsValue>, ) -> Result<(), JsValue>
Sourcepub fn join_voice_chat(
&self,
chat_id: &str,
invite_hash: Option<&str>,
) -> Result<(), JsValue>
pub fn join_voice_chat( &self, chat_id: &str, invite_hash: Option<&str>, ) -> Result<(), JsValue>
Sourcepub fn add_to_home_screen(&self) -> Result<bool, JsValue>
pub fn add_to_home_screen(&self) -> Result<bool, JsValue>
Call WebApp.addToHomeScreen() and return whether the prompt was shown.
§Examples
let _shown = app.add_to_home_screen().unwrap();Sourcepub fn check_home_screen_status<F>(&self, callback: F) -> Result<(), JsValue>
pub fn check_home_screen_status<F>(&self, callback: F) -> Result<(), JsValue>
Call WebApp.checkHomeScreenStatus(callback).
§Examples
app.check_home_screen_status(|status| {
let _ = status;
})
.unwrap();Sourcepub fn request_write_access<F>(&self, callback: F) -> Result<(), JsValue>
pub fn request_write_access<F>(&self, callback: F) -> Result<(), JsValue>
Sourcepub fn download_file<F>(
&self,
params: DownloadFileParams<'_>,
callback: F,
) -> Result<(), JsValue>
pub fn download_file<F>( &self, params: DownloadFileParams<'_>, callback: F, ) -> Result<(), JsValue>
Call WebApp.downloadFile(params, callback).
§Examples
let params = DownloadFileParams {
url: "https://example.com/file",
file_name: None,
mime_type: None
};
app.download_file(params, |file_id| {
let _ = file_id;
})
.unwrap();§Errors
Returns JsValue if the underlying JS call fails or the parameters
fail to serialize.
Sourcepub fn request_emoji_status_access<F>(&self, callback: F) -> Result<(), JsValue>
pub fn request_emoji_status_access<F>(&self, callback: F) -> Result<(), JsValue>
Sourcepub fn show_popup<F>(
&self,
params: &JsValue,
callback: F,
) -> Result<(), JsValue>
pub fn show_popup<F>( &self, params: &JsValue, callback: F, ) -> Result<(), JsValue>
Call WebApp.showPopup(params, callback).
§Examples
let params = Object::new();
app.show_popup(¶ms.into(), |id| {
let _ = id;
})
.unwrap();Sourcepub fn show_scan_qr_popup<F>(
&self,
text: &str,
callback: F,
) -> Result<(), JsValue>
pub fn show_scan_qr_popup<F>( &self, text: &str, callback: F, ) -> Result<(), JsValue>
Call WebApp.showScanQrPopup(text, callback).
§Examples
app.show_scan_qr_popup("Scan", |text| {
let _ = text;
})
.unwrap();Sourcepub fn close_scan_qr_popup(&self) -> Result<(), JsValue>
pub fn close_scan_qr_popup(&self) -> Result<(), JsValue>
Sourcepub fn hide_keyboard(&self) -> Result<(), JsValue>
pub fn hide_keyboard(&self) -> Result<(), JsValue>
Sourcepub fn read_text_from_clipboard<F>(&self, callback: F) -> Result<(), JsValue>
pub fn read_text_from_clipboard<F>(&self, callback: F) -> Result<(), JsValue>
Set callback for onClick() on a bottom button.
Returns an EventHandle that can be used to remove the callback.
§Errors
Returns JsValue if the underlying JS call fails.
Legacy alias for Self::show_bottom_button with
BottomButton::Main.
Show the secondary bottom button.
Legacy alias for Self::hide_bottom_button with
BottomButton::Main.
Hide the secondary bottom button.
Legacy alias for Self::set_bottom_button_text with
BottomButton::Main.
Set text for the secondary bottom button.
Legacy alias for Self::set_bottom_button_color with
BottomButton::Main.
Set color for the secondary bottom button.
Legacy alias for Self::set_bottom_button_text_color with
BottomButton::Main.
Set text color for the secondary bottom button.
Legacy alias for Self::set_bottom_button_callback with
BottomButton::Main.
Set callback for the secondary bottom button.
Legacy alias for Self::remove_bottom_button_callback.
Remove callback for the secondary bottom button.
Sourcepub fn on_event<F>(
&self,
event: &str,
callback: F,
) -> Result<EventHandle<dyn FnMut(JsValue)>, JsValue>
pub fn on_event<F>( &self, event: &str, callback: F, ) -> Result<EventHandle<dyn FnMut(JsValue)>, JsValue>
Register event handler (web_app_event_name, callback).
Returns an EventHandle that can be passed to
off_event.
§Errors
Returns JsValue if the underlying JS call fails.
Sourcepub fn on_background_event<F>(
&self,
event: BackgroundEvent,
callback: F,
) -> Result<EventHandle<dyn FnMut(JsValue)>, JsValue>
pub fn on_background_event<F>( &self, event: BackgroundEvent, callback: F, ) -> Result<EventHandle<dyn FnMut(JsValue)>, JsValue>
Register a callback for a background event.
Returns an EventHandle that can be passed to
off_event.
§Errors
Returns JsValue if the underlying JS call fails.
Sourcepub fn viewport_height(&self) -> Option<f64>
pub fn viewport_height(&self) -> Option<f64>
Sourcepub fn viewport_width(&self) -> Option<f64>
pub fn viewport_width(&self) -> Option<f64>
Sourcepub fn viewport_stable_height(&self) -> Option<f64>
pub fn viewport_stable_height(&self) -> Option<f64>
pub fn is_expanded(&self) -> bool
Sourcepub fn expand_viewport(&self) -> Result<(), JsValue>
pub fn expand_viewport(&self) -> Result<(), JsValue>
Sourcepub fn on_theme_changed<F>(
&self,
callback: F,
) -> Result<EventHandle<dyn FnMut()>, JsValue>where
F: 'static + Fn(),
pub fn on_theme_changed<F>(
&self,
callback: F,
) -> Result<EventHandle<dyn FnMut()>, JsValue>where
F: 'static + Fn(),
Register a callback for theme changes.
Returns an EventHandle that can be passed to
off_event.
§Errors
Returns JsValue if the underlying JS call fails.
Sourcepub fn on_safe_area_changed<F>(
&self,
callback: F,
) -> Result<EventHandle<dyn FnMut()>, JsValue>where
F: 'static + Fn(),
pub fn on_safe_area_changed<F>(
&self,
callback: F,
) -> Result<EventHandle<dyn FnMut()>, JsValue>where
F: 'static + Fn(),
Register a callback for safe area changes.
Returns an EventHandle that can be passed to
off_event.
§Errors
Returns JsValue if the underlying JS call fails.
Sourcepub fn on_content_safe_area_changed<F>(
&self,
callback: F,
) -> Result<EventHandle<dyn FnMut()>, JsValue>where
F: 'static + Fn(),
pub fn on_content_safe_area_changed<F>(
&self,
callback: F,
) -> Result<EventHandle<dyn FnMut()>, JsValue>where
F: 'static + Fn(),
Register a callback for content safe area changes.
Returns an EventHandle that can be passed to
off_event.
§Errors
Returns JsValue if the underlying JS call fails.
Sourcepub fn on_viewport_changed<F>(
&self,
callback: F,
) -> Result<EventHandle<dyn FnMut()>, JsValue>where
F: 'static + Fn(),
pub fn on_viewport_changed<F>(
&self,
callback: F,
) -> Result<EventHandle<dyn FnMut()>, JsValue>where
F: 'static + Fn(),
Register a callback for viewport changes.
Returns an EventHandle that can be passed to
off_event.
§Errors
Returns JsValue if the underlying JS call fails.
Sourcepub fn on_clipboard_text_received<F>(
&self,
callback: F,
) -> Result<EventHandle<dyn FnMut(JsValue)>, JsValue>
pub fn on_clipboard_text_received<F>( &self, callback: F, ) -> Result<EventHandle<dyn FnMut(JsValue)>, JsValue>
Register a callback for received clipboard text.
Returns an EventHandle that can be passed to
off_event.
§Errors
Returns JsValue if the underlying JS call fails.
Sourcepub fn on_invoice_closed<F>(
&self,
callback: F,
) -> Result<EventHandle<dyn FnMut(String)>, JsValue>
pub fn on_invoice_closed<F>( &self, callback: F, ) -> Result<EventHandle<dyn FnMut(String)>, JsValue>
Register a callback for invoice payment result.
Returns an EventHandle that can be passed to
off_event.
§Examples
let handle = app
.on_invoice_closed(|status| {
let _ = status;
})
.unwrap();
app.off_event(handle).unwrap();§Errors
Returns JsValue if the underlying JS call fails.
Registers a callback for the native back button.
Returns an EventHandle that can be passed to
remove_back_button_callback.
§Examples
let handle = app.set_back_button_callback(|| {}).expect("callback");
app.remove_back_button_callback(handle).unwrap();§Errors
Returns JsValue if the underlying JS call fails.
Trait Implementations§
Source§impl Clone for TelegramWebApp
impl Clone for TelegramWebApp
Source§fn clone(&self) -> TelegramWebApp
fn clone(&self) -> TelegramWebApp
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more