TelegramWebApp class abstract
All the apis provided at https://core.telegram.org/bots/webapps#initializing-mini-apps
- Implementers
Constructors
Properties
- backButton → BackButton
-
An object for controlling the back button which can
be displayed in the header of the Mini App in the Telegram
interface.
no setter
- backgroundColor → Color?
-
Current background color in the #RRGGBB format.
no setter
- biometricManager → BiometricManager
-
An object for controlling biometrics on the device.
no setter
- bottomBarColor → Color?
-
Current bottom bar color in the #RRGGBB format.
no setter
- cloudStorage → CloudStorage
-
An object for controlling cloud storage.
no setter
- colorScheme → TelegramColorScheme
-
The color scheme currently used in the Telegram app.
Either “light” or “dark”.
Also available as the CSS variable var(--tg-color-scheme).
no setter
- hapticFeedback → HapticFeedback
-
An object for controlling haptic feedback.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- headerColor → Color?
-
Current header color in the #RRGGBB format.
no setter
- initData → TelegramInitData
-
A string with raw data transferred to the Mini App,
convenient for validating data.
WARNING: Validate data from this field before using it on
the bot's server.
no setter
- initDataUnsafe → WebAppInitData?
-
An object with input data transferred to the Mini App.
WARNING: Data from this field should not be trusted.
You should only use data from initData on the bot's
server and only after it has been validated.
no setter
- isClosingConfirmationEnabled → bool
-
True, if the confirmation dialog is enabled while the
user is trying to close the Mini App. False, if the confirmation
dialog is disabled.
no setter
- isExpanded → bool
-
True, if the Mini App is expanded to the maximum
available height. False, if the Mini App occupies part of
the screen and can be expanded to the full height using
the expand() method.
no setter
- isSupported → bool
-
Returns true if opened inside Telegram web.
no setter
- isVerticalSwipesEnabled → bool
-
True, if vertical swipes to close or minimize the Mini App
are enabled. False, if vertical swipes to close or minimize
the Mini App are disabled. In any case, the user will still
be able to minimize and close the Mini App by swiping
the Mini App's header.
no setter
- mainButton → BottomButton
-
An object for controlling the main button, which is
displayed at the bottom of the Mini App in the Telegram
interface.
no setter
- platform → String
-
The name of the platform of the user's Telegram app.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- secondaryButton → BottomButton
-
An object for controlling the secondary button, which is
displayed at the bottom of the Mini App in the Telegram
interface.
no setter
- settingButton → SettingsButton
-
An object for controlling the Settings item in the context
menu of the Mini App in the Telegram interface.
no setter
- themeParams → ThemeParams
-
An object containing the current theme settings used in
the Telegram app.
no setter
- version → String
-
The version of the Bot API available in the user's
Telegram app.
no setter
- viewportHeight → double?
-
The current height of the visible area of the Mini App.
Also available in CSS as the variable var(--tg-viewport-
height).
no setter
- viewportStableHeight → double?
-
The height of the visible area of the Mini App in its last
stable state. Also available in CSS as a variable var(--tg-
viewport-stable-height).
no setter
Methods
-
close(
) → void - A method that closes the Mini App.
-
closeScanQrPopup(
) → void - Bot API 6.4+ A method that closes the native popup for scanning a QR code opened with the showScanQrPopup method. Run it if you received valid data in the event qrTextReceived.
-
disableClosingConfirmation(
) → void - Bot API 6.2+ A method that disables the confirmation dialog while the user is trying to close the Mini App.
-
disableVerticalSwipes(
) → void - Bot API 7.7+ A method that disables vertical swipes to close or minimize the Mini App. This method is useful if your Mini App uses swipe gestures that may conflict with the gestures for minimizing and closing the app.
-
enableClosingConfirmation(
) → void - Bot API 6.2+ A method that enables a confirmation dialog while the user is trying to close the Mini App.
-
enableVerticalSwipes(
) → void - Bot API 7.7+ A method that enables vertical swipes to close or minimize the Mini App. For user convenience, it is recommended to always enable swipes unless they conflict with the Mini App's own gestures.
-
expand(
) → void - 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
-
isVersionAtLeast(
String version) → bool - 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.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
offEvent(
TelegramEvent event) → void - A method that deletes a previously set event handler.
-
onEvent(
TelegramEvent event) → void - A method that sets the app event handler. Check the list of available events.
-
openInvoice(
String url, [void onInvoiceStatus(InvoiceStatus status)?]) → void - Bot API 6.1+ A method that opens an invoice using the link url. The Mini App will receive the event invoiceClosed when the invoice is closed. If an optional callback parameter was passed, the callback function will be called and the invoice status will be passed as the first argument.
-
openLink(
String url, {bool tryInstantView = true}) → void - A method that opens a link in an external browser. The Mini App will not be closed. Bot API 6.4+ If the optional options parameter is passed with the field try_instant_view=true, the link will be opened in Instant View mode if possible.
-
openTelegramLink(
String url) → void - A method that opens a telegram link inside the Telegram app. The Mini App will not be closed after this method is called.
-
readTextFromClipboard(
[void onRead(String clipboardText)?]) → void - Bot API 6.4+ A method that requests text from the clipboard. The Mini App will receive the event clipboardTextReceived. If an optional callback parameter was passed, the callback function will be called and the text from the clipboard will be passed as the first argument.
-
ready(
) → void - 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.
-
requestContact(
[void onResult(bool granted)?]) → void - Bot API 6.9+ A method that shows a native popup prompting the user for their phone number. 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 shared its phone number.
-
requestWriteAccess(
{required dynamic onResult(bool granted)}) → void - Bot API 6.9+ A method that shows a native popup requesting permission for the bot to send messages to the user. 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 granted this access.
-
sendData(
String data) → void - A method used to send data to the bot. When this method is called, a service message is sent to the bot containing the data data of the length up to 4096 bytes, and the Mini App is closed. See the field web_app_data in the class Message.
-
setBackgroundColor(
Color color) → void - Bot API 6.1+ A method that sets the app background color in the #RRGGBB format. You can also use keywords bg_color and secondary_bg_color.
-
setBottomBarColor(
Color color) → void - Bot API 7.10+ A method that sets the app's bottom bar color in the #RRGGBB format. You can also use the keywords bg_color, secondary_bg_color and bottom_bar_bg_color.
-
setHeaderColor(
Color color) → void - Bot API 6.1+ A method that sets the app header color in the #RRGGBB format. You can also use keywords bg_color and secondary_bg_color.
- Bot API 7.8+ A method that opens the native story editor with the media specified in the media_url parameter as an HTTPS URL. An optional params argument of the type StoryShareParams describes additional sharing settings.
-
showAlert(
String message, [dynamic callback()?]) → void - Bot API 6.2+ A method that shows message in a simple alert with a 'Close' button. If an optional callback parameter was passed, the callback function will be called when the popup is closed.
-
showConfirm(
String message, [void callback(bool isOkPressed)?]) → void - Bot API 6.2+ 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.
-
showPopup(
{String? title, required String message, List< PopupButton> ? buttons, required dynamic callback(String id)}) → void -
Bot API 6.2+ 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. -
showScanQrPopup(
String? infoTitle, [bool callback(String result)?]) → void -
Bot API 6.4+ 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. -
switchInlineQuery(
String query, [List< ChatType> ? chatTypes]) → void - Bot API 6.7+ A method that inserts the bot's username and the specified inline query in the current chat's input field. Query may be empty, in which case only the bot's username will be inserted. If an optional choose_chat_types parameter was passed, the client prompts the user to choose a specific chat, then opens that chat and inserts the bot's username and the specified inline query in the input field. You can specify which types of chats the user will be able to choose from. It can be one or more of the following types: users, bots, groups, channels.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → TelegramWebApp
-
no setter