Skip to content


Events are signals, sent from Telegram native application in case, when some external action was done. Like methods, each event has its unique name and parameters.


As mentioned before, the web version uses a standard way of communication between iframes. It means, the parent iframe is able to send events through window.postMessage function. To handle this type of message, it is enough to add message event listener on the global window object:

window.addEventListener('message', ...);

The native application will send an event with data: string which represents a JSON object converted to string. This object has the same interface as we defined in the Methods section:

interface MessageJSON {
  eventType: string;
  eventData: any;

Then, lets imagine how we could process an event from Telegram application:

window.addEventListener('message', ({ data }) => {
  const { eventType, eventData } = JSON.parse(data);
  console.log(eventType, eventData);


In this code, we assumed, that the message event is sent only by the native application which is not always true in real applications. Additionally, we didn't check if data is really of type string. Don't forget to check each type and appropriately process incoming events.

Desktop, Mobile and Windows Phone

Desktop, mobile, and Windows Phone versions of Telegram don’t use the method, described in the previous section. They do it in a bit unusual way. The first thing developer should know, is in case, when Telegram needs to emit an event, it will insert JavaScript code, which calls a globally defined function.

Here is an example:

window.Telegram.WebView.receiveEvent('popup_closed', {
  button_id: 'cancel'

Path to this function depends on platform:

  • window.TelegramGameProxy.receiveEvent - Telegram Desktop;
  • window.Telegram.WebView.receiveEvent - Telegram for iOS and Android;
  • window.TelegramGameProxy_receiveEvent - Windows Phone

All of these functions have the same signature:

type ReceiveEvent = (eventType: string, eventData: unknown) => void;

So, the solution is rather simple. To handle incoming events we should create a function of this type and assign it to all 3 paths.

Listening to Events

Handling all possible environments for a developer's application can be challenging. To simplify this process, the community developed the @tma.js/sdk package, which greatly eases integration.

Here's how to use it:

import { on } from '@tma.js/sdk';

// Start listening to "viewport_changed" event. Returned value
// is a function, which removes this event listener.
const removeListener = on('viewport_changed', payload => {
  console.log('Viewport changed:', payload);

// Remove this event listener.

You can learn more about calling methods in the package's documentation.

Available Events

This section contains the list of events, sent from Telegram: their names, description, and parameters. Section title means minimal version, from which events inside the section could be sent.


Available since: v6.1

User clicked the Back Button.


Available since: v7.2

Biometry authentication request completed. This event usually occurs in a response to the web_app_request_auth method.

If authentication was successful, the event contains a token from the local secure storage.

status'failed' or 'authorized'Authentication status.
tokenstringOptional. Token from the local secure storage saved previously. Passed only if status is authorized.


Available since: v7.2

Biometry settings were received.

availablebooleanShows whether biometry is available.
access_requestedbooleanShows whether permission to use biometrics has been requested.
access_grantedbooleanShows whether permission to use biometrics has been granted.
device_idstringA unique device identifier that can be used to match the token to the device.
token_savedbooleanShow whether local secure storage contains previously saved token.
type'face' or 'finger'The type of biometrics currently available on the device.


Available since: v7.2

Biometry token was updated.

statusupdated or removedUpdate status.


Available since: v6.4

Telegram application attempted to extract text from clipboard.

req_idstringPassed during the web_app_read_text_from_clipboard method invocation req_id value.
datastring or nullOptional. Data extracted from the clipboard. The returned value will have the type string only in the case, application has access to the clipboard.


Available since: v6.9

Custom method invocation completed.

req_idstringUnique identifier of this invocation.
resultunknownOptional. Method invocation successful result.
errorstringOptional. Method invocation error code.


An invoice was closed.

slugstring Passed during the  web_app_open_invoice  method invocation slug value.
statusstring Invoice status. Values:
  • paid, invoice was paid
  • failed, invoice failed
  • pending, invoice is currently pending
  • cancelled, invoice was cancelled


User clicked the Main Button.


Available since: v6.9

Application received phone access request status.

statusstringRequest status. Can only be sent.

Popup was closed.

button_idstringOptional. Identifier of the clicked button. In case, the popup was closed without clicking any button, this property will be omitted.


Parent iframe requested current iframe reload.


Available since: v6.4

The QR scanner scanned some QR and extracted its content.

datastringOptional. Data extracted from the QR.


Available since: v6.4

QR scanner was closed.


The event which is usually sent by the Telegram web application. Its payload represents <style/> tag html content, a developer could use. The stylesheet described in the payload will help the developer to stylize the app scrollbar (but he is still able to do it himself).


Available since: v6.1

Occurs when the Settings Button was pressed.


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

theme_paramsRecord<string, string>Map where the key is a theme stylesheet key and value is the corresponding color in #RRGGBB format.


Occurs whenever the viewport has been changed. For example, when the user started dragging the application or called the expansion method.

heightnumberThe viewport height.
widthnumberOptional. The viewport width.
is_expandedbooleanIs the viewport currently expanded.
is_state_stablebooleanIs the viewport current state stable and not going to change in the next moment.


Pay attention to the fact, that send rate of this method is not enough to smoothly resize the application window. You should probably use a stable height instead of the current one, or handle this problem in another way.


Available since: v6.9

Application received write access request status.

statusstringRequest status. Can only be allowed.

Released under the MIT License.