diff --git a/docs.json b/docs.json index 96339f2c9..91741a2b5 100644 --- a/docs.json +++ b/docs.json @@ -226,6 +226,7 @@ "group": "TMA: Telegram Mini Apps", "pages": [ "ecosystem/tma/overview", + "ecosystem/tma/apps-communication", "ecosystem/tma/create-mini-app", { "group": "Telegram UI", diff --git a/ecosystem/tma/apps-communication.mdx b/ecosystem/tma/apps-communication.mdx new file mode 100644 index 000000000..ce9800721 --- /dev/null +++ b/ecosystem/tma/apps-communication.mdx @@ -0,0 +1,120 @@ +--- +title: "Apps communication" +--- + +import { Aside } from '/snippets/aside.jsx'; + +The Telegram client and a Mini App communicate through a message-passing interface. The exact transport depends on the platform, but the protocol is the same: the Mini App sends **methods** to the Telegram client, and the Telegram client sends **events** back to the Mini App. + +## Methods and events + +Two terms describe the communication directions: + +- **Methods** — calls sent from the Mini App to the Telegram client. A method triggers an action in the native app (for example, showing a popup or expanding the viewport). +- **Events** — signals sent from the Telegram client to the Mini App. An event notifies the Mini App that something happened (for example, the viewport changed or a button was pressed). + +Internally both are messages, but "methods" and "events" distinguish the direction throughout the Mini Apps platform. + +## Transport by platform + +The transport mechanism varies by Telegram client: + +| Platform | Transport | Details | +| -------------------------------------------------- | --------------------------------------- | ------------------------------------------------------------------------------------ | +| Web (Telegram Web A, Web K) | `window.parent.postMessage` | The Mini App runs in an `