Skip to content

Events

Mini Apps communicate with the client through an event system. Use Telegram.WebApp.onEvent() to subscribe and Telegram.WebApp.offEvent() to unsubscribe.

javascript
// Subscribe to event
Telegram.WebApp.onEvent(eventType, eventHandler);

// Unsubscribe
Telegram.WebApp.offEvent(eventType, eventHandler);

Lifecycle Events

activated

Triggered when the Mini App enters the active state. Bot API 8.0+

deactivated

Triggered when the Mini App enters the inactive state. Bot API 8.0+

View Events

themeChanged

Triggered when the client theme changes.

javascript
Telegram.WebApp.onEvent('themeChanged', () => {
  console.log('New theme:', Telegram.WebApp.colorScheme);
  console.log('Theme params:', Telegram.WebApp.themeParams);
});

viewportChanged

Triggered when the Mini App viewport size changes.

Callback parameter: Object

FieldTypeDescription
isStateStableBooleanWhether the viewport change has stabilized
javascript
Telegram.WebApp.onEvent('viewportChanged', (event) => {
  if (event.isStateStable) {
    console.log('Viewport height:', Telegram.WebApp.viewportHeight);
  }
});

safeAreaChanged

Triggered when the device safe area changes. Bot API 8.0+

contentSafeAreaChanged

Triggered when the content safe area changes. Bot API 8.0+

fullscreenChanged

Triggered when the fullscreen mode state changes. Bot API 8.0+

fullscreenFailed

Triggered when a fullscreen request fails. Bot API 8.0+

Callback parameter: Object

FieldTypeDescription
errorStringError reason: "UNSUPPORTED" or "ALREADY_FULLSCREEN"

Button Events

backButtonClicked

Triggered when the back button is clicked.

javascript
Telegram.WebApp.onEvent('backButtonClicked', () => {
  window.history.back();
});

mainButtonClicked

Triggered when the main button is clicked.

secondaryButtonClicked

Triggered when the secondary button is clicked. Bot API 7.10+

settingsButtonClicked

Triggered when the settings button is clicked. Bot API 7.0+

Interaction Events

popupClosed

Triggered when a popup is closed.

Callback parameter: Object

FieldTypeDescription
button_idString | nullID of the button clicked by the user, or null if the popup was dismissed

qrTextReceived

Triggered when a QR code is successfully scanned. Bot API 6.9+

Callback parameter: Object

FieldTypeDescription
dataStringScanned text content

scanQrPopupClosed

Triggered when the QR code scanning popup is closed. Bot API 7.7+

clipboardTextReceived

Triggered when clipboard reading is complete. Bot API 6.9+

Callback parameter: Object

FieldTypeDescription
dataString | nullClipboard text content, or null if reading failed

invoiceClosed

Triggered when the invoice payment interface is closed.

Callback parameter: Object

FieldTypeDescription
urlStringInvoice link
statusStringPayment status: "paid", "cancelled", "failed", "pending"

writeAccessRequested

Result of a write access permission request. Bot API 6.9+

Callback parameter: Object

FieldTypeDescription
statusStringResult: "allowed" or "cancelled"

contactRequested

Result of a contact information request. Bot API 6.9+

Callback parameter: Object

FieldTypeDescription
statusStringResult: "sent" or "cancelled"

Sharing Events

shareMessageSent

Triggered when a message is shared successfully. Bot API 8.0+

shareMessageFailed

Triggered when a message sharing fails. Bot API 8.0+

Callback parameter: Object

FieldTypeDescription
errorStringError reason: "UNSUPPORTED", "MESSAGE_EXPIRED", "MESSAGE_SEND_FAILED", "USER_DECLINED"

emojiStatusSet

Triggered when an emoji status is set successfully. Bot API 8.0+

emojiStatusFailed

Triggered when setting an emoji status fails. Bot API 8.0+

Callback parameter: Object

FieldTypeDescription
errorStringError reason: "UNSUPPORTED", "SUGGESTED_EMOJI_INVALID", "DURATION_INVALID", "USER_DECLINED"

emojiStatusAccessRequested

Result of an emoji status permission request. Bot API 8.0+

Callback parameter: Object

FieldTypeDescription
statusStringResult: "allowed" or "cancelled"

fileDownloadRequested

File download request result. Bot API 8.0+

Callback parameter: Object

FieldTypeDescription
statusStringResult: "downloading" or "cancelled"

Sensor Events

accelerometerStarted

Triggered when the accelerometer starts collecting data. Bot API 8.0+

accelerometerStopped

Triggered when the accelerometer stops collecting data. Bot API 8.0+

accelerometerChanged

Triggered when accelerometer data updates. Bot API 8.0+

accelerometerFailed

Triggered when the accelerometer fails to start. Bot API 8.0+

Callback parameter: Object

FieldTypeDescription
errorStringError reason: "UNSUPPORTED"

deviceOrientationStarted

Triggered when the device orientation sensor starts collecting data. Bot API 8.0+

deviceOrientationStopped

Triggered when the device orientation sensor stops collecting data. Bot API 8.0+

deviceOrientationChanged

Triggered when device orientation data updates. Bot API 8.0+

deviceOrientationFailed

Triggered when the device orientation sensor fails to start. Bot API 8.0+

Callback parameter: Object

FieldTypeDescription
errorStringError reason: "UNSUPPORTED"

gyroscopeStarted

Triggered when the gyroscope starts collecting data. Bot API 8.0+

gyroscopeStopped

Triggered when the gyroscope stops collecting data. Bot API 8.0+

gyroscopeChanged

Triggered when gyroscope data updates. Bot API 8.0+

gyroscopeFailed

Triggered when the gyroscope fails to start. Bot API 8.0+

Callback parameter: Object

FieldTypeDescription
errorStringError reason: "UNSUPPORTED"

Location Events

locationManagerUpdated

Triggered when the location manager state updates. Bot API 8.0+

locationRequested

Location request result. Bot API 8.0+

Callback parameter: Object

FieldTypeDescription
locationDataLocationDataLocation data object, null if the request failed

Biometric Events

biometricManagerUpdated

Triggered when the biometric manager state updates. Bot API 7.2+

biometricAuthRequested

Biometric authentication result. Bot API 7.2+

Callback parameter: Object

FieldTypeDescription
isAuthenticatedBooleanWhether authentication was successful
biometricTokenStringToken returned on successful authentication

biometricTokenUpdated

Biometric token update result. Bot API 7.2+

Callback parameter: Object

FieldTypeDescription
isUpdatedBooleanWhether the token was updated successfully

Usage Example

javascript
const tg = Telegram.WebApp;

// Listen to multiple events
tg.onEvent('viewportChanged', (e) => {
  if (e.isStateStable) {
    adjustLayout();
  }
});

tg.onEvent('themeChanged', () => {
  applyTheme(tg.themeParams);
});

tg.onEvent('popupClosed', (e) => {
  if (e.button_id === 'confirm') {
    handleConfirm();
  }
});

tg.onEvent('invoiceClosed', (e) => {
  if (e.status === 'paid') {
    showSuccess();
  }
});