TelegramWebApp

Struct TelegramWebApp 

Source
pub struct TelegramWebApp { /* private fields */ }
Expand description

Safe wrapper around window.Telegram.WebApp

Implementations§

Source§

impl TelegramWebApp

Source

pub fn instance() -> Option<Self>

Get instance of Telegram.WebApp or None if not present

Source

pub fn try_instance() -> Result<Self, JsValue>

Try to get instance of Telegram.WebApp.

§Errors

Returns JsValue if the Telegram.WebApp object is missing or malformed.

Source

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();
Source

pub fn send_data(&self, data: &str) -> Result<(), JsValue>

Call WebApp.sendData(data).

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn expand(&self) -> Result<(), JsValue>

Call WebApp.expand().

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn close(&self) -> Result<(), JsValue>

Call WebApp.close().

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn enable_closing_confirmation(&self) -> Result<(), JsValue>

Call WebApp.enableClosingConfirmation().

§Examples
app.enable_closing_confirmation().unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn disable_closing_confirmation(&self) -> Result<(), JsValue>

Call WebApp.disableClosingConfirmation().

§Examples
app.disable_closing_confirmation().unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn is_closing_confirmation_enabled(&self) -> bool

Returns whether closing confirmation is currently enabled.

§Examples
let _ = app.is_closing_confirmation_enabled();
Source

pub fn request_fullscreen(&self) -> Result<(), JsValue>

Call WebApp.requestFullscreen().

§Examples
app.request_fullscreen().unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn exit_fullscreen(&self) -> Result<(), JsValue>

Call WebApp.exitFullscreen().

§Examples
app.exit_fullscreen().unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn lock_orientation(&self, orientation: &str) -> Result<(), JsValue>

Call WebApp.lockOrientation(orientation).

§Examples
app.lock_orientation("portrait").unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn unlock_orientation(&self) -> Result<(), JsValue>

Call WebApp.unlockOrientation().

§Examples
app.unlock_orientation().unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn enable_vertical_swipes(&self) -> Result<(), JsValue>

Call WebApp.enableVerticalSwipes().

§Examples
app.enable_vertical_swipes().unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn disable_vertical_swipes(&self) -> Result<(), JsValue>

Call WebApp.disableVerticalSwipes().

§Examples
app.disable_vertical_swipes().unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn show_alert(&self, msg: &str) -> Result<(), JsValue>

Call WebApp.showAlert(message).

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn show_confirm<F>(&self, msg: &str, on_confirm: F) -> Result<(), JsValue>
where F: 'static + Fn(bool),

Call WebApp.showConfirm(message, callback).

§Errors

Returns JsValue if the underlying JS call fails.

Call WebApp.openLink(url).

§Examples
app.open_link("https://example.com", None).unwrap();

Call WebApp.openTelegramLink(url).

§Examples
app.open_telegram_link("https://t.me/telegram").unwrap();
Source

pub fn is_version_at_least(&self, version: &str) -> Result<bool, JsValue>

Returns whether the WebApp version is at least the provided value.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.is_version_at_least("9.0");
}
Source

pub fn open_invoice<F>(&self, url: &str, callback: F) -> Result<(), JsValue>
where F: 'static + Fn(String),

Call WebApp.openInvoice(url, callback).

§Examples
app.open_invoice("https://invoice", |status| {
    let _ = status;
})
.unwrap();
Source

pub fn switch_inline_query( &self, query: &str, choose_chat_types: Option<&JsValue>, ) -> Result<(), JsValue>

Call WebApp.switchInlineQuery(query, choose_chat_types).

§Examples
app.switch_inline_query("query", None).unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn share_message<F>(&self, msg_id: &str, callback: F) -> Result<(), JsValue>
where F: 'static + Fn(bool),

Call WebApp.shareMessage(msg_id, callback).

§Examples
app.share_message("id123", |sent| {
    let _ = sent;
})
.unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn share_to_story( &self, media_url: &str, params: Option<&JsValue>, ) -> Result<(), JsValue>

Call WebApp.shareToStory(media_url, params).

§Examples
let params = Object::new();
app.share_to_story("https://example.com/image.png", Some(&params.into()))
    .unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn share_url(&self, url: &str, text: Option<&str>) -> Result<(), JsValue>

Call WebApp.shareURL(url, text).

§Examples
app.share_url("https://example.com", Some("Check this"))
    .unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn join_voice_chat( &self, chat_id: &str, invite_hash: Option<&str>, ) -> Result<(), JsValue>

Call WebApp.joinVoiceChat(chat_id, invite_hash).

§Examples
app.join_voice_chat("chat", None).unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

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();
Source

pub fn check_home_screen_status<F>(&self, callback: F) -> Result<(), JsValue>
where F: 'static + Fn(String),

Call WebApp.checkHomeScreenStatus(callback).

§Examples
app.check_home_screen_status(|status| {
    let _ = status;
})
.unwrap();
Source

pub fn request_write_access<F>(&self, callback: F) -> Result<(), JsValue>
where F: 'static + Fn(bool),

Call WebApp.requestWriteAccess(callback).

§Examples
app.request_write_access(|granted| {
    let _ = granted;
})
.unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn download_file<F>( &self, params: DownloadFileParams<'_>, callback: F, ) -> Result<(), JsValue>
where F: 'static + Fn(String),

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.

Source

pub fn request_emoji_status_access<F>(&self, callback: F) -> Result<(), JsValue>
where F: 'static + Fn(bool),

Call WebApp.requestEmojiStatusAccess(callback).

§Examples
app.request_emoji_status_access(|granted| {
    let _ = granted;
})
.unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn set_emoji_status<F>( &self, status: &JsValue, callback: F, ) -> Result<(), JsValue>
where F: 'static + Fn(bool),

Call WebApp.setEmojiStatus(status, callback).

§Examples
let status = Object::new();
let _ = Reflect::set(&status, &"custom_emoji_id".into(), &"123".into());
app.set_emoji_status(&status.into(), |success| {
    let _ = success;
})
.unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn show_popup<F>( &self, params: &JsValue, callback: F, ) -> Result<(), JsValue>
where F: 'static + Fn(String),

Call WebApp.showPopup(params, callback).

§Examples
let params = Object::new();
app.show_popup(&params.into(), |id| {
    let _ = id;
})
.unwrap();
Source

pub fn show_scan_qr_popup<F>( &self, text: &str, callback: F, ) -> Result<(), JsValue>
where F: 'static + Fn(String),

Call WebApp.showScanQrPopup(text, callback).

§Examples
app.show_scan_qr_popup("Scan", |text| {
    let _ = text;
})
.unwrap();
Source

pub fn close_scan_qr_popup(&self) -> Result<(), JsValue>

Call WebApp.closeScanQrPopup().

§Examples
app.close_scan_qr_popup().unwrap();
Source

pub fn hide_keyboard(&self) -> Result<(), JsValue>

Hide the on-screen keyboard. Call WebApp.hideKeyboard().

§Examples
app.hide_keyboard().unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn read_text_from_clipboard<F>(&self, callback: F) -> Result<(), JsValue>
where F: 'static + Fn(String),

Call WebApp.readTextFromClipboard(callback).

§Examples
app.read_text_from_clipboard(|text| {
    let _ = text;
})
.unwrap();
§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn show_bottom_button(&self, button: BottomButton) -> Result<(), JsValue>

Call WebApp.MainButton.show().

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn hide_bottom_button(&self, button: BottomButton) -> Result<(), JsValue>

Hide a bottom button.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn ready(&self) -> Result<(), JsValue>

Call WebApp.ready().

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn show_back_button(&self) -> Result<(), JsValue>

Show back button.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn hide_back_button(&self) -> Result<(), JsValue>

Hide back button.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn set_header_color(&self, color: &str) -> Result<(), JsValue>

Call WebApp.setHeaderColor(color).

§Errors

Returns JsValue if the underlying JS call fails.

§Examples
app.set_header_color("#ffffff").unwrap();
Source

pub fn set_background_color(&self, color: &str) -> Result<(), JsValue>

Call WebApp.setBackgroundColor(color).

§Errors

Returns JsValue if the underlying JS call fails.

§Examples
app.set_background_color("#ffffff").unwrap();
Source

pub fn set_bottom_bar_color(&self, color: &str) -> Result<(), JsValue>

Call WebApp.setBottomBarColor(color).

§Errors

Returns JsValue if the underlying JS call fails.

§Examples
app.set_bottom_bar_color("#ffffff").unwrap();
Source

pub fn set_bottom_button_text( &self, button: BottomButton, text: &str, ) -> Result<(), JsValue>

Set main button text.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn set_bottom_button_color( &self, button: BottomButton, color: &str, ) -> Result<(), JsValue>

Set bottom button color (setColor(color)).

§Errors

Returns JsValue if the underlying JS call fails.

§Examples
let _ = app.set_bottom_button_color(BottomButton::Main, "#ff0000");
Source

pub fn set_bottom_button_text_color( &self, button: BottomButton, color: &str, ) -> Result<(), JsValue>

Set bottom button text color (setTextColor(color)).

§Errors

Returns JsValue if the underlying JS call fails.

§Examples
let _ = app.set_bottom_button_text_color(BottomButton::Main, "#ffffff");
Source

pub fn enable_bottom_button(&self, button: BottomButton) -> Result<(), JsValue>

Enable a bottom button, allowing user interaction.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.enable_bottom_button(BottomButton::Main);
}
Source

pub fn disable_bottom_button(&self, button: BottomButton) -> Result<(), JsValue>

Disable a bottom button, preventing user interaction.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.disable_bottom_button(BottomButton::Main);
}
Source

pub fn show_bottom_button_progress( &self, button: BottomButton, leave_active: bool, ) -> Result<(), JsValue>

Show the circular loading indicator on a bottom button.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.show_bottom_button_progress(BottomButton::Main, false);
}
Source

pub fn hide_bottom_button_progress( &self, button: BottomButton, ) -> Result<(), JsValue>

Hide the loading indicator on a bottom button.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.hide_bottom_button_progress(BottomButton::Main);
}
Source

pub fn is_bottom_button_visible(&self, button: BottomButton) -> bool

Returns whether the specified bottom button is currently visible.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.is_bottom_button_visible(BottomButton::Main);
}
Source

pub fn is_bottom_button_active(&self, button: BottomButton) -> bool

Returns whether the specified bottom button is active (enabled).

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.is_bottom_button_active(BottomButton::Main);
}
Source

pub fn is_bottom_button_progress_visible(&self, button: BottomButton) -> bool

Returns whether the progress indicator is visible on the button.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.is_bottom_button_progress_visible(BottomButton::Main);
}
Source

pub fn bottom_button_text(&self, button: BottomButton) -> Option<String>

Returns the current text displayed on the button.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.bottom_button_text(BottomButton::Main);
}
Source

pub fn bottom_button_text_color(&self, button: BottomButton) -> Option<String>

Returns the current text color of the button.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.bottom_button_text_color(BottomButton::Main);
}
Source

pub fn bottom_button_color(&self, button: BottomButton) -> Option<String>

Returns the current background color of the button.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.bottom_button_color(BottomButton::Main);
}
Source

pub fn bottom_button_has_shine_effect(&self, button: BottomButton) -> bool

Returns whether the shine effect is enabled on the button.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.bottom_button_has_shine_effect(BottomButton::Main);
}
Source

pub fn set_bottom_button_params( &self, button: BottomButton, params: &BottomButtonParams<'_>, ) -> Result<(), JsValue>

Update bottom button state via setParams.

§Examples
use telegram_webapp_sdk::webapp::{BottomButton, BottomButtonParams, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let params = BottomButtonParams {
        text: Some("Send"),
        ..Default::default()
    };
    let _ = app.set_bottom_button_params(BottomButton::Main, &params);
}
Source

pub fn set_secondary_button_params( &self, params: &SecondaryButtonParams<'_>, ) -> Result<(), JsValue>

Update secondary button state via setParams, including position.

§Examples
use telegram_webapp_sdk::webapp::{
    SecondaryButtonParams, SecondaryButtonPosition, TelegramWebApp
};

if let Some(app) = TelegramWebApp::instance() {
    let params = SecondaryButtonParams {
        position: Some(SecondaryButtonPosition::Left),
        ..Default::default()
    };
    let _ = app.set_secondary_button_params(&params);
}
Source

pub fn secondary_button_position(&self) -> Option<SecondaryButtonPosition>

Returns the configured position of the secondary button, if available.

§Examples
use telegram_webapp_sdk::webapp::{SecondaryButtonPosition, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.secondary_button_position();
}
Source

pub fn set_bottom_button_callback<F>( &self, button: BottomButton, callback: F, ) -> Result<EventHandle<dyn FnMut()>, JsValue>
where F: 'static + Fn(),

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.

Source

pub fn remove_bottom_button_callback( &self, handle: EventHandle<dyn FnMut()>, ) -> Result<(), JsValue>

Remove previously set bottom button callback.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn show_main_button(&self) -> Result<(), JsValue>

Source

pub fn show_secondary_button(&self) -> Result<(), JsValue>

Show the secondary bottom button.

Source

pub fn hide_main_button(&self) -> Result<(), JsValue>

Source

pub fn hide_secondary_button(&self) -> Result<(), JsValue>

Hide the secondary bottom button.

Source

pub fn set_main_button_text(&self, text: &str) -> Result<(), JsValue>

Source

pub fn set_secondary_button_text(&self, text: &str) -> Result<(), JsValue>

Set text for the secondary bottom button.

Source

pub fn set_main_button_color(&self, color: &str) -> Result<(), JsValue>

Source

pub fn set_secondary_button_color(&self, color: &str) -> Result<(), JsValue>

Set color for the secondary bottom button.

Source

pub fn set_main_button_text_color(&self, color: &str) -> Result<(), JsValue>

Source

pub fn set_secondary_button_text_color( &self, color: &str, ) -> Result<(), JsValue>

Set text color for the secondary bottom button.

Source

pub fn enable_main_button(&self) -> Result<(), JsValue>

Enable the main bottom button.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.enable_main_button();
}
Source

pub fn enable_secondary_button(&self) -> Result<(), JsValue>

Enable the secondary bottom button.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.enable_secondary_button();
}
Source

pub fn disable_main_button(&self) -> Result<(), JsValue>

Disable the main bottom button.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.disable_main_button();
}
Source

pub fn disable_secondary_button(&self) -> Result<(), JsValue>

Disable the secondary bottom button.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.disable_secondary_button();
}
Source

pub fn show_main_button_progress( &self, leave_active: bool, ) -> Result<(), JsValue>

Show progress on the main bottom button.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.show_main_button_progress(false);
}
Source

pub fn show_secondary_button_progress( &self, leave_active: bool, ) -> Result<(), JsValue>

Show progress on the secondary bottom button.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.show_secondary_button_progress(false);
}
Source

pub fn hide_main_button_progress(&self) -> Result<(), JsValue>

Hide progress indicator from the main bottom button.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.hide_main_button_progress();
}
Source

pub fn hide_secondary_button_progress(&self) -> Result<(), JsValue>

Hide progress indicator from the secondary bottom button.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.hide_secondary_button_progress();
}
Source

pub fn set_main_button_params( &self, params: &BottomButtonParams<'_>, ) -> Result<(), JsValue>

Update the main button state via set_bottom_button_params.

Source

pub fn set_main_button_callback<F>( &self, callback: F, ) -> Result<EventHandle<dyn FnMut()>, JsValue>
where F: 'static + Fn(),

Source

pub fn set_secondary_button_callback<F>( &self, callback: F, ) -> Result<EventHandle<dyn FnMut()>, JsValue>
where F: 'static + Fn(),

Set callback for the secondary bottom button.

Source

pub fn remove_main_button_callback( &self, handle: EventHandle<dyn FnMut()>, ) -> Result<(), JsValue>

Source

pub fn remove_secondary_button_callback( &self, handle: EventHandle<dyn FnMut()>, ) -> Result<(), JsValue>

Remove callback for the secondary bottom button.

Source

pub fn on_event<F>( &self, event: &str, callback: F, ) -> Result<EventHandle<dyn FnMut(JsValue)>, JsValue>
where F: 'static + Fn(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.

Source

pub fn on_background_event<F>( &self, event: BackgroundEvent, callback: F, ) -> Result<EventHandle<dyn FnMut(JsValue)>, JsValue>
where F: 'static + Fn(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.

Source

pub fn off_event<T: ?Sized>( &self, handle: EventHandle<T>, ) -> Result<(), JsValue>

Deregister a previously registered event handler.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn viewport_height(&self) -> Option<f64>

Returns the current viewport height in pixels.

§Examples
let _ = app.viewport_height();
Source

pub fn viewport_width(&self) -> Option<f64>

Returns the current viewport width in pixels.

§Examples
let _ = app.viewport_width();
Source

pub fn viewport_stable_height(&self) -> Option<f64>

Returns the stable viewport height in pixels.

§Examples
let _ = app.viewport_stable_height();
Source

pub fn is_expanded(&self) -> bool

Source

pub fn is_active(&self) -> bool

Returns whether the mini app is currently active (visible to the user).

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.is_active();
}
Source

pub fn is_fullscreen(&self) -> bool

Returns whether the app is displayed in fullscreen mode.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.is_fullscreen();
}
Source

pub fn is_orientation_locked(&self) -> bool

Returns whether the orientation is locked.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.is_orientation_locked();
}
Source

pub fn is_vertical_swipes_enabled(&self) -> bool

Returns whether vertical swipes are currently enabled.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.is_vertical_swipes_enabled();
}
Source

pub fn safe_area_inset(&self) -> Option<SafeAreaInset>

Returns the safe area insets reported by Telegram.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.safe_area_inset();
}
Source

pub fn content_safe_area_inset(&self) -> Option<SafeAreaInset>

Returns the content safe area insets reported by Telegram.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.content_safe_area_inset();
}
Source

pub fn expand_viewport(&self) -> Result<(), JsValue>

Call WebApp.expand() to expand the viewport.

§Errors

Returns JsValue if the underlying JS call fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn on_clipboard_text_received<F>( &self, callback: F, ) -> Result<EventHandle<dyn FnMut(JsValue)>, JsValue>
where F: 'static + Fn(String),

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.

Source

pub fn on_invoice_closed<F>( &self, callback: F, ) -> Result<EventHandle<dyn FnMut(String)>, JsValue>
where F: 'static + Fn(String),

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.

Source

pub fn set_back_button_callback<F>( &self, callback: F, ) -> Result<EventHandle<dyn FnMut()>, JsValue>
where F: 'static + Fn(),

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.

Source

pub fn remove_back_button_callback( &self, handle: EventHandle<dyn FnMut()>, ) -> Result<(), JsValue>

Remove previously set back button callback.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn is_back_button_visible(&self) -> bool

Returns whether the native back button is visible.

§Examples
let _ = app.is_back_button_visible();

Trait Implementations§

Source§

impl Clone for TelegramWebApp

Source§

fn clone(&self) -> TelegramWebApp

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.