Skip to content

Latest commit

 

History

History
2795 lines (1995 loc) · 70.4 KB

File metadata and controls

2795 lines (1995 loc) · 70.4 KB

TelegramWebApp

WebApp

WebApp.webAppUser

type webAppUser = {
  id: int,
  is_bot?: bool,
  first_name: string,
  last_name?: string,
  username?: string,
  language_code?: string,
  is_premium?: bool,
  added_to_attachment_menu?: bool,
  allows_write_to_pm?: bool,
  photo_url?: string,
}

WebApp.webAppChat

type webAppChat = {
  id: int,
  type_: string,
  title: string,
  username?: string,
  photo_url?: string,
}

WebApp.webAppInitDataUnsafe

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.

type webAppInitDataUnsafe = {
  query_id?: string,
  user?: webAppUser,
  receiver?: webAppUser,
  chat?: webAppChat,
  chat_type?: string,
  chat_instance?: string,
  start_param?: string,
  can_send_after?: int,
  auth_date: int,
  hash: string,
  signature: string,
}

WebApp.colorScheme

type colorScheme = @as("light") Light | @as("dark") Dark

WebApp.themeParams

ThemeParams 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:

type themeParams = {
  bg_color?: string,
  text_color?: string,
  hint_color?: string,
  link_color?: string,
  button_color?: string,
  button_text_color?: string,
  secondary_bg_color?: string,
  header_bg_color?: string,
  bottom_bar_bg_color?: string,
  accent_text_color?: string,
  section_bg_color?: string,
  section_header_text_color?: string,
  section_separator_color?: string,
  subtitle_text_color?: string,
  destructive_text_color?: string,
}

WebApp.safeAreaInset

type safeAreaInset = {
  top: int,
  bottom: int,
  left: int,
  right: int,
}

WebApp.contentSafeAreaInset

type contentSafeAreaInset = {
  top: int,
  bottom: int,
  left: int,
  right: int,
}

WebApp.t

type t = {
  initData: string,
  initDataUnsafe: webAppInitDataUnsafe,
  version: string,
  platform: string,
  colorScheme: colorScheme,
  themeParams: themeParams,
  isActve: bool,
  isExpanded: bool,
  viewportHeight: float,
  viewportStableHeight: float,
  mutable headerColor: string,
  mutable backgroundColor: string,
  mutable bottomBarColor: string,
  mutable isClosingConfirmationEnabled: bool,
  mutable isVerticalSwipesEnabled: bool,
  isFullscreen: bool,
  mutable isOrientationLocked: bool,
  safeAreaInset: safeAreaInset,
  contentSafeAreaInset: contentSafeAreaInset,
  backButton: TelegramWebApp.BackButton.t,
  mainButton: TelegramWebApp.BottomButton.t,
  secondaryButton: TelegramWebApp.BottomButton.t,
  settings: TelegramWebApp.SettingsButton.t,
  hapticFeedback: TelegramWebApp.HapticFeedback.t,
  cloudStorage: TelegramWebApp.CloudStorage.t,
  biometricManager: TelegramWebApp.BiometricManager.t,
  accelerometer: TelegramWebApp.Accelerometer.t,
  deviceOrientation: TelegramWebApp.DeviceOrientation.t,
  gyroscope: TelegramWebApp.Gyroscope.t,
  locationManager: TelegramWebApp.LocationManager.t,
  deviceStorage: TelegramWebApp.DeviceStorage.t,
  secureStorage: TelegramWebApp.SecureStorage.t,
}

WebAppAPI

WebAppAPI.isVersionAtLeast

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.

let isVersionAtLeast: (TelegramWebApp.WebApp.t, string) => bool

WebAppAPI.setHeaderColor

A method that sets the app header color in the #RRGGBB format. You can also use keywords bg_color and secondary_bg_color.

Up to Bot API 6.9 You can only pass Telegram.WebApp.themeParams.bg_color or Telegram.WebApp.themeParams.secondary_bg_color as a color or bg_color, secondary_bg_color keywords.

let setHeaderColor: (TelegramWebApp.WebApp.t, string) => unit

WebAppAPI.setBackgroundColor

A method that sets the app background color in the #RRGGBB format. You can also use keywords bg_color and secondary_bg_color.

let setBackgroundColor: (TelegramWebApp.WebApp.t, string) => unit

WebAppAPI.setBottomBarColor

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. This color is also applied to the navigation bar on Android.

let setBottomBarColor: (TelegramWebApp.WebApp.t, string) => unit

WebAppAPI.enableClosingConfirmation

A method that enables a confirmation dialog while the user is trying to close the Mini App.

let enableClosingConfirmation: TelegramWebApp.WebApp.t => unit

WebAppAPI.disableClosingConfirmation

A method that disables the confirmation dialog while the user is trying to close the Mini App.

let disableClosingConfirmation: TelegramWebApp.WebApp.t => unit

WebAppAPI.enableVerticalSwipes

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.

let enableVerticalSwipes: TelegramWebApp.WebApp.t => unit

WebAppAPI.disableVerticalSwipes

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.

let disableVerticalSwipes: TelegramWebApp.WebApp.t => unit

WebAppAPI.requestFullscreen

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.

let requestFullscreen: TelegramWebApp.WebApp.t => unit

WebAppAPI.exitFullscreen

A method that requests exiting fullscreen mode.

let exitFullscreen: TelegramWebApp.WebApp.t => unit

WebAppAPI.lockOrientation

A method that locks the Mini App’s orientation to its current mode (either portrait or landscape). Once locked, the orientation remains fixed, regardless of device rotation. This is useful if a stable orientation is needed during specific interactions.

let lockOrientation: TelegramWebApp.WebApp.t => unit

WebAppAPI.unlockOrientation

A method that unlocks the Mini App’s orientation, allowing it to follow the device's rotation freely. Use this to restore automatic orientation adjustments based on the device orientation.

let unlockOrientation: TelegramWebApp.WebApp.t => unit

WebAppAPI.addToHomeScreen

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.

let addToHomeScreen: TelegramWebApp.WebApp.t => unit

WebAppAPI.homeScreenStatus

type homeScreenStatus =
  | @as("unsupported") Unsupported
  | @as("unknown") Unknown
  | @as("added") Added
  | @as("missed") Missed
  | UndocumentedStatus(string)

WebAppAPI.checkHomeScreenStatus

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.

let checkHomeScreenStatus: (
  TelegramWebApp.WebApp.t,
  ~callback: homeScreenStatus => unit=?,
) => unit

WebAppAPI.invoiceStatus

@unboxed
type invoiceStatus =
  | @as("paid") Paid
  | @as("cancelled") Cancelled
  | @as("failed") Failed
  | @as("pending") Pending
  | UndocumentedStatus(string)

WebAppAPI.onActivated

Occurs when the Mini App becomes active (e.g., opened from minimized state or selected among tabs).

let onActivated: (TelegramWebApp.WebApp.t, Events.activated) => unit

WebAppAPI.offActivated

let offActivated: (TelegramWebApp.WebApp.t, Events.activated) => unit

WebAppAPI.onDeactivated

Occurs when the Mini App becomes inactive (e.g., minimized or moved to an inactive tab).

let onDeactivated: (TelegramWebApp.WebApp.t, Events.deactivated) => unit

WebAppAPI.offDeactivated

let offDeactivated: (TelegramWebApp.WebApp.t, Events.deactivated) => unit

WebAppAPI.onThemeChanged

Occurs whenever theme settings are changed in the user's Telegram app (including switching to night mode).

eventHandler receives no parameters, new theme settings and color scheme can be received via this.themeParams and this.colorScheme respectively.

let onThemeChanged: (TelegramWebApp.WebApp.t, Events.themeChanged) => unit

WebAppAPI.offThemeChanged

let offThemeChanged: (TelegramWebApp.WebApp.t, Events.themeChanged) => unit

WebAppAPI.onViewportChanged

Occurs when the visible section of the Mini App is changed.

eventHandler receives an object with the single field isStateStable. If isStateStable is true, the resizing of the Mini App is finished. If it is false, the resizing is ongoing (the user is expanding or collapsing the Mini App or an animated object is playing). The current value of the visible section’s height is available in this.viewportHeight.

let onViewportChanged: (TelegramWebApp.WebApp.t, Events.viewportChanged) => unit

WebAppAPI.offViewportChanged

let offViewportChanged: (TelegramWebApp.WebApp.t, Events.viewportChanged) => unit

WebAppAPI.onSafeAreaChanged

Occurs when the device's safe area insets change (e.g., due to orientation change or screen adjustments).

eventHandler receives no parameters. The current inset values can be accessed via this.safeAreaInset.

let onSafeAreaChanged: (TelegramWebApp.WebApp.t, Events.safeAreaChanged) => unit

WebAppAPI.offSafeAreaChanged

let offSafeAreaChanged: (TelegramWebApp.WebApp.t, Events.safeAreaChanged) => unit

WebAppAPI.onContentSafeAreaChanged

Occurs when the safe area for content changes (e.g., due to orientation change or screen adjustments).

eventHandler receives no parameters. The current inset values can be accessed via this.contentSafeAreaInset.

let onContentSafeAreaChanged: (
  TelegramWebApp.WebApp.t,
  Events.contentSafeAreaChanged,
) => unit

WebAppAPI.offContentSafeAreaChanged

let offContentSafeAreaChanged: (
  TelegramWebApp.WebApp.t,
  Events.contentSafeAreaChanged,
) => unit

WebAppAPI.onMainButtonClicked

Occurs when the main button is pressed.

let onMainButtonClicked: (TelegramWebApp.WebApp.t, Events.mainButtonClicked) => unit

WebAppAPI.offMainButtonClicked

let offMainButtonClicked: (TelegramWebApp.WebApp.t, Events.mainButtonClicked) => unit

WebAppAPI.onSecondaryButtonClicked

Occurs when the secondary button is pressed.

let onSecondaryButtonClicked: (
  TelegramWebApp.WebApp.t,
  Events.secondaryButtonClicked,
) => unit

WebAppAPI.offSecondaryButtonClicked

let offSecondaryButtonClicked: (
  TelegramWebApp.WebApp.t,
  Events.secondaryButtonClicked,
) => unit

WebAppAPI.onBackButtonClicked

Occurrs when the back button is pressed.

let onBackButtonClicked: (TelegramWebApp.WebApp.t, Events.backButtonClicked) => unit

WebAppAPI.offBackButtonClicked

let offBackButtonClicked: (TelegramWebApp.WebApp.t, Events.backButtonClicked) => unit

WebAppAPI.onSettingsButtonClicked

Occurrs when the Settings item in context menu is pressed.

let onSettingsButtonClicked: (
  TelegramWebApp.WebApp.t,
  Events.settingsButtonClicked,
) => unit

WebAppAPI.offSettingsButtonClicked

let offSettingsButtonClicked: (
  TelegramWebApp.WebApp.t,
  Events.settingsButtonClicked,
) => unit

WebAppAPI.onInvoiceClosed

Occurrs when the opened invoice is closed.

eventHandler receives an object with the two fields: url – invoice link provided and status – one of the invoice statuses.

let onInvoiceClosed: (TelegramWebApp.WebApp.t, Events.invoiceClosed) => unit

WebAppAPI.offInvoiceClosed

let offInvoiceClosed: (TelegramWebApp.WebApp.t, Events.invoiceClosed) => unit

WebAppAPI.onPopupClosed

Occurrs when the opened popup is closed.

eventHandler receives an object with the single field button_id – the value of the field id of the pressed button. If no buttons were pressed, the field button_id will be null.

let onPopupClosed: (TelegramWebApp.WebApp.t, Events.popupClosed) => unit

WebAppAPI.offPopupClosed

let offPopupClosed: (TelegramWebApp.WebApp.t, Events.popupClosed) => unit

WebAppAPI.onQrTextReceived

Occurs when the QR code scanner catches a code with text data.

eventHandler receives an object with the single field data containing text data from the QR code.

let onQrTextReceived: (TelegramWebApp.WebApp.t, Events.qrTextReceived) => unit

WebAppAPI.offQrTextReceived

let offQrTextReceived: (TelegramWebApp.WebApp.t, Events.qrTextReceived) => unit

WebAppAPI.onScanQrPopupClosed

Occurs when the QR code scanner popup is closed by the user.

let onScanQrPopupClosed: (TelegramWebApp.WebApp.t, Events.scanQrPopupClosed) => unit

WebAppAPI.offScanQrPopupClosed

let offScanQrPopupClosed: (TelegramWebApp.WebApp.t, Events.scanQrPopupClosed) => unit

WebAppAPI.onClipboardTextReceived

Occurrs when the readTextFromClipboard method is called.

eventHandler receives an object with the single field data containing text data from the clipboard. If the clipboard contains non-text data, the field data will be an empty string. If the Mini App has no access to the clipboard, the field data will be null.

let onClipboardTextReceived: (
  TelegramWebApp.WebApp.t,
  Events.clipboardTextReceived,
) => unit

WebAppAPI.offClipboardTextReceived

let offClipboardTextReceived: (
  TelegramWebApp.WebApp.t,
  Events.clipboardTextReceived,
) => unit

WebAppAPI.onWriteAccessRequested

Occurs when the write permission was requested.

eventHandler receives an object with the single field status containing one of the statuses.

let onWriteAccessRequested: (
  TelegramWebApp.WebApp.t,
  Events.writeAccessRequested,
) => unit

WebAppAPI.offWriteAccessRequested

let offWriteAccessRequested: (
  TelegramWebApp.WebApp.t,
  Events.writeAccessRequested,
) => unit

WebAppAPI.onContactRequested

Occurrs when the user's phone number was requested.

eventHandler receives an object with the single field status containing one of the statuses.

let onContactRequested: (TelegramWebApp.WebApp.t, Events.contactRequested) => unit

WebAppAPI.offContactRequested

let offContactRequested: (TelegramWebApp.WebApp.t, Events.contactRequested) => unit

WebAppAPI.onBiometricManagerUpdated

Occurs whenever BiometricManager object is changed.

let onBiometricManagerUpdated: (
  TelegramWebApp.WebApp.t,
  Events.biometricManagerUpdated,
) => unit

WebAppAPI.offBiometricManagerUpdated

let offBiometricManagerUpdated: (
  TelegramWebApp.WebApp.t,
  Events.biometricManagerUpdated,
) => unit

WebAppAPI.onBiometricAuthRequested

Occurs whenever biometric authentication was requested.

eventHandler receives an object with the field isAuthenticated containing a boolean indicating whether the user was authenticated successfully. If isAuthenticated is true, the field biometricToken will contain the biometric token stored in secure storage on the device.

let onBiometricAuthRequested: (
  TelegramWebApp.WebApp.t,
  Events.biometricAuthRequested,
) => unit

WebAppAPI.offBiometricAuthRequested

let offBiometricAuthRequested: (
  TelegramWebApp.WebApp.t,
  Events.biometricAuthRequested,
) => unit

WebAppAPI.onBiometricTokenUpdated

Occurs whenever the biometric token was updated.

eventHandler receives an object with the single field isUpdated, containing a boolean indicating whether the token was updated.

let onBiometricTokenUpdated: (
  TelegramWebApp.WebApp.t,
  Events.biometricTokenUpdated,
) => unit

WebAppAPI.offBiometricTokenUpdated

let offBiometricTokenUpdated: (
  TelegramWebApp.WebApp.t,
  Events.biometricTokenUpdated,
) => unit

WebAppAPI.onFullscreenChanged

Occurs whenever the Mini App enters or exits fullscreen mode.

eventHandler receives no parameters. The current fullscreen state can be checked via this.isFullscreen.

let onFullscreenChanged: (TelegramWebApp.WebApp.t, Events.fullscreenChanged) => unit

WebAppAPI.offFullscreenChanged

let offFullscreenChanged: (TelegramWebApp.WebApp.t, Events.fullscreenChanged) => unit

WebAppAPI.onFullscreenFailed

Occurs if a request to enter fullscreen mode fails.

eventHandler receives an object with the single field error, describing the reason for the failure.

let onFullscreenFailed: (TelegramWebApp.WebApp.t, Events.fullscreenFailed) => unit

WebAppAPI.offFullscreenFailed

let offFullscreenFailed: (TelegramWebApp.WebApp.t, Events.fullscreenFailed) => unit

WebAppAPI.onHomeScreenAdded

Occurs when the Mini App is successfully added to the home screen.

let onHomeScreenAdded: (TelegramWebApp.WebApp.t, Events.homeScreenAdded) => unit

WebAppAPI.offHomeScreenAdded

let offHomeScreenAdded: (TelegramWebApp.WebApp.t, Events.homeScreenAdded) => unit

WebAppAPI.onHomeScreenChecked

Occurs after checking the home screen status.

eventHandler receives an object with the field status, which is a string indicating the current home screen status.

let onHomeScreenChecked: (TelegramWebApp.WebApp.t, Events.homeScreenChecked) => unit

WebAppAPI.offHomeScreenChecked

let offHomeScreenChecked: (TelegramWebApp.WebApp.t, Events.homeScreenChecked) => unit

WebAppAPI.onAccelerometerStarted

Occurs when accelerometer tracking has started successfully.

let onAccelerometerStarted: (
  TelegramWebApp.WebApp.t,
  Events.accelerometerStarted,
) => unit

WebAppAPI.offAccelerometerStarted

let offAccelerometerStarted: (
  TelegramWebApp.WebApp.t,
  Events.accelerometerStarted,
) => unit

WebAppAPI.onAccelerometerStopped

Occurs when accelerometer tracking has stopped.

let onAccelerometerStopped: (
  TelegramWebApp.WebApp.t,
  Events.accelerometerStopped,
) => unit

WebAppAPI.offAccelerometerStopped

let offAccelerometerStopped: (
  TelegramWebApp.WebApp.t,
  Events.accelerometerStopped,
) => unit

WebAppAPI.onAccelerometerChanged

Occurs with the specified frequency after calling the start method, sending the current accelerometer data.

eventHandler receives no parameters, the current acceleration values can be received via this.x, this.y and this.z respectively.

let onAccelerometerChanged: (
  TelegramWebApp.WebApp.t,
  Events.accelerometerChanged,
) => unit

WebAppAPI.offAccelerometerChanged

let offAccelerometerChanged: (
  TelegramWebApp.WebApp.t,
  Events.accelerometerChanged,
) => unit

WebAppAPI.onAccelerometerFailed

Occurs if a request to start accelerometer tracking fails.

eventHandler receives an object with the single field error, describing the reason for the failure.

let onAccelerometerFailed: (
  TelegramWebApp.WebApp.t,
  Events.accelerometerFailed,
) => unit

WebAppAPI.offAccelerometerFailed

let offAccelerometerFailed: (
  TelegramWebApp.WebApp.t,
  Events.accelerometerFailed,
) => unit

WebAppAPI.onDeviceOrientationStarted

Occurs when device orientation tracking has started successfully.

let onDeviceOrientationStarted: (
  TelegramWebApp.WebApp.t,
  Events.deviceOrientationStarted,
) => unit

WebAppAPI.offDeviceOrientationStarted

let offDeviceOrientationStarted: (
  TelegramWebApp.WebApp.t,
  Events.deviceOrientationStarted,
) => unit

WebAppAPI.onDeviceOrientationStopped

Occurs when device orientation tracking has stopped.

let onDeviceOrientationStopped: (
  TelegramWebApp.WebApp.t,
  Events.deviceOrientationStopped,
) => unit

WebAppAPI.offDeviceOrientationStopped

let offDeviceOrientationStopped: (
  TelegramWebApp.WebApp.t,
  Events.deviceOrientationStopped,
) => unit

WebAppAPI.onDeviceOrientationChanged

Occurs with the specified frequency after calling the start method, sending the current orientation data.

eventHandler receives no parameters, the current device orientation values can be received via this.alpha, this.beta and this.gamma respectively.

let onDeviceOrientationChanged: (
  TelegramWebApp.WebApp.t,
  Events.deviceOrientationChanged,
) => unit

WebAppAPI.offDeviceOrientationChanged

let offDeviceOrientationChanged: (
  TelegramWebApp.WebApp.t,
  Events.deviceOrientationChanged,
) => unit

WebAppAPI.onDeviceOrientationFailed

Occurs if a request to start device orientation tracking fails.

eventHandler receives an object with the single field error, describing the reason for the failure.

let onDeviceOrientationFailed: (
  TelegramWebApp.WebApp.t,
  Events.deviceOrientationFailed,
) => unit

WebAppAPI.offDeviceOrientationFailed

let offDeviceOrientationFailed: (
  TelegramWebApp.WebApp.t,
  Events.deviceOrientationFailed,
) => unit

WebAppAPI.onGyroscopeStarted

Occurs when gyroscope tracking has started successfully.

let onGyroscopeStarted: (TelegramWebApp.WebApp.t, Events.gyroscopeStarted) => unit

WebAppAPI.offGyroscopeStarted

let offGyroscopeStarted: (TelegramWebApp.WebApp.t, Events.gyroscopeStarted) => unit

WebAppAPI.onGyroscopeStopped

Occurs when gyroscope tracking has stopped.

let onGyroscopeStopped: (TelegramWebApp.WebApp.t, Events.gyroscopeStopped) => unit

WebAppAPI.offGyroscopeStopped

let offGyroscopeStopped: (TelegramWebApp.WebApp.t, Events.gyroscopeStopped) => unit

WebAppAPI.onGyroscopeChanged

Occurs with the specified frequency after calling the start method, sending the current gyroscope data.

eventHandler receives no parameters, the current rotation rates can be received via this.x, this.y and this.z respectively.

let onGyroscopeChanged: (TelegramWebApp.WebApp.t, Events.gyroscopeChanged) => unit

WebAppAPI.offGyroscopeChanged

let offGyroscopeChanged: (TelegramWebApp.WebApp.t, Events.gyroscopeChanged) => unit

WebAppAPI.onGyroscopeFailed

Occurs if a request to start gyroscope tracking fails.

eventHandler receives an object with the single field error, describing the reason for the failure.

let onGyroscopeFailed: (TelegramWebApp.WebApp.t, Events.gyroscopeFailed) => unit

WebAppAPI.offGyroscopeFailed

let offGyroscopeFailed: (TelegramWebApp.WebApp.t, Events.gyroscopeFailed) => unit

WebAppAPI.onLocationManagerUpdated

Occurs whenever LocationManager object is changed.

let onLocationManagerUpdated: (
  TelegramWebApp.WebApp.t,
  Events.locationManagerUpdated,
) => unit

WebAppAPI.offLocationManagerUpdated

let offLocationManagerUpdated: (
  TelegramWebApp.WebApp.t,
  Events.locationManagerUpdated,
) => unit

WebAppAPI.onLocationRequested

Occurs when location data is requested.

eventHandler receives an object with the single field locationData of type LocationData, containing the current location information.

let onLocationRequested: (TelegramWebApp.WebApp.t, Events.locationRequested) => unit

WebAppAPI.offLocationRequested

let offLocationRequested: (TelegramWebApp.WebApp.t, Events.locationRequested) => unit

WebAppAPI.onShareMessageSent

Occurs when the message is successfully shared by the user.

let onShareMessageSent: (TelegramWebApp.WebApp.t, Events.shareMessageSent) => unit

WebAppAPI.offShareMessageSent

let offShareMessageSent: (TelegramWebApp.WebApp.t, Events.shareMessageSent) => unit

WebAppAPI.onShareMessageFailed

Occurs if sharing the message fails.

eventHandler receives an object with the single field error, describing the reason for the failure.

let onShareMessageFailed: (TelegramWebApp.WebApp.t, Events.shareMessageFailed) => unit

WebAppAPI.offShareMessageFailed

let offShareMessageFailed: (TelegramWebApp.WebApp.t, Events.shareMessageFailed) => unit

WebAppAPI.onEmojiStatusSet

Occurs when the emoji status is successfully set.

let onEmojiStatusSet: (TelegramWebApp.WebApp.t, Events.emojiStatusSet) => unit

WebAppAPI.offEmojiStatusSet

let offEmojiStatusSet: (TelegramWebApp.WebApp.t, Events.emojiStatusSet) => unit

WebAppAPI.onEmojiStatusFailed

Occurs if setting the emoji status fails.

eventHandler receives an object with the single field error, describing the reason for the failure.

let onEmojiStatusFailed: (TelegramWebApp.WebApp.t, Events.emojiStatusFailed) => unit

WebAppAPI.offEmojiStatusFailed

let offEmojiStatusFailed: (TelegramWebApp.WebApp.t, Events.emojiStatusFailed) => unit

WebAppAPI.onEmojiStatusAccessRequested

Occurs when the write permission was requested.

eventHandler receives an object with the single field status containing one of the statuses

let onEmojiStatusAccessRequested: (
  TelegramWebApp.WebApp.t,
  Events.emojiStatusAccessRequested,
) => unit

WebAppAPI.offEmojiStatusAccessRequested

let offEmojiStatusAccessRequested: (
  TelegramWebApp.WebApp.t,
  Events.emojiStatusAccessRequested,
) => unit

WebAppAPI.onFileDownloadRequested

Occurs when the user responds to the file download request.

eventHandler receives an object with the single field status containing one of the statuses.

let onFileDownloadRequested: (
  TelegramWebApp.WebApp.t,
  Events.fileDownloadRequested,
) => unit

WebAppAPI.offFileDownloadRequested

let offFileDownloadRequested: (
  TelegramWebApp.WebApp.t,
  Events.fileDownloadRequested,
) => unit

WebAppAPI.onEvent

A method that sets the app event handler.

let onEvent: (TelegramWebApp.WebApp.t, string, unit => unit) => unit

WebAppAPI.offEvent

A method that deletes a previously set event handler.

let offEvent: (TelegramWebApp.WebApp.t, string, unit => unit) => unit

WebAppAPI.onEvent1

A method that sets the app event handler.

let onEvent1: (TelegramWebApp.WebApp.t, string, 'a => unit) => unit

WebAppAPI.offEvent1

A method that deletes a previously set event handler.

let offEvent1: (TelegramWebApp.WebApp.t, string, 'a => unit) => unit

WebAppAPI.sendData

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.

This method is only available for Mini Apps launched via a Keyboard button.

let sendData: (TelegramWebApp.WebApp.t, string) => unit

WebAppAPI.chooseChatType

type chooseChatType =
  | @as("users") Users
  | @as("bots") Bots
  | @as("groups") Groups
  | @as("channels") Channels

WebAppAPI.switchInlineQuery

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.

let switchInlineQuery: (
  TelegramWebApp.WebApp.t,
  string,
  ~choose_chat_types: array<chooseChatType>=?,
) => unit

WebAppAPI.openLinkOptions

type openLinkOptions = {try_instant_view: bool}

WebAppAPI.openLink

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.

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)

let openLink: (
  TelegramWebApp.WebApp.t,
  string,
  ~options: openLinkOptions=?,
) => unit

WebAppAPI.openTelegramLink

A method that opens a telegram link inside the Telegram app. The Mini App will not be closed after this method is called.

Up to Bot API 7.0 The Mini App will be closed after this method is called.

let openTelegramLink: (TelegramWebApp.WebApp.t, string) => unit

WebAppAPI.openInvoice

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.

let openInvoice: (
  TelegramWebApp.WebApp.t,
  string,
  ~callback: invoiceStatus => unit=?,
) => unit

WebAppAPI.storyWidgetLink

type storyWidgetLink = {url: string, name?: string}

WebAppAPI.shareToStoryParams

type shareToStoryParams = {
  text?: string,
  widget_link?: storyWidgetLink,
}

WebAppAPI.shareToStory

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.

let shareToStory: (
  TelegramWebApp.WebApp.t,
  string,
  ~params: shareToStoryParams=?,
) => unit

WebAppAPI.shareMessage

A method that opens a dialog allowing the user to share a message provided by the bot. If an optional callback parameter is provided, the callback function will be called with a boolean as the first argument, indicating whether the message was successfully sent. The message id passed to this method must belong to a PreparedInlineMessage previously obtained via the Bot API method savePreparedInlineMessage.

let shareMessage: (
  TelegramWebApp.WebApp.t,
  string,
  ~callback: bool => unit=?,
) => unit

WebAppAPI.emojiStatusParams

type emojiStatusParams = {duration?: int}

WebAppAPI.setEmojiStatus

A method that opens a dialog allowing the user to set the specified custom emoji as their status. An optional params argument of type EmojiStatusParams specifies additional settings, such as duration. If an optional callback parameter is provided, the callback function will be called with a boolean as the first argument, indicating whether the status was set.

Note: this method opens a native dialog and cannot be used to set the emoji status without manual user interaction. For fully programmatic changes, you should instead use the Bot API method setUserEmojiStatus after obtaining authorization to do so via the Mini App method requestEmojiStatusAccess.

let setEmojiStatus: (
  TelegramWebApp.WebApp.t,
  string,
  ~params: emojiStatusParams=?,
  ~callback: bool => unit=?,
) => unit

WebAppAPI.requestEmojiStatusAccess

A method that shows a native popup requesting permission for the bot to manage user's emoji status. 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.

let requestEmojiStatusAccess: (TelegramWebApp.WebApp.t, ~callback: bool => unit=?) => unit

WebAppAPI.downloadFileParams

type downloadFileParams = {url: string, file_name: string}

WebAppAPI.downloadFile

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.

let downloadFile: (
  TelegramWebApp.WebApp.t,
  ~params: downloadFileParams=?,
  ~callback: bool => unit=?,
) => unit

WebAppAPI.hideKeyboard

A method that hides the on-screen keyboard, if it is currently visible. Does nothing if the keyboard is not active.

let hideKeyboard: TelegramWebApp.WebApp.t => unit

WebAppAPI.popupButtonType

type popupButtonType =
  | @as("default") Default
  | @as("ok") Ok
  | @as("close") Close
  | @as("cancel") Cancel
  | @as("destructive") Destructive

WebAppAPI.popupButton

type popupButton = {
  id?: string,
  type_?: popupButtonType,
  text?: string,
}

WebAppAPI.popupParams

type popupParams = {
  title?: string,
  message: string,
  buttons: array<popupButton>,
}

WebAppAPI.showPopup

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.

let showPopup: (
  TelegramWebApp.WebApp.t,
  ~params: popupParams=?,
  ~callback: string => unit=?,
) => unit

WebAppAPI.showAlert

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.

let showAlert: (
  TelegramWebApp.WebApp.t,
  string,
  ~callback: unit => unit=?,
) => unit

WebAppAPI.showConfirm

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.

let showConfirm: (
  TelegramWebApp.WebApp.t,
  string,
  ~callback: bool => unit=?,
) => unit

WebAppAPI.scanQrPopupParams

type scanQrPopupParams = {text?: string}

WebAppAPI.showScanQrPopup

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.

let showScanQrPopup: (
  TelegramWebApp.WebApp.t,
  ~params: scanQrPopupParams,
  ~callback: string => bool=?,
) => unit

WebAppAPI.closeScanQrPopup

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.

let closeScanQrPopup: TelegramWebApp.WebApp.t => unit

WebAppAPI.readTextFromClipboard

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.

Note: this method can be called only for Mini Apps launched from the attachment menu and only in response to a user interaction with the Mini App interface (e.g. a click inside the Mini App or on the main button).

let readTextFromClipboard: (
  TelegramWebApp.WebApp.t,
  ~callback: string => unit=?,
) => unit

WebAppAPI.requestWriteAccess

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.

let requestWriteAccess: (TelegramWebApp.WebApp.t, ~callback: bool => unit=?) => unit

WebAppAPI.requestContact

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.

let requestContact: (TelegramWebApp.WebApp.t, ~callback: bool => unit=?) => unit

WebAppAPI.ready

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.

let ready: TelegramWebApp.WebApp.t => unit

WebAppAPI.expand

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

let expand: TelegramWebApp.WebApp.t => unit

WebAppAPI.close

A method that closes the Mini App.

let close: TelegramWebApp.WebApp.t => unit

Events

WebAppAPI.Events.activated

type activated = unit => unit

WebAppAPI.Events.deactivated

type deactivated = unit => unit

WebAppAPI.Events.themeChanged

type themeChanged = unit => unit

WebAppAPI.Events.viewportChangedEvent

type viewportChangedEvent = {isStateStable: bool}

WebAppAPI.Events.viewportChanged

type viewportChanged = viewportChangedEvent => unit

WebAppAPI.Events.safeAreaChanged

type safeAreaChanged = unit => unit

WebAppAPI.Events.contentSafeAreaChanged

type contentSafeAreaChanged = unit => unit

WebAppAPI.Events.mainButtonClicked

type mainButtonClicked = unit => unit

WebAppAPI.Events.secondaryButtonClicked

type secondaryButtonClicked = unit => unit

WebAppAPI.Events.backButtonClicked

type backButtonClicked = unit => unit

WebAppAPI.Events.settingsButtonClicked

type settingsButtonClicked = unit => unit

WebAppAPI.Events.invoiceClosedEvent

type invoiceClosedEvent = {
  url: string,
  status: invoiceStatus,
}

WebAppAPI.Events.invoiceClosed

type invoiceClosed = invoiceClosedEvent => unit

WebAppAPI.Events.popupClosedEvent

type popupClosedEvent = {button_id: Null.t<string>}

WebAppAPI.Events.popupClosed

type popupClosed = popupClosedEvent => unit

WebAppAPI.Events.qrTextReceivedEvent

type qrTextReceivedEvent = {data: string}

WebAppAPI.Events.qrTextReceived

type qrTextReceived = qrTextReceivedEvent => unit

WebAppAPI.Events.scanQrPopupClosed

type scanQrPopupClosed = unit => unit

WebAppAPI.Events.clipboardTextReceivedEvent

type clipboardTextReceivedEvent = {data: Null.t<string>}

WebAppAPI.Events.clipboardTextReceived

type clipboardTextReceived = clipboardTextReceivedEvent => unit

WebAppAPI.Events.writeAccessRequestedStatus

@unboxed
type writeAccessRequestedStatus =
  | @as("allowed") Allowed
  | @as("cancelled") Cancelled
  | UndocumentedStatus(string)

WebAppAPI.Events.writeAccessRequestedEvent

type writeAccessRequestedEvent = {
  status: writeAccessRequestedStatus,
}

WebAppAPI.Events.writeAccessRequested

type writeAccessRequested = writeAccessRequestedEvent => unit

WebAppAPI.Events.contactRequestedStatus

@unboxed
type contactRequestedStatus =
  | @as("sent") Sent
  | @as("cancelled") Cancelled
  | UndocumentedStatus(string)

WebAppAPI.Events.contactRequestedEvent

type contactRequestedEvent = {
  status: contactRequestedStatus,
}

WebAppAPI.Events.contactRequested

type contactRequested = contactRequestedEvent => unit

WebAppAPI.Events.biometricManagerUpdated

type biometricManagerUpdated = unit => unit

WebAppAPI.Events.biometricAuthRequestedEvent

type biometricAuthRequestedEvent = {
  isAuthenticated: bool,
  biometricToken?: string,
}

WebAppAPI.Events.biometricAuthRequested

type biometricAuthRequested = biometricAuthRequestedEvent => unit

WebAppAPI.Events.biometricTokenUpdatedEvent

type biometricTokenUpdatedEvent = {isUpdated: bool}

WebAppAPI.Events.biometricTokenUpdated

type biometricTokenUpdated = biometricTokenUpdatedEvent => unit

WebAppAPI.Events.fullscreenChanged

type fullscreenChanged = unit => unit

WebAppAPI.Events.fullscreenError

@unboxed
type fullscreenError =
  | @as("UNSUPPORTED") Unsupported
  | @as("ALREADY_FULLSCREEN") AlreadyFullscreen
  | UndocumentedError(string)

WebAppAPI.Events.fullscreenFailedEvent

type fullscreenFailedEvent = {error: fullscreenError}

WebAppAPI.Events.fullscreenFailed

type fullscreenFailed = fullscreenFailedEvent => unit

WebAppAPI.Events.homeScreenAdded

type homeScreenAdded = unit => unit

WebAppAPI.Events.homeScreenCheckedEvent

type homeScreenCheckedEvent = {status: homeScreenStatus}

WebAppAPI.Events.homeScreenChecked

type homeScreenChecked = homeScreenCheckedEvent => unit

WebAppAPI.Events.accelerometerStarted

type accelerometerStarted = unit => unit

WebAppAPI.Events.accelerometerStopped

type accelerometerStopped = unit => unit

WebAppAPI.Events.accelerometerChanged

type accelerometerChanged = unit => unit

WebAppAPI.Events.accelerometerFailedError

@unboxed
type accelerometerFailedError =
  | @as("UNSUPPORTED") Unsupported
  | UndocumentedError(string)

WebAppAPI.Events.accelerometerFailedEvent

type accelerometerFailedEvent = {
  error: accelerometerFailedError,
}

WebAppAPI.Events.accelerometerFailed

type accelerometerFailed = accelerometerFailedEvent => unit

WebAppAPI.Events.deviceOrientationStarted

type deviceOrientationStarted = unit => unit

WebAppAPI.Events.deviceOrientationStopped

type deviceOrientationStopped = unit => unit

WebAppAPI.Events.deviceOrientationChanged

type deviceOrientationChanged = unit => unit

WebAppAPI.Events.deviceOrientationFailedError

@unboxed
type deviceOrientationFailedError =
  | @as("UNSUPPORTED") Unsupported
  | UndocumentedError(string)

WebAppAPI.Events.deviceOrientationFailedEvent

type deviceOrientationFailedEvent = {
  error: deviceOrientationFailedError,
}

WebAppAPI.Events.deviceOrientationFailed

type deviceOrientationFailed = deviceOrientationFailedEvent => unit

WebAppAPI.Events.gyroscopeStarted

type gyroscopeStarted = unit => unit

WebAppAPI.Events.gyroscopeStopped

type gyroscopeStopped = unit => unit

WebAppAPI.Events.gyroscopeChanged

type gyroscopeChanged = unit => unit

WebAppAPI.Events.gyroscopeFailedError

@unboxed
type gyroscopeFailedError =
  | @as("UNSUPPORTED") Unsupported
  | UndocumentedError(string)

WebAppAPI.Events.gyroscopeFailedEvent

type gyroscopeFailedEvent = {error: gyroscopeFailedError}

WebAppAPI.Events.gyroscopeFailed

type gyroscopeFailed = gyroscopeFailedEvent => unit

WebAppAPI.Events.locationManagerUpdated

type locationManagerUpdated = unit => unit

WebAppAPI.Events.locationRequestedEvent

type locationRequestedEvent = {
  locationData: TelegramWebApp.LocationManager.locationData,
}

WebAppAPI.Events.locationRequested

type locationRequested = locationRequestedEvent => unit

WebAppAPI.Events.shareMessageSent

type shareMessageSent = unit => unit

WebAppAPI.Events.shareMessageError

@unboxed
type shareMessageError =
  | @as("UNSUPPORTED") Unsupported
  | @as("MESSAGE_EXPIRED") MessageExpired
  | @as("MESSAGE_SEND_FAILED") MessageSendFailed
  | @as("USER_DECLINED") UserDeclined
  | @as("UNKNOWN_ERROR") UnknownError
  | UndocumentedError(string)

WebAppAPI.Events.shareMessageFailedEvent

type shareMessageFailedEvent = {error: shareMessageError}

WebAppAPI.Events.shareMessageFailed

type shareMessageFailed = shareMessageFailedEvent => unit

WebAppAPI.Events.emojiStatusError

@unboxed
type emojiStatusError =
  | @as("UNSUPPORTED") Unsupported
  | @as("SUGGESTED_EMOJI_INVALID") SuggestedEmojiInvalid
  | @as("DURATION_INVALID") DurationInvalid
  | @as("USER_DECLINED") UserDeclined
  | @as("SERVER_ERROR") ServerError
  | @as("UNKNOWN_ERROR") UnknownError
  | UndocumentedError(string)

WebAppAPI.Events.emojiStatusFailedEvent

type emojiStatusFailedEvent = {error: emojiStatusError}

WebAppAPI.Events.emojiStatusSet

type emojiStatusSet = unit => unit

WebAppAPI.Events.emojiStatusFailed

type emojiStatusFailed = emojiStatusFailedEvent => unit

WebAppAPI.Events.emojiStatusAccessStatus

@unboxed
type emojiStatusAccessStatus =
  | @as("allowed") Allowed
  | @as("cancelled") Cancelled
  | UndocumentedError(string)

WebAppAPI.Events.emojiStatusAccessRequestedEvent

type emojiStatusAccessRequestedEvent = {
  status: emojiStatusAccessStatus,
}

WebAppAPI.Events.emojiStatusAccessRequested

type emojiStatusAccessRequested = emojiStatusAccessRequestedEvent => unit

WebAppAPI.Events.fileDownloadStatus

@unboxed
type fileDownloadStatus =
  | @as("downloading") Downloading
  | @as("cancelled") Cancelled
  | UndocumentedError(string)

WebAppAPI.Events.fileDownloadRequestedEvent

type fileDownloadRequestedEvent = {
  status: fileDownloadStatus,
}

WebAppAPI.Events.fileDownloadRequested

type fileDownloadRequested = fileDownloadRequestedEvent => unit

Global

Global.telegramWebApp

A reference to global Telegram.WebApp object.

Assumes <script src="https://telegram.org/js/telegram-web-app.js?59"></script> is connectede beforehand.

let telegramWebApp: TelegramWebApp.WebApp.t

Accelerometer

Accelerometer.t

type t = {isStarted: bool, x: float, y: float, z: float}

AccelerometerAPI

AccelerometerAPI.accelerometerStartParams

type accelerometerStartParams = {refresh_rate?: int}

AccelerometerAPI.start

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.

let start: (
  TelegramWebApp.Accelerometer.t,
  accelerometerStartParams,
  ~callback: bool => unit=?,
) => TelegramWebApp.Accelerometer.t

AccelerometerAPI.stop

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.

let stop: (
  TelegramWebApp.Accelerometer.t,
  ~callback: bool => unit=?,
) => TelegramWebApp.Accelerometer.t

BackButton

BackButton.t

type t = {mutable isVisible: bool}

BackButtonAPI

BackButtonAPI.onClick

A method that sets the button press event handler. An alias for Telegram.WebApp.onEvent('backButtonClicked', callback)

let onClick: (
  TelegramWebApp.BackButton.t,
  ~callback: unit => unit,
) => TelegramWebApp.BackButton.t

BackButtonAPI.offClick

A method that removes the button press event handler. An alias for Telegram.WebApp.offEvent('backButtonClicked', callback)

let offClick: (
  TelegramWebApp.BackButton.t,
  ~callback: unit => unit,
) => TelegramWebApp.BackButton.t

BackButtonAPI.show

A method to make the button active and visible.

let show: TelegramWebApp.BackButton.t => TelegramWebApp.BackButton.t

BackButtonAPI.hide

A method to hide the button.

let hide: TelegramWebApp.BackButton.t => TelegramWebApp.BackButton.t

BiometricManager

BiometricManager.t

type t = {
  isInited: bool,
  isBiometricAvailable: bool,
  biometricType: string,
  isAccessRequested: bool,
  isAccessGranted: bool,
  isBiometricTokenSaved: bool,
  deviceId: string,
}

BiometricManagerAPI

BiometricManagerAPI.init

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.

let init: (
  TelegramWebApp.BiometricManager.t,
  ~callback: unit => unit=?,
) => TelegramWebApp.BiometricManager.t

BiometricManagerAPI.biometricRequestAccessParams

type biometricRequestAccessParams = {reason?: string}

BiometricManagerAPI.requestAccess

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.

let requestAccess: (
  TelegramWebApp.BiometricManager.t,
  biometricRequestAccessParams,
  ~callback: bool => unit=?,
) => TelegramWebApp.BiometricManager.t

BiometricManagerAPI.biometricAuthenticateParams

type biometricAuthenticateParams = {reason?: string}

BiometricManagerAPI.authenticate

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.

let authenticate: (
  TelegramWebApp.BiometricManager.t,
  biometricAuthenticateParams,
  ~callback: (bool, string) => unit=?,
) => TelegramWebApp.BiometricManager.t

BiometricManagerAPI.updateBiometricToken

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.

let updateBiometricToken: (
  TelegramWebApp.BiometricManager.t,
  string,
  ~callback: bool => unit=?,
) => TelegramWebApp.BiometricManager.t

BiometricManagerAPI.openSettings

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)

let openSettings: TelegramWebApp.BiometricManager.t => TelegramWebApp.BiometricManager.t

BottomButton

BottomButton.bottomButtonType

type bottomButtonType =
  | @as("main") Main
  | @as("secondary") Secondary

BottomButton.bottomButtonPosition

type bottomButtonPosition =
  | @as("left") Left
  | @as("right") Right
  | @as("top") Top
  | @as("bottom") Bottom

BottomButton.t

type t = {
  type_: bottomButtonType,
  mutable text: string,
  mutable color: string,
  mutable textColor: string,
  mutable isVisible: bool,
  mutable isActive: bool,
  mutable hasShineEffect: bool,
  mutable position: option<bottomButtonPosition>,
  isProgressVisible: bool,
}

BottomButtonAPI

BottomButtonAPI.setText

A method to set the button text.

let setText: (
  TelegramWebApp.BottomButton.t,
  string,
) => TelegramWebApp.BottomButton.t

BottomButtonAPI.onClick

A method that sets the button's press event handler. An alias for Telegram.WebApp.onEvent('mainButtonClicked', callback)

let onClick: (
  TelegramWebApp.BottomButton.t,
  ~callback: unit => unit,
) => TelegramWebApp.BottomButton.t

BottomButtonAPI.offClick

A method that removes the button's press event handler. An alias for Telegram.WebApp.offEvent('mainButtonClicked', callback)

let offClick: (
  TelegramWebApp.BottomButton.t,
  ~callback: unit => unit,
) => TelegramWebApp.BottomButton.t

BottomButtonAPI.show

A method to make the button visible. Note that opening the Mini App from the attachment menu hides the main button until the user interacts with the Mini App interface.

let show: TelegramWebApp.BottomButton.t => TelegramWebApp.BottomButton.t

BottomButtonAPI.hide

A method to hide the button.

let hide: TelegramWebApp.BottomButton.t => TelegramWebApp.BottomButton.t

BottomButtonAPI.enable

A method to enable the button.

let enable: TelegramWebApp.BottomButton.t => TelegramWebApp.BottomButton.t

BottomButtonAPI.disable

A method to disable the button.

let disable: TelegramWebApp.BottomButton.t => TelegramWebApp.BottomButton.t

BottomButtonAPI.showProgress

A method to show a loading indicator on the button.

It is recommended to display loading progress if the action tied to the button may take a long time. By default, the button is disabled while the action is in progress. If the parameter leaveActive=true is passed, the button remains enabled.

let showProgress: (
  TelegramWebApp.BottomButton.t,
  bool,
) => TelegramWebApp.BottomButton.t

BottomButtonAPI.hideProgress

A method to hide the loading indicator.

let hideProgress: TelegramWebApp.BottomButton.t => TelegramWebApp.BottomButton.t

BottomButtonAPI.params

type params = {
  text?: string,
  color?: string,
  text_color?: string,
  has_shine_effect?: bool,
  position?: TelegramWebApp.BottomButton.bottomButtonPosition,
  is_active?: bool,
  is_visible?: bool,
}

BottomButtonAPI.setParams

A method to set the button parameters. The params parameter is an object containing one or several fields that need to be changed.

let setParams: (
  TelegramWebApp.BottomButton.t,
  params,
) => TelegramWebApp.BottomButton.t

CloudStorage

CloudStorage.t

type t

CloudStorageAPI

CloudStorageAPI.cloudStorageError

@unboxed
type cloudStorageError =
  | @as("UNKNOWN_ERROR") UnknownError
  | UndocumentedError(string)

CloudStorageAPI.setItem

A method that stores a value in the cloud storage using the specified key. The key should contain 1-128 characters, only A-Z, a-z, 0-9, _ and - are allowed. The value should contain 0-4096 characters. You can store up to 1024 keys in the cloud 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 the value was stored.

let setItem: (
  TelegramWebApp.CloudStorage.t,
  string,
  string,
  ~callback: (
    Null.t<cloudStorageError>,
    option<bool>,
  ) => unit=?,
) => TelegramWebApp.CloudStorage.t

CloudStorageAPI.getItem

A method that receives a value from the cloud storage using the specified key. The key should contain 1-128 characters, only A-Z, a-z, 0-9, _ and - are allowed. 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.

let getItem: (
  TelegramWebApp.CloudStorage.t,
  string,
  ~callback: (
    Null.t<cloudStorageError>,
    option<string>,
  ) => unit,
) => TelegramWebApp.CloudStorage.t

CloudStorageAPI.getItems

A method that receives values from the cloud storage using the specified keys. The keys should contain 1-128 characters, only A-Z, a-z, 0-9, _ and - are allowed. 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 values will be passed as the second argument.

let getItems: (
  TelegramWebApp.CloudStorage.t,
  array<string>,
  ~callback: (
    Null.t<cloudStorageError>,
    option<array<string>>,
  ) => unit,
) => TelegramWebApp.CloudStorage.t

CloudStorageAPI.removeItem

let removeItem: (
  TelegramWebApp.CloudStorage.t,
  string,
  ~callback: (
    Null.t<cloudStorageError>,
    option<bool>,
  ) => unit,
) => TelegramWebApp.CloudStorage.t

CloudStorageAPI.removeItems

A method that removes values from the cloud storage using the specified keys. The keys should contain 1-128 characters, only A-Z, a-z, 0-9, _ and - are allowed. 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 values were removed.

let removeItems: (
  TelegramWebApp.CloudStorage.t,
  array<string>,
  ~callback: (
    Null.t<cloudStorageError>,
    option<bool>,
  ) => unit,
) => TelegramWebApp.CloudStorage.t

CloudStorageAPI.getKeys

A method that receives the list of all keys stored in the cloud storage. 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 list of keys will be passed as the second argument.

let getKeys: (
  TelegramWebApp.CloudStorage.t,
  ~callback: (
    Null.t<cloudStorageError>,
    option<array<string>>,
  ) => unit,
) => TelegramWebApp.CloudStorage.t

DeviceOrientation

DeviceOrientation.t

type t = {
  isStarted: bool,
  absolute: bool,
  alpha: float,
  beta: float,
  gamma: float,
}

DeviceOrientationAPI

DeviceOrientationAPI.deviceOrientationStartParams

type deviceOrientationStartParams = {
  refresh_rate?: int,
  need_absolute?: bool,
}

DeviceOrientationAPI.start

Starts tracking device orientation data using params of type DeviceOrientationStartParams. If an optional callback parameter is provided, the callback function will be called with a boolean indicating whether tracking was successfully started.

let start: (
  TelegramWebApp.DeviceOrientation.t,
  deviceOrientationStartParams,
  ~callback: bool => unit=?,
) => TelegramWebApp.DeviceOrientation.t

DeviceOrientationAPI.stop

Stops tracking device orientation data. If an optional callbackparameter is provided, the callback function will be called with a boolean indicating whether tracking was successfully stopped.

let stop: (
  TelegramWebApp.DeviceOrientation.t,
  ~callback: bool => unit=?,
) => TelegramWebApp.DeviceOrientation.t

DeviceStorage

DeviceStorage.t

type t

DeviceStorageAPI

DeviceStorageAPI.deviceStorageError

@unboxed
type deviceStorageError =
  | @as("UNKNOWN_ERROR") UnknownError
  | UndocumentedError(string)

DeviceStorageAPI.setItem

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.

let setItem: (
  TelegramWebApp.DeviceStorage.t,
  string,
  string,
  ~callback: (
    Null.t<deviceStorageError>,
    option<bool>,
  ) => unit=?,
) => TelegramWebApp.DeviceStorage.t

DeviceStorageAPI.getItem

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.

let getItem: (
  TelegramWebApp.DeviceStorage.t,
  string,
  ~callback: (
    Null.t<deviceStorageError>,
    option<string>,
  ) => unit,
) => TelegramWebApp.DeviceStorage.t

DeviceStorageAPI.removeItem

A method that removes a value from the device's local storage using the specified key. If an optional callback parameter was passed, the callbackfunction 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.

let removeItem: (
  TelegramWebApp.DeviceStorage.t,
  string,
  ~callback: (
    Null.t<deviceStorageError>,
    option<bool>,
  ) => unit=?,
) => TelegramWebApp.DeviceStorage.t

DeviceStorageAPI.clear

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 callbackfunction 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.

let clear: (
  TelegramWebApp.DeviceStorage.t,
  ~callback: (
    Null.t<deviceStorageError>,
    option<bool>,
  ) => unit=?,
) => TelegramWebApp.DeviceStorage.t

Gyroscope

Gyroscope.t

type t = {isStarted: bool, x: float, y: float, z: float}

GyroscopeAPI

GyroscopeAPI.gyroscopeStartParams

type gyroscopeStartParams = {refresh_rate?: int}

GyroscopeAPI.start

Starts tracking gyroscope data using params of type GyroscopeStartParams. If an optional callback parameter is provided, the callbackfunction will be called with a boolean indicating whether tracking was successfully started.

let start: (
  TelegramWebApp.Gyroscope.t,
  gyroscopeStartParams,
  ~callback: bool => unit=?,
) => TelegramWebApp.Gyroscope.t

GyroscopeAPI.stop

Stops tracking gyroscope data. If an optional callback parameter is provided, the callback function will be called with a boolean indicating whether tracking was successfully stopped.

let stop: (
  TelegramWebApp.Gyroscope.t,
  ~callback: bool => unit=?,
) => TelegramWebApp.Gyroscope.t

HapticFeedback

HapticFeedback.t

type t

HapticFeedbackAPI

HapticFeedbackAPI.impactStyle

type impactStyle =
  | @as("light") Light
  | @as("medium") Medium
  | @as("heavy") Heavy
  | @as("rigid") Rigid
  | @as("soft") Soft

HapticFeedbackAPI.impactOccurred

A method tells that an impact occurred. The Telegram app may play the appropriate haptics based on style value passed.

let impactOccurred: (TelegramWebApp.HapticFeedback.t, impactStyle) => unit

HapticFeedbackAPI.notificationType

type notificationType =
  | @as("error") Error
  | @as("success") Success
  | @as("warning") Warning

HapticFeedbackAPI.notificationOccurred

A method tells that a task or action has succeeded, failed, or produced a warning. The Telegram app may play the appropriate haptics based on type value passed.

let notificationOccurred: (TelegramWebApp.HapticFeedback.t, notificationType) => unit

HapticFeedbackAPI.selectionChanged

A method tells that the user has changed a selection. The Telegram app may play the appropriate haptics.

Do not use this feedback when the user makes or confirms a selection; use it only when the selection changes.

let selectionChanged: (TelegramWebApp.HapticFeedback.t, notificationType) => unit

LocationManager

LocationManager.t

type t = {
  isInited: bool,
  isLocationAvailable: bool,
  isAccessRequested: bool,
  isAccessGranted: bool,
}

LocationManager.locationData

type locationData = {
  latitude: float,
  longitude: float,
  altitude: float,
  course: float,
  speed: float,
  horizontal_accuracy: float,
  vertical_accuracy: float,
  course_accuracy: float,
  speed_accuracy: float,
}

LocationManagerAPI

LocationManagerAPI.init

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.

let init: (
  TelegramWebApp.LocationManager.t,
  ~callback: unit => unit=?,
) => TelegramWebApp.LocationManager.t

LocationManagerAPI.getLocation

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.

let getLocation: (
  TelegramWebApp.LocationManager.t,
  ~callback: TelegramWebApp.LocationManager.locationData => unit,
) => TelegramWebApp.LocationManager.t

LocationManagerAPI.openSetting

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)."

let openSetting: TelegramWebApp.LocationManager.t => TelegramWebApp.LocationManager.t

SecureStorage

SecureStorage.t

type t

SecureStorageAPI

SecureStorageAPI.secureStorageError

@unboxed
type secureStorageError =
  | @as("UNKNOWN_ERROR") UnknownError
  | UndocumentedError(string)

SecureStorageAPI.setItem

A method that stores a value in the device's secure 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.

let setItem: (
  TelegramWebApp.SecureStorage.t,
  string,
  string,
  ~callback: (
    Null.t<secureStorageError>,
    option<bool>,
  ) => unit=?,
) => TelegramWebApp.SecureStorage.t

SecureStorageAPI.getItem

A method that receives a value from the device's secure 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. If the key was not found, the second argument will be null, and the third argument will be a boolean indicating whether the key can be restored from the current device.

let getItem: (
  TelegramWebApp.SecureStorage.t,
  string,
  ~callback: (
    Null.t<secureStorageError>,
    option<string>,
  ) => unit,
) => TelegramWebApp.SecureStorage.t

SecureStorageAPI.restoreItem

Attempts to restore a key that previously existed on the current device. When called, the user will be asked for permission to restore the value. If the user declines or an error occurs, the first argument in the callback will contain the error. If restored successfully, the first argument will be null and the second argument will contain the restored value.

let restoreItem: (
  TelegramWebApp.SecureStorage.t,
  string,
  ~callback: (
    Null.t<secureStorageError>,
    option<string>,
  ) => unit=?,
) => TelegramWebApp.SecureStorage.t

SecureStorageAPI.removeItem

A method that removes a value from the device's secure storage using the specified key. If an optional callback parameter was passed, the callbackfunction 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.

let removeItem: (
  TelegramWebApp.SecureStorage.t,
  string,
  ~callback: (
    Null.t<secureStorageError>,
    option<bool>,
  ) => unit=?,
) => TelegramWebApp.SecureStorage.t

SecureStorageAPI.clear

A method that clears all keys previously stored by the bot in the device's secure storage. If an optional callback parameter was passed, the callbackfunction 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.

let clear: (
  TelegramWebApp.SecureStorage.t,
  ~callback: (
    Null.t<secureStorageError>,
    option<bool>,
  ) => unit=?,
) => TelegramWebApp.SecureStorage.t

SettingsButton

SettingsButton.t

type t = {mutable isVisible: bool}

SettingsButtonAPI

SettingsButtonAPI.onClick

A method that sets the press event handler for the Settings item in the context menu. An alias for Telegram.WebApp.onEvent('settingsButtonClicked', callback)

let onClick: (
  TelegramWebApp.SettingsButton.t,
  ~callback: unit => unit,
) => TelegramWebApp.SettingsButton.t

SettingsButtonAPI.offClick

A method that removes the press event handler from the Settings item in the context menu. An alias for Telegram.WebApp.offEvent('settingsButtonClicked', callback)

let offClick: (
  TelegramWebApp.SettingsButton.t,
  ~callback: unit => unit,
) => TelegramWebApp.SettingsButton.t

SettingsButtonAPI.show

A method to make the Settings item in the context menu visible.

let show: TelegramWebApp.SettingsButton.t => TelegramWebApp.SettingsButton.t

SettingsButtonAPI.hide

A method to hide the Settings item in the context menu.

let hide: TelegramWebApp.SettingsButton.t => TelegramWebApp.SettingsButton.t