Skip to main content

TelegramWebApp

Struct TelegramWebApp 

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

Safe wrapper around window.Telegram.WebApp

Implementations§

Source§

impl TelegramWebApp

Source

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

Call WebApp.MainButton.show() or WebApp.SecondaryButton.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 set_bottom_button_text( &self, button: BottomButton, text: &str, ) -> Result<(), JsValue>

Set bottom 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 set_bottom_button_icon_custom_emoji_id( &self, button: BottomButton, icon_id: &str, ) -> Result<(), JsValue>

Set custom emoji icon for a bottom button (Bot API 9.5+).

Sets the custom emoji ID to be displayed as an icon on the button. Use an empty string to remove the icon.

§Arguments
  • button - The button to update (Main or Secondary)
  • icon_id - The custom emoji ID (e.g., “123456789”)
§Errors

Returns JsValue if the underlying JS call fails.

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

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.set_bottom_button_icon_custom_emoji_id(BottomButton::Main, "123456789");
}
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_icon_custom_emoji_id( &self, button: BottomButton, ) -> Option<String>

Returns the current custom emoji icon ID of the button (Bot API 9.5+).

§Arguments
  • button - The button to query (Main or Secondary)
§Examples
use telegram_webapp_sdk::webapp::{BottomButton, TelegramWebApp};

if let Some(app) = TelegramWebApp::instance() {
    if let Some(icon_id) = app.bottom_button_icon_custom_emoji_id(BottomButton::Main) {
        println!("Icon ID: {}", icon_id);
    }
}
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_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_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();
Source

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

Show the native settings button.

§Errors

Returns JsValue if the underlying JS call fails.

Source

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

Hide the native settings button.

§Errors

Returns JsValue if the underlying JS call fails.

Source

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

Registers a callback for the native settings button.

Returns an EventHandle that can be passed to remove_settings_button_callback.

§Errors

Returns JsValue if the underlying JS call fails.

Source

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

Remove previously set settings button callback.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn is_settings_button_visible(&self) -> bool

Returns whether the native settings button is visible.

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn set_main_button_icon_custom_emoji_id( &self, icon_id: &str, ) -> Result<(), JsValue>

Set custom emoji icon for the main button (Bot API 9.5+).

Legacy alias for Self::set_bottom_button_icon_custom_emoji_id with BottomButton::Main.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.set_main_button_icon_custom_emoji_id("123456789");
}
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 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 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 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 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 remove_main_button_callback( &self, handle: EventHandle<dyn FnMut()>, ) -> Result<(), JsValue>

Remove callback for the main button.

Legacy alias for Self::remove_bottom_button_callback.

Source

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

Show the secondary bottom button.

Source

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

Hide the secondary bottom button.

Source

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

Set text for the secondary bottom button.

Source

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

Set color for the secondary bottom button.

Source

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

Set text color for the secondary bottom button.

Source

pub fn set_secondary_button_icon_custom_emoji_id( &self, icon_id: &str, ) -> Result<(), JsValue>

Set custom emoji icon for the secondary button (Bot API 9.5+).

Convenience alias for Self::set_bottom_button_icon_custom_emoji_id with BottomButton::Secondary.

§Examples
use telegram_webapp_sdk::webapp::TelegramWebApp;

if let Some(app) = TelegramWebApp::instance() {
    let _ = app.set_secondary_button_icon_custom_emoji_id("123456789");
}
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_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_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_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_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_secondary_button_callback( &self, handle: EventHandle<dyn FnMut()>, ) -> Result<(), JsValue>

Remove callback for the secondary bottom button.

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§

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 get_raw_init_data() -> Result<String, &'static str>

Returns the raw initData string as provided by Telegram.

This is the URL-encoded initData string captured during SDK initialization, suitable for server-side signature validation.

§Errors

Returns an error if the SDK has not been initialized via crate::core::init::init_sdk.

§Examples
use telegram_webapp_sdk::TelegramWebApp;

match TelegramWebApp::get_raw_init_data() {
    Ok(raw) => {
        // Send to backend for validation
        println!("Raw initData: {}", raw);
    }
    Err(e) => eprintln!("SDK not initialized: {}", e)
}
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 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 ready(&self) -> Result<(), JsValue>

Call WebApp.ready().

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub fn invoke_custom_method_with_callback<F>( &self, method: &str, params: &JsValue, callback: F, ) -> Result<(), JsValue>
where F: 'static + FnOnce(Result<JsValue, JsValue>),

Call WebApp.invokeCustomMethod(method, params, callback).

JS callback signature is (error, result). The Rust callback receives a Result<JsValue, JsValue>Ok(result) when JS passes null/undefined for error, Err(err) otherwise.

Prefer the async sibling Self::invoke_custom_method for new code.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub async fn invoke_custom_method( &self, method: &str, params: &JsValue, ) -> Result<JsValue, JsValue>

Async wrapper over WebApp.invokeCustomMethod.

Resolves with the JS result value when Telegram returns a successful response and rejects with the JS error value otherwise.

§Examples
let app = TelegramWebApp::try_instance()?;
let params = Object::new();
let result = app
    .invoke_custom_method("getRequestedContact", &params.into())
    .await?;
let _ = result;
§Errors

Returns JsValue if Telegram rejects the call or the underlying JS invocation fails.

Source§

impl TelegramWebApp

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_with_callback<F>( &self, msg: &str, on_confirm: F, ) -> Result<(), JsValue>
where F: 'static + FnOnce(bool),

Callback variant of Self::show_confirm.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub async fn show_confirm(&self, msg: &str) -> Result<bool, JsValue>

Async wrapper over WebApp.showConfirm. Resolves with the user’s boolean answer.

§Errors

Returns JsValue if the underlying JS call fails.

Source

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

Call WebApp.showPopup(params, callback).

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

Callback variant of Self::show_popup.

Source

pub async fn show_popup(&self, params: &JsValue) -> Result<String, JsValue>

Async wrapper over WebApp.showPopup. Resolves with the id of the button the user pressed, or an empty string if the popup was dismissed.

§Errors

Returns JsValue if the underlying JS call fails.

Source

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

Call WebApp.showScanQrPopup({ text }, callback).

The text is shown above the scanner viewport. Pass an empty string to open the scanner without a caption.

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

Callback variant of Self::show_scan_qr_popup.

Source

pub async fn show_scan_qr_popup(&self, text: &str) -> Result<String, JsValue>

Async wrapper over WebApp.showScanQrPopup. Resolves with the scanned text. Pass an empty text to open the scanner without a caption.

§Errors

Returns JsValue if the underlying JS call fails.

Source

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

Call WebApp.closeScanQrPopup().

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

impl TelegramWebApp

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 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§

impl TelegramWebApp

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 close_with_options(&self, options: &CloseOptions) -> Result<(), JsValue>

Call WebApp.close(options) (Bot API 7.6+ for return_back).

On older Telegram clients the option is silently ignored on the JS side.

§Examples
app.close_with_options(&CloseOptions {
    return_back: Some(true)
})
.unwrap();
§Errors

Returns JsValue if the underlying JS call fails or the options fail to serialize.

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 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 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 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 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 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 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_expanded(&self) -> bool

Source§

impl TelegramWebApp

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 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_with_callback<F>( &self, msg_id: &str, callback: F, ) -> Result<(), JsValue>
where F: 'static + FnOnce(bool),

Callback variant of Self::share_message.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub async fn share_message(&self, msg_id: &str) -> Result<bool, JsValue>

Async wrapper over WebApp.shareMessage. Resolves with true when the prepared message was sent.

§Examples
let app = TelegramWebApp::try_instance()?;
let sent: bool = app.share_message("id123").await?;
let _ = sent;
§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 request_chat_with_callback<F>( &self, req_id: i32, callback: F, ) -> Result<(), JsValue>
where F: 'static + FnOnce(bool),

Callback variant of Self::request_chat (Bot API 9.6+).

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub async fn request_chat(&self, req_id: i32) -> Result<bool, JsValue>

Async wrapper over WebApp.requestChat (Bot API 9.6+). Resolves with true when the user picks a chat, false on cancel/failure.

§Examples
let app = TelegramWebApp::try_instance()?;
let sent: bool = app.request_chat(42).await?;
let _ = sent;
§Errors

Returns JsValue if the underlying JS call fails (including when the running Telegram client predates Bot API 9.6).

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_with_callback<F>( &self, callback: F, ) -> Result<(), JsValue>
where F: 'static + FnOnce(String),

Callback variant of Self::check_home_screen_status.

Source

pub async fn check_home_screen_status(&self) -> Result<String, JsValue>

Async wrapper over WebApp.checkHomeScreenStatus. Resolves with the status string Telegram returns (e.g. "added", "missed").

§Errors

Returns JsValue if the underlying JS call fails.

Source§

impl TelegramWebApp

Source

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

Callback variant of Self::request_write_access.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub async fn request_write_access(&self) -> Result<bool, JsValue>

Async wrapper over WebApp.requestWriteAccess.

Resolves with true when the user grants permission to receive messages from the bot.

§Examples
let app = TelegramWebApp::try_instance()?;
let granted: bool = app.request_write_access().await?;
let _ = granted;
§Errors

Returns JsValue if the underlying JS call fails.

Source

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

Callback variant of Self::request_emoji_status_access.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub async fn request_emoji_status_access(&self) -> Result<bool, JsValue>

Async wrapper over WebApp.requestEmojiStatusAccess.

§Errors

Returns JsValue if the underlying JS call fails.

Source

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

Callback variant of Self::set_emoji_status.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub async fn set_emoji_status(&self, status: &JsValue) -> Result<bool, JsValue>

Async wrapper over WebApp.setEmojiStatus.

§Errors

Returns JsValue if the underlying JS call fails.

Source

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

Callback variant of Self::open_invoice.

Source

pub async fn open_invoice(&self, url: &str) -> Result<String, JsValue>

Async wrapper over WebApp.openInvoice. Resolves with the invoice status string (paid, cancelled, failed, pending).

§Errors

Returns JsValue if the underlying JS call fails.

Source

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

Callback variant of Self::download_file.

§Errors

Returns JsValue if the underlying JS call fails or the parameters fail to serialize.

Source

pub async fn download_file( &self, params: DownloadFileParams<'_>, ) -> Result<String, JsValue>

Async wrapper over WebApp.downloadFile. Resolves with the file id string that Telegram returns.

§Errors

Returns JsValue if the underlying JS call fails or the parameters fail to serialize.

Source

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

Callback variant of Self::read_text_from_clipboard.

§Errors

Returns JsValue if the underlying JS call fails.

Source

pub async fn read_text_from_clipboard(&self) -> Result<String, JsValue>

Async wrapper over WebApp.readTextFromClipboard.

§Errors

Returns JsValue if the underlying JS call fails.

Source§

impl TelegramWebApp

Source

pub fn color_scheme(&self) -> Option<String>

Returns WebApp.colorScheme"light" or "dark".

Source

pub fn header_color(&self) -> Option<String>

Returns the current WebApp.headerColor value.

Source

pub fn background_color(&self) -> Option<String>

Returns the current WebApp.backgroundColor value.

Source

pub fn bottom_bar_color(&self) -> Option<String>

Returns the current WebApp.bottomBarColor value (Bot API 7.10+).

Source

pub fn raw_version(&self) -> Option<String>

Returns the raw WebApp.version string (e.g. "9.6").

Source

pub fn platform(&self) -> Option<String>

Returns the WebApp.platform string (e.g. "tdesktop", "ios", "web").

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§

impl TelegramWebApp

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 expand_viewport(&self) -> Result<(), JsValue>

Call WebApp.expand() to expand the viewport.

§Errors

Returns JsValue if the underlying JS call fails.

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

Trait Implementations§

Source§

impl Clone for TelegramWebApp

Source§

fn clone(&self) -> TelegramWebApp

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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> 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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more