### DeviceOrientation.start Source: https://core.telegram.org/bots/webapps Starts tracking device orientation data. It accepts an optional parameters object and a callback function. ```APIDOC ## DeviceOrientation.start ### Description Starts tracking device orientation data using the provided parameters. An optional callback function can be supplied to handle the result of the operation. ### Method Function ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **params** (DeviceOrientationStartParams) - Required - An object containing parameters for starting orientation tracking. - **callback** (Function) - Optional - A function to be called with a boolean indicating success or failure. ### Request Example ```javascript DeviceOrientation.start({ refresh_rate: 100, need_absolute: true }, (success) => { console.log('Orientation tracking started:', success); }); ``` ### Response #### Success Response Returns the DeviceOrientation object for chaining. #### Response Example ```json { "isStarted": true, "absolute": true, "alpha": 0.5, "beta": 1.2, "gamma": -0.1 } ``` ``` -------------------------------- ### Gyroscope.start Source: https://core.telegram.org/bots/webapps Starts tracking gyroscope data. It accepts an optional parameters object and a callback function. ```APIDOC ## Gyroscope.start ### Description Starts tracking gyroscope data using the provided parameters. An optional callback function can be supplied to handle the result of the operation. ### Method Function ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **params** (GyroscopeStartParams) - Required - An object containing parameters for starting gyroscope tracking. - **callback** (Function) - Optional - A function to be called with a boolean indicating success or failure. ### Request Example ```javascript Gyroscope.start({ refresh_rate: 50 }, (success) => { console.log('Gyroscope tracking started:', success); }); ``` ### Response #### Success Response Returns the Gyroscope object for chaining. #### Response Example ```json { "isStarted": true, "x": 0.1, "y": -0.05, "z": 0.02 } ``` ``` -------------------------------- ### Example Android User-Agent String Source: https://core.telegram.org/bots/webapps An example of the User-Agent string provided by Telegram for Android Mini Apps, including specific version and device details. ```plaintext Mozilla/5.0 (Linux; Android 14; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672.136 Mobile Safari/537.36 Telegram-Android/11.3.3 (Google sdk_gphone64_arm64; Android 14; SDK 34; LOW) ``` -------------------------------- ### addToHomeScreen() Source: https://core.telegram.org/bots/webapps Bot API 8.0+ A method that prompts the user to add the Mini App to the home screen. After successfully adding the icon, the `homeScreenAdded` event will be triggered if supported by the device. Note that if the device cannot determine the installation status, the event may not be received even if the icon has been added. ```APIDOC ## addToHomeScreen() ### Description Prompts the user to add the Mini App to their device's home screen. Triggers `homeScreenAdded` event upon success if supported. ### Method POST ### Endpoint `/addToHomeScreen` ### Response #### Success Response (200) - **status** (string) - Indicates success. ### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### AccelerometerStartParams Source: https://core.telegram.org/bots/webapps Defines the parameters for starting accelerometer tracking. ```APIDOC ## AccelerometerStartParams This object defines the parameters for starting accelerometer tracking. ### Fields - **refresh_rate** (Integer): _Optional._ The refresh rate in milliseconds, with acceptable values ranging from 20 to 1000. Set to `_1000_` by default. Note that `_refresh_rate_` may not be supported on all platforms, so the actual tracking frequency may differ from the specified value. ``` -------------------------------- ### fileDownloadRequested Source: https://core.telegram.org/bots/webapps This event is triggered when the user responds to a file download request initiated by the Mini App. The event handler receives a 'status' field indicating whether the download started or was cancelled. ```APIDOC ## fileDownloadRequested ### Description Occurs when the user responds to the file download request. ### Event `fileDownloadRequested` ### Parameters _eventHandler_ receives an object with the single field _status_ containing one of the statuses: - **downloading** – the file download has started, - **cancelled** – user declined this request. ``` -------------------------------- ### Handle Activation Event in Mini Apps Source: https://core.telegram.org/bots/webapps The `activated` event (Bot API 8.0+) fires when the Mini App becomes active, for example, when opened from a minimized state or selected from tabs. The handler receives no parameters. ```javascript Telegram.WebApp.onEvent('activated', () => { console.log('Mini App activated!'); }); ``` -------------------------------- ### __WebAppInitData Source: https://core.telegram.org/bots/webapps Contains data transferred to the Mini App when it is opened. This object is empty if the Mini App was launched from a keyboard button or inline mode. ```APIDOC ## __WebAppInitData ### Description This object contains data that is transferred to the Mini App when it is opened. It is empty if the Mini App was launched from a keyboard button or from inline mode. ### Fields - **query_id** (String) - Optional. A unique identifier for the Mini App session, required for sending messages via the `answerWebAppQuery` method. - **user** (WebAppUser) - Optional. An object containing data about the current user. - **receiver** (WebAppUser) - Optional. An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu. Returned only for private chats and only for Mini Apps launched via the attachment menu. - **chat** (WebAppChat) - Optional. An object containing data about the chat where the bot was launched via the attachment menu. Returned for supergroups, channels and group chats – only for Mini Apps launched via the attachment menu. - **chat_type** (String) - Optional. Type of the chat from which the Mini App was opened. Can be either “sender” for a private chat with the user opening the link, “private”, “group”, “supergroup”, or “channel”. Returned only for Mini Apps launched from direct links. - **chat_instance** (String) - Optional. Global identifier, uniquely corresponding to the chat from which the Mini App was opened. Returned only for Mini Apps launched from a direct link. - **start_param** (String) - Optional. The value of the _startattach_ parameter, passed via link. Only returned for Mini Apps when launched from the attachment menu via link. The value of the `start_param` parameter will also be passed in the GET-parameter `tgWebAppStartParam`, so the Mini App can load the correct interface right away. - **can_send_after** (Integer) - Optional. Time in seconds, after which a message can be sent via the `answerWebAppQuery` method. - **auth_date** (Integer) - Unix time when the form was opened. - **hash** (String) - A hash of all passed parameters, which the bot server can use to check their validity. - **signature** (String) - A signature of all passed parameters (except _hash_), which the third party can use to check their validity. ``` -------------------------------- ### Telegram Web App SDK Initialization and Properties Source: https://core.telegram.org/bots/webapps Connect the SDK by including the script in your HTML head. The `window.Telegram.WebApp` object provides access to various properties reflecting the Telegram client's state and user environment. ```APIDOC ## Initialize Telegram Web App SDK ### Description Include the Telegram Web App SDK script in the `` of your HTML document before any other scripts to initialize the `window.Telegram.WebApp` object. ### Script Tag ```html ``` ### Available Properties #### `window.Telegram.WebApp` Object Properties - **initData** (String) - Raw data transferred to the Mini App, used for data validation. **WARNING:** Validate this data on your bot's server before use. - **initDataUnsafe** (WebAppInitData) - An object containing input data transferred to the Mini App. **WARNING:** Do not trust data from this field; always validate `initData` on the server. - **version** (String) - The version of the Bot API available in the user's Telegram app. - **platform** (String) - The name of the platform of the user's Telegram app. - **colorScheme** (String) - The current color scheme ('light' or 'dark') used in the Telegram app. Also available as CSS variable `--tg-color-scheme`. - **themeParams** (ThemeParams) - An object containing the current theme settings. - **isActive** (Boolean) - (Bot API 8.0+) `true` if the Mini App is active, `false` if minimized. - **isExpanded** (Boolean) - `true` if the Mini App is expanded to maximum height, `false` otherwise. Can be expanded using the `expand()` method. - **viewportHeight** (Float) - The current height of the visible Mini App area. Also available as CSS variable `--tg-viewport-height`. This value updates in real-time but is not suitable for smooth animations. - **viewportStableHeight** (Float) - The height of the visible Mini App area in its last stable state. Also available as CSS variable `--tg-viewport-stable-height`. Updates after gestures and animations complete. Use the `viewportChanged` event with `isStateStable=true` to track changes. - **headerColor** (String) - Current header color in `#RRGGBB` format. - **backgroundColor** (String) - Current background color in `#RRGGBB` format. - **bottomBarColor** (String) - Current bottom bar color in `#RRGGBB` format. - **isClosingConfirmationEnabled** (Boolean) - `true` if the confirmation dialog is enabled when closing the Mini App, `false` otherwise. - **isVerticalSwipesEnabled** (Boolean) - `true` if vertical swipes to close/minimize are enabled, `false` otherwise. Swiping the header always works. - **isFullscreen** (Boolean) - `true` if the Mini App is currently displayed in fullscreen mode. - **isOrientationLocked** (Boolean) - `true` if the Mini App’s orientation is locked, `false` otherwise. - **safeAreaInset** (SafeAreaInset) - An object representing the device's safe area insets. - **contentSafeAreaInset** (ContentSafeAreaInset) - An object representing the safe area for content, avoiding overlap with Telegram UI. - **BackButton** (BackButton) - An object for controlling the back button in the Mini App header. ``` -------------------------------- ### checkHomeScreenStatus([callback]) Source: https://core.telegram.org/bots/webapps Bot API 8.0+ A method that checks if adding to the home screen is supported and if the Mini App has already been added. If an optional _callback_ parameter is provided, the _callback_ function will be called with a single argument _status_ , which is a string indicating the home screen status. Possible values for _status_ are: unsupported – the feature is not supported, and it is not possible to add the icon to the home screen, ```APIDOC ## checkHomeScreenStatus([callback]) ### Description Checks if adding the Mini App to the home screen is supported and if it has already been added. Optionally accepts a callback function to receive the status. ### Method GET ### Endpoint `/checkHomeScreenStatus` ### Parameters #### Query Parameters - **callback** (function) - Optional - A function to be called with the status string ('supported', 'added', 'unsupported'). ### Response #### Success Response (200) - **status** (string) - The home screen status: 'supported', 'added', or 'unsupported'. ### Response Example ```json { "status": "added" } ``` ``` -------------------------------- ### requestFullscreen() Source: https://core.telegram.org/bots/webapps Bot API 8.0+ A method that requests opening the Mini App in fullscreen mode. Although the header is transparent in fullscreen mode, it is recommended that the Mini App sets the header color using the _setHeaderColor_ method. This color helps determine a contrasting color for the status bar and other UI controls. ```APIDOC ## requestFullscreen() ### Description Requests that the Mini App open in fullscreen mode. It's recommended to set the header color when using this feature. ### Method POST ### Endpoint `/requestFullscreen` ### Response #### Success Response (200) - **status** (string) - Indicates success. ### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### ready Source: https://core.telegram.org/bots/webapps Informs the Telegram app that the Mini App is ready to be displayed, hiding the loading placeholder. ```APIDOC ## ready ### Description A method that informs the Telegram app that the Mini App is ready to be displayed. It is recommended to call this method as early as possible, as soon as all essential interface elements are loaded. Once this method is called, the loading placeholder is hidden and the Mini App is shown. If the method is not called, the placeholder will be hidden only when the page is fully loaded. ### Method Function ### Endpoint Not applicable (Client-side function) ### Parameters None ### Request Example ```javascript Telegram.WebApp.ready(); ``` ### Response None ``` -------------------------------- ### expand Source: https://core.telegram.org/bots/webapps Expands the Mini App to its maximum available height. ```APIDOC ## expand ### Description A method that expands the Mini App to the maximum available height. To find out if the Mini App is expanded to the maximum height, refer to the value of the _Telegram.WebApp.isExpanded_ parameter. ### Method Function ### Endpoint Not applicable (Client-side function) ### Parameters None ### Request Example ```javascript Telegram.WebApp.expand(); ``` ### Response None ``` -------------------------------- ### showScanQrPopup Source: https://core.telegram.org/bots/webapps Opens a native QR code scanner popup. Receives scanned data via events or callbacks. Available from Bot API 6.4+. ```APIDOC ## showScanQrPopup ### Description A method that shows a native popup for scanning a QR code described by the _params_ argument of the type ScanQrPopupParams. The Mini App will receive the event _qrTextReceived_ every time the scanner catches a code with text data. If an optional _callback_ parameter was passed, the _callback_ function will be called and the text from the QR code will be passed as the first argument. Returning _true_ inside this callback function causes the popup to be closed. Starting from Bot API 7.7, the Mini App will receive the _scanQrPopupClosed_ event if the user closes the native popup for scanning a QR code. ### Method Function ### Endpoint Not applicable (Client-side function) ### Parameters - **params** (ScanQrPopupParams) - Required - Parameters describing the QR scanner popup. - **callback** (Function) - Optional - A function to be called with the scanned QR code text. Returning true closes the popup. ### Request Example ```javascript Telegram.WebApp.showScanQrPopup({ neededResultTypes: ['text'] }, (scannedText) => { console.log("Scanned text: " + scannedText); return true; // Close the popup after receiving text }); ``` ### Response None ``` -------------------------------- ### Add Bot to Attachment Menu Link Source: https://core.telegram.org/bots/webapps Use this link format to allow users to add your bot to their attachment menu. The optional 'startattach' parameter can pass a command to the Mini App. ```plaintext https://t.me/botusername?startattach ``` ```plaintext https://t.me/botusername?startattach=command ``` -------------------------------- ### Add Bot to Attachment Menu via User Chat Link Source: https://core.telegram.org/bots/webapps These links open a Mini App in the attachment menu within a chat with a specific user. The 'startattach' parameter is passed to the Mini App. ```plaintext https://t.me/username?attach=botusername ``` ```plaintext https://t.me/username?attach=botusername&startattach=command ``` ```plaintext https://t.me/+1234567890?attach=botusername ``` ```plaintext https://t.me/+1234567890?attach=botusername&startattach=command ``` -------------------------------- ### showConfirm Source: https://core.telegram.org/bots/webapps Displays a confirmation window with 'OK' and 'Cancel' buttons. Supports callbacks. Available from Bot API 6.2+. ```APIDOC ## showConfirm ### Description A method that shows _message_ in a simple confirmation window with 'OK' and 'Cancel' buttons. If an optional _callback_ parameter was passed, the _callback_ function will be called when the popup is closed and the first argument will be a boolean indicating whether the user pressed the 'OK' button. ### Method Function ### Endpoint Not applicable (Client-side function) ### Parameters - **message** (string) - Required - The message to display in the confirmation window. - **callback** (Function) - Optional - A function to be called when the popup is closed. Receives a boolean indicating if 'OK' was pressed. ### Request Example ```javascript Telegram.WebApp.showConfirm("Are you sure you want to proceed?", (okPressed) => { if (okPressed) { console.log("User pressed OK."); } else { console.log("User pressed Cancel."); } }); ``` ### Response None ``` -------------------------------- ### File Download Source: https://core.telegram.org/bots/webapps Function for initiating a file download via a native popup. ```APIDOC ## downloadFile(params[, callback]) ### Description Bot API 8.0+ NEW A method that displays a native popup prompting the user to download a file specified by the _params_ argument of type DownloadFileParams. If an optional _callback_ parameter is provided, the _callback_ function will be called when the popup is closed, with the first argument as a boolean indicating whether the user accepted the download request. ### Method Function ### Parameters - **params** (object) - Required - An object of type `DownloadFileParams` specifying the file to download. - **callback** (function) - Optional - A callback function that receives a boolean indicating if the user accepted the download. ``` -------------------------------- ### isVersionAtLeast(version) Source: https://core.telegram.org/bots/webapps Returns true if the user's app supports a version of the Bot API that is equal to or higher than the version passed as the parameter. ```APIDOC ## isVersionAtLeast(version) ### Description Checks if the current Bot API version is at least the specified version. ### Parameters #### Path Parameters - **version** (string) - Required - The version string to compare against (e.g., "6.1"). ### Returns - **boolean** - True if the Bot API version is sufficient, false otherwise. ### Usage ```javascript Telegram.WebApp.isVersionAtLeast('6.1') ``` ``` -------------------------------- ### Add Bot to Attachment Menu with Chat Type Selection Source: https://core.telegram.org/bots/webapps This link format allows users to select a specific chat type (users, bots, groups, channels) to open the attachment menu in. The 'startattach' parameter is passed to the Mini App. ```plaintext https://t.me/botusername?startattach&choose=users+bots ``` ```plaintext https://t.me/botusername?startattach=command&choose=groups+channels ``` -------------------------------- ### __WebAppUser Source: https://core.telegram.org/bots/webapps This object contains the data of the Mini App user. ```APIDOC ## __WebAppUser ### Description This object contains the data of the Mini App user. ### Fields - **id** (Integer) - A unique identifier for the user or bot. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. It has at most 52 significant bits, so a 64-bit integer or a double-precision float type is safe for storing this identifier. - **is_bot** (Boolean) - Optional. True, if this user is a bot. Returns in the receiver field only. - **first_name** (String) - First name of the user or bot. - **last_name** (String) - Optional. Last name of the user or bot. - **username** (String) - Optional. Username of the user or bot. - **language_code** (String) - Optional. IETF language tag of the user's language. Returns in _user_ field only. - **is_premium** (True) - Optional. True, if this user is a Telegram Premium user. - **added_to_attachment_menu** (True) - Optional. True, if this user added the bot to the attachment menu. - **allows_write_to_pm** (True) - Optional. True, if this user allowed the bot to message them. - **photo_url** (String) - Optional. URL of the user’s profile photo. The photo can be in .jpeg or .svg formats. ``` -------------------------------- ### showPopup Source: https://core.telegram.org/bots/webapps Displays a native popup with customizable parameters. Supports callbacks for user interaction. Available from Bot API 6.2+. ```APIDOC ## showPopup ### Description A method that shows a native popup described by the _params_ argument of the type PopupParams. The Mini App will receive the event _popupClosed_ when the popup is closed. If an optional _callback_ parameter was passed, the _callback_ function will be called and the field _id_ of the pressed button will be passed as the first argument. ### Method Function ### Endpoint Not applicable (Client-side function) ### Parameters - **params** (PopupParams) - Required - Parameters describing the popup. - **callback** (Function) - Optional - A function to be called when the popup is closed. ### Request Example ```javascript Telegram.WebApp.showPopup({ title: "Popup Title", message: "Popup message", buttons: [{ id: "ok", type: "default", text: "OK" }] }, (buttonId) => { console.log("Button clicked: " + buttonId); }); ``` ### Response None ``` -------------------------------- ### ScanQrPopupParams Source: https://core.telegram.org/bots/webapps Describes the native popup for scanning QR codes, including optional text to be displayed. ```APIDOC ## ScanQrPopupParams ### Description This object describes the native popup for scanning QR codes. ### Fields - **text** (String) - Optional - The text to be displayed under the 'Scan QR' heading, 0-64 characters. ``` -------------------------------- ### CloudStorage Methods Source: https://core.telegram.org/bots/webapps Manages cloud storage for bots, allowing storage of up to 1024 items per user. These methods can be chained. ```APIDOC ## CloudStorage This object controls the cloud storage. Each bot can store up to 1024 items per user in the cloud storage. ### Methods #### setItem(key, value[, callback]) Bot API 6.9+ Stores a value in the cloud storage using the specified key. **Parameters:** - **key** (string) - Required - 1-128 characters. Allowed characters: `A-Z`, `a-z`, `0-9`, `_`, `-`. - **value** (string) - Required - 0-4096 characters. - **callback** (function) - Optional - Called after the operation. Receives error as the first argument, or null and a boolean indicating success as the second. #### getItem(key, callback) Bot API 6.9+ Retrieves a value from the cloud storage using the specified key. **Parameters:** - **key** (string) - Required - 1-128 characters. Allowed characters: `A-Z`, `a-z`, `0-9`, `_`, `-`. - **callback** (function) - Required - Called after the operation. Receives error as the first argument, or null and the value as the second. #### getItems(keys, callback) Bot API 6.9+ Retrieves values from the cloud storage using the specified keys. **Parameters:** - **keys** (array of strings) - Required - Array of keys. Each key should be 1-128 characters. Allowed characters: `A-Z`, `a-z`, `0-9`, `_`, `-`. - **callback** (function) - Required - Called after the operation. Receives error as the first argument, or null and the values as the second. #### removeItem(key[, callback]) Bot API 6.9+ Removes a value from the cloud storage using the specified key. **Parameters:** - **key** (string) - Required - 1-128 characters. Allowed characters: `A-Z`, `a-z`, `0-9`, `_`, `-`. - **callback** (function) - Optional - Called after the operation. Receives error as the first argument, or null and a boolean indicating success. #### removeItems(keys[, callback]) Bot API 6.9+ Removes values from the cloud storage using the specified keys. **Parameters:** - **keys** (array of strings) - Required - Array of keys. Each key should be 1-128 characters. Allowed characters: `A-Z`, `a-z`, `0-9`, `_`, `-`. - **callback** (function) - Optional - Called after the operation. Receives error as the first argument, or null and a boolean indicating success. #### getKeys(callback) Bot API 6.9+ Retrieves the list of all keys stored in the cloud storage. **Parameters:** - **callback** (function) - Required - Called after the operation. Receives error as the first argument, or null and the list of keys as the second. All these methods return the CloudStorage object, so they can be chained. ``` -------------------------------- ### Handle Settings Button Press in Mini Apps Source: https://core.telegram.org/bots/webapps Listen for the `settingsButtonClicked` event to handle presses of the Settings item in the context menu, available from Bot API 6.1 onwards. ```javascript Telegram.WebApp.onEvent('settingsButtonClicked', () => { console.log('Settings button clicked!'); }); ``` -------------------------------- ### close Source: https://core.telegram.org/bots/webapps Closes the Mini App. ```APIDOC ## close ### Description A method that closes the Mini App. ### Method Function ### Endpoint Not applicable (Client-side function) ### Parameters None ### Request Example ```javascript Telegram.WebApp.close(); ``` ### Response None ``` -------------------------------- ### SettingsButton Source: https://core.telegram.org/bots/webapps Controls the 'Settings' item in the context menu of the Mini App. Allows making the item visible or hidden and handling click events. ```APIDOC ## SettingsButton ### Description This object controls the **Settings** item in the context menu of the Mini App in the Telegram interface. ### Properties - **isVisible** (Boolean) - Shows whether the context menu item is visible. Set to _false_ by default. ### Methods - **onClick(callback)** - Bot API 7.0+ A method that sets the press event handler for the Settings item in the context menu. An alias for `Telegram.WebApp.onEvent('settingsButtonClicked', callback)`. - **offClick(callback)** - Bot API 7.0+ A method that removes the press event handler from the Settings item in the context menu. An alias for `Telegram.WebApp.offEvent('settingsButtonClicked', callback)`. - **show()** - Bot API 7.0+ A method to make the Settings item in the context menu visible. - **hide()** - Bot API 7.0+ A method to hide the Settings item in the context menu. All these methods return the SettingsButton object so they can be chained. ``` -------------------------------- ### getItem Source: https://core.telegram.org/bots/webapps Retrieves a value from the device's secure storage using the specified key. Requires a callback function for handling the result. ```APIDOC ## getItem(key, callback) ### Description Retrieves a value from the device's secure storage using the specified key. The callback function will be invoked with the result. ### Parameters #### Path Parameters - **key** (string) - Required - The key of the value to retrieve. - **callback** (function) - Required - The callback function to handle the result. ### Callback Response - **error** (Error) - If an error occurs, this argument will contain the error. - **value** (any) - If successful, this argument will contain the retrieved value. If the key is not found, this will be null. - **restorable** (boolean) - Indicates whether the key can be restored from the current device (only relevant if the key was not found). ``` -------------------------------- ### restoreItem Source: https://core.telegram.org/bots/webapps Attempts to restore a previously stored key from the device's secure storage, prompting the user for permission. Supports an optional callback. ```APIDOC ## restoreItem(key[, callback]) ### Description Attempts to restore a key that previously existed on the current device. The user will be prompted for permission. ### Parameters #### Path Parameters - **key** (string) - Required - The key to restore. - **callback** (function) - Optional - A callback function to be called after the operation. ### Callback Response - **error** (Error) - If an error occurs or the user declines, this argument will contain the error. - **value** (any) - If restored successfully, this argument will contain the restored value. ``` -------------------------------- ### ThemeParams Source: https://core.telegram.org/bots/webapps Provides access to the user's current theme settings, allowing Mini Apps to adjust their appearance in real-time to match the Telegram user's app. ```APIDOC ## ThemeParams ### Description Mini Apps can adjust the appearance of the interface to match the Telegram user's app in real time. This object contains the user's current theme settings. ### Fields - **bg_color** (String) - Optional - Background color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-bg-color)`. - **text_color** (String) - Optional - Main text color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-text-color)`. - **hint_color** (String) - Optional - Hint text color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-hint-color)`. - **link_color** (String) - Optional - Link color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-link-color)`. - **button_color** (String) - Optional - Button color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-button-color)`. - **button_text_color** (String) - Optional - Button text color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-button-text-color)`. - **secondary_bg_color** (String) - Optional - Bot API 6.1+ Secondary background color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-secondary-bg-color)`. - **header_bg_color** (String) - Optional - Bot API 7.0+ Header background color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-header-bg-color)`. - **bottom_bar_bg_color** (String) - Optional - Bot API 7.10+ Bottom background color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-bottom-bar-bg-color)`. - **accent_text_color** (String) - Optional - Bot API 7.0+ Accent text color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-accent-text-color)`. - **section_bg_color** (String) - Optional - Bot API 7.0+ Background color for the section in the `#RRGGBB` format. It is recommended to use this in conjunction with _secondary_bg_color_. Also available as the CSS variable `var(--tg-theme-section-bg-color)`. - **section_header_text_color** (String) - Optional - Bot API 7.0+ Header text color for the section in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-section-header-text-color)`. - **section_separator_color** (String) - Optional - Bot API 7.6+ Section separator color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-section-separator-color)`. - **subtitle_text_color** (String) - Optional - Bot API 7.0+ Subtitle text color in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-subtitle-text-color)`. - **destructive_text_color** (String) - Optional - Bot API 7.0+ Text color for destructive actions in the `#RRGGBB` format. Also available as the CSS variable `var(--tg-theme-destructive-text-color)`. ``` -------------------------------- ### __DownloadFileParams Source: https://core.telegram.org/bots/webapps Describes the parameters for the file download request, including URL and suggested file name. ```APIDOC ## __DownloadFileParams ### Description This object describes the parameters for the file download request. > **Note:** To ensure consistent file download behavior across platforms, include the HTTP headers `Content-Disposition: attachment; filename=""` and `Access-Control-Allow-Origin: https://web.telegram.org` in the server response. Without these headers, the download may not work as expected, especially on web platforms. ### Fields - **url** (String) - The HTTPS URL of the file to be downloaded. - **file_name** (String) - The suggested name for the downloaded file. ``` -------------------------------- ### __DeviceStorage Source: https://core.telegram.org/bots/webapps Provides access to persistent local storage on the user’s device. ```APIDOC ## __DeviceStorage ### Description This object provides access to persistent local storage on the user’s device. It is conceptually similar to the browser's `localStorage` API, but integrated within the Telegram client. All data is stored locally and is available only to the bot that created it. Each bot can store up to **5 MB per user** using this storage. ### Methods #### setItem(key, value[, callback]) Bot API 9.0+ A method that stores a value in the device's local storage using the specified key. If an optional _callback_ parameter was passed, the _callback_ function will be called. In case of an error, the first argument will contain the error. In case of success, the first argument will be _null_ and the second argument will be a boolean indicating whether the value was stored. #### getItem(key, callback) Bot API 9.0+ A method that receives a value from the device's local storage using the specified key. In case of an error, the _callback_ function will be called and the first argument will contain the error. In case of success, the first argument will be _null_ and the value will be passed as the second argument. #### removeItem(key[, callback]) Bot API 9.0+ A method that removes a value from the device's local storage using the specified key. If an optional _callback_ parameter was passed, the _callback_ function will be called. In case of an error, the first argument will contain the error. In case of success, the first argument will be _null_ and the second argument will be a boolean indicating whether the value was removed. #### clear([callback]) Bot API 9.0+ A method that clears all keys previously stored by the bot in the device's local storage. If an optional _callback_ parameter was passed, the _callback_ function will be called. In case of an error, the first argument will contain the error. In case of success, the first argument will be _null_ and the second argument will be a boolean indicating whether all values were removed. All these methods return the DeviceStorage object, so they can be chained. ``` -------------------------------- ### SettingsButton Source: https://core.telegram.org/bots/webapps An object for controlling the Settings item in the context menu of the Mini App in the Telegram interface. ```APIDOC ## SettingsButton ### Description Controls the Settings item in the Mini App's context menu. ### Usage ```javascript Telegram.WebApp.SettingsButton ``` ``` -------------------------------- ### exitFullscreen() Source: https://core.telegram.org/bots/webapps Bot API 8.0+ A method that requests exiting fullscreen mode. ```APIDOC ## exitFullscreen() ### Description Requests to exit the fullscreen mode of the Mini App. ### Method POST ### Endpoint `/exitFullscreen` ### Response #### Success Response (200) - **status** (string) - Indicates success. ### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### Accelerometer Methods Source: https://core.telegram.org/bots/webapps Provides access to accelerometer data on the device. ```APIDOC ## Accelerometer This object provides access to accelerometer data on the device. ### Fields - **isStarted** (Boolean): Indicates whether accelerometer tracking is currently active. - **x** (Float): The current acceleration in the X-axis, measured in m/s². - **y** (Float): The current acceleration in the Y-axis, measured in m/s². - **z** (Float): The current acceleration in the Z-axis, measured in m/s². ### Methods #### start(params[, callback]) Bot API 8.0+ Starts tracking accelerometer data using `_params_` of type `AccelerometerStartParams`. If an optional `_callback_` parameter is provided, the `_callback_` function will be called with a boolean indicating whether tracking was successfully started. #### stop([callback]) Bot API 8.0+ Stops tracking accelerometer data. If an optional `_callback_` parameter is provided, the `_callback_` function will be called with a boolean indicating whether tracking was successfully stopped. All these methods return the `Accelerometer` object so they can be chained. ``` -------------------------------- ### BiometricManager Methods Source: https://core.telegram.org/bots/webapps Controls biometrics on the device. Must be initialized before first use. ```APIDOC ## BiometricManager This object controls biometrics on the device. Before the first use of this object, it needs to be initialized using the `_init_` method. ### Fields - **isInited** (Boolean): Shows whether biometrics object is initialized. - **isBiometricAvailable** (Boolean): Shows whether biometrics is available on the current device. - **biometricType** (String): The type of biometrics currently available on the device. Can be one of these values: `_finger_`, `_face_`, `_unknown_`. - **isAccessRequested** (Boolean): Shows whether permission to use biometrics has been requested. - **isAccessGranted** (Boolean): Shows whether permission to use biometrics has been granted. - **isBiometricTokenSaved** (Boolean): Shows whether the token is saved in secure storage on the device. - **deviceId** (String): A unique device identifier that can be used to match the token to the device. ### Methods #### init([callback]) Bot API 7.2+ A method that initializes the BiometricManager object. It should be called before the object's first use. If an optional `_callback_` parameter was passed, the `_callback_` function will be called when the object is initialized. #### requestAccess(params[, callback]) Bot API 7.2+ A method that requests permission to use biometrics according to the `_params_` argument of type `BiometricRequestAccessParams`. If an optional `_callback_` parameter was passed, the `_callback_` function will be called and the first argument will be a boolean indicating whether the user granted access. #### authenticate(params[, callback]) Bot API 7.2+ A method that authenticates the user using biometrics according to the `_params_` argument of type `BiometricAuthenticateParams`. If an optional `_callback_` parameter was passed, the `_callback_` function will be called and the first argument will be a boolean indicating whether the user authenticated successfully. If so, the second argument will be a biometric token. #### updateBiometricToken(token, [callback]) Bot API 7.2+ A method that updates the biometric token in secure storage on the device. To remove the token, pass an empty string. If an optional `_callback_` parameter was passed, the `_callback_` function will be called and the first argument will be a boolean indicating whether the token was updated. #### openSettings() Bot API 7.2+ A method that opens the biometric access settings for bots. Useful when you need to request biometrics access to users who haven't granted it yet. _Note that this method can be called only in response to user interaction with the Mini App interface (e.g. a click inside the Mini App or on the main button)_ All these methods return the `BiometricManager` object so they can be chained. ``` -------------------------------- ### __LocationManager Source: https://core.telegram.org/bots/webapps Controls location access on the device. Must be initialized before use. ```APIDOC ## __LocationManager ### Description This object controls location access on the device. Before the first use of this object, it needs to be initialized using the _init_ method. ### Methods #### init([callback]) Bot API 8.0+ A method that initializes the LocationManager object. It should be called before the object's first use. If an optional _callback_ parameter is provided, the _callback_ function will be called when the object is initialized. #### getLocation(callback) Bot API 8.0+ A method that requests location data. The _callback_ function will be called with _null_ as the first argument if access to location was not granted, or an object of type LocationData as the first argument if access was successful. #### openSettings() Bot API 8.0+ A method that opens the location access settings for bots. Useful when you need to request location access from users who haven't granted it yet. _Note that this method can be called only in response to user interaction with the Mini App interface (e.g., a click inside the Mini App or on the main button)._ ### Fields - **isInited** (Boolean) - Shows whether the LocationManager object has been initialized. - **isLocationAvailable** (Boolean) - Shows whether location services are available on the current device. - **isAccessRequested** (Boolean) - Shows whether permission to use location has been requested. - **isAccessGranted** (Boolean) - Shows whether permission to use location has been granted. All these methods return the LocationManager object so they can be chained. ``` -------------------------------- ### clear Source: https://core.telegram.org/bots/webapps Clears all keys previously stored by the bot in the device's secure storage. Supports an optional callback for asynchronous operations. ```APIDOC ## clear([callback]) ### Description Clears all keys previously stored by the bot in the device's secure storage. If an optional _callback_ parameter was passed, the _callback_ function will be called. ### Parameters #### Path Parameters - **callback** (function) - Optional - A callback function to be called after the operation. ### Callback Response - **error** (Error) - If an error occurs, this argument will contain the error. - **success** (boolean) - If successful, this argument will be true, indicating all values were removed. ``` -------------------------------- ### __BackButton Source: https://core.telegram.org/bots/webapps Controls the back button in the Mini App header, allowing visibility toggling and event handling. ```APIDOC ## __BackButton ### Description This object controls the **back** button, which can be displayed in the header of the Mini App in the Telegram interface. ### Fields - **isVisible** (Boolean) - Shows whether the button is visible. Set to _false_ by default. - **onClick(callback)** (Function) - Bot API 6.1+ A method that sets the button press event handler. An alias for `Telegram.WebApp.onEvent('backButtonClicked', callback)`. - **offClick(callback)** (Function) - Bot API 6.1+ A method that removes the button press event handler. An alias for `Telegram.WebApp.offEvent('backButtonClicked', callback)`. - **show()** (Function) - Bot API 6.1+ A method to make the button active and visible. - **hide()** (Function) - Bot API 6.1+ A method to hide the button. All these methods return the BackButton object so they can be chained. ``` -------------------------------- ### SecureStorage Source: https://core.telegram.org/bots/webapps An object for storing and retrieving data from the device's secure storage. ```APIDOC ## SecureStorage ### Description Manages secure storage for sensitive data on the device. ### Usage ```javascript Telegram.WebApp.SecureStorage ``` ``` -------------------------------- ### CloudStorage Source: https://core.telegram.org/bots/webapps An object for controlling cloud storage. ```APIDOC ## CloudStorage ### Description Manages interactions with cloud storage. ### Usage ```javascript Telegram.WebApp.CloudStorage ``` ``` -------------------------------- ### __WebAppChat Source: https://core.telegram.org/bots/webapps This object represents a chat. ```APIDOC ## __WebAppChat ### Description This object represents a chat. ### Fields - **id** (Integer) - Unique identifier for this chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. - **type** (String) - Type of chat, can be either “group”, “supergroup” or “channel”. - **title** (String) - Title of the chat. - **username** (String) - Optional. Username of the chat. - **photo_url** (String) - Optional. URL of the chat’s photo. The photo can be in .jpeg or .svg formats. Only returned for Mini Apps launched from the attachment menu. ``` -------------------------------- ### Event Handling Source: https://core.telegram.org/bots/webapps Methods for managing event listeners within a Mini App. `onEvent` registers a handler for a specific event type, while `offEvent` removes a previously registered handler. ```APIDOC ## onEvent(eventType, eventHandler) ### Description A method that sets the app event handler. Check the list of available events. ### Method Function ### Parameters - **eventType** (string) - Required - The type of event to listen for. - **eventHandler** (function) - Required - The function to be called when the event occurs. ``` ```APIDOC ## offEvent(eventType, eventHandler) ### Description A method that deletes a previously set event handler. ### Method Function ### Parameters - **eventType** (string) - Required - The type of event to remove the handler from. - **eventHandler** (function) - Required - The specific event handler function to remove. ```