<p>When interacting with HTML5 games and the websites of payment gateways, Telegram apps should expose APIs to allow receiving data and events from the websites.</p>
<p>Games and payment gateways can generate events that are meant to be received by the Telegram apps.<br>Typically events are generated by using the <code>postEvent</code> method of the <ahref="https://github.com/TelegramMessenger/GamingCommunication/blob/master/games.js">GamingCommunication library</a>.<br>The <code>postEvent</code> function will try sending the event to the Telegram app in a number of different ways.</p>
<p>In mobile apps, the event receiver API should be typically exposed as a <code>window.TelegramWebviewProxy</code> object with a <code>postEvent</code> method.</p>
<p>Finally, web MTProto clients that need to open a game or process a payment in an iframe can use the <ahref="https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage">postMessage API</a> to receive events from iframes.<br>The <ahref="https://github.com/TelegramMessenger/GamingCommunication/blob/master/games.js">GamingCommunication library</a> by default will use <code>'*'</code> as <code>targetOrigin</code>, sending messages to parent pages regardless of the origin of the embedder.</p>
<p><code>eventType</code> is a simple string indicating the event type, and <code>eventData</code> is a payload with an object that will be parsed by the Telegram app.</p>
<tableclass="table">
<thead>
<tr>
<th>eventType</th>
<th>eventData</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>payment_form_submit</code></td>
<td>JSON object with <code>data</code> and <code>title</code> fields</td>
<td><code>title</code> is the censored credit card title.<br><code>data</code> is a service-specific JSON payload with information about the payment credentials provided by the user to the payment system.<br><strong>Neither Telegram, nor bots will have access to your credit card information.</strong><br>Credit card details will be handled only by the payment system.</td>
</tr>
<tr>
<td><code>share_score</code></td>
<td>null</td>
<td>Will be called by games when the user explicitly clicks on the <strong>share score</strong> button to share the game, along with his score.<br>Typically done by using <ahref="/method/messages.forwardMessages">messages.forwardMessages</a> on the game message with the <code>with_my_score</code> flag.</td>
<td>Will be called by games when the user explicitly clicks on the <strong>share game</strong> button to share the game, without sharing his score.<br>Typically done by using <ahref="/method/messages.forwardMessages">messages.forwardMessages</a> on the game message without the <code>with_my_score</code> flag, or by sharing the game's short URL.</td>
<td>Can be called by games when the user loses a game</td>
</tr>
<tr>
<td><code>game_loaded</code></td>
<td>null</td>
<td>Can be called by games once the game fully loads</td>
</tr>
<tr>
<td><code>resize_frame</code></td>
<td>JSON object with <code>height</code> field</td>
<td>Called by supported pages inside of <ahref="https://instantview.telegram.org">IV</a> iframe embeds, indicates the new size of the embed frame.</td>