<metaproperty="description"content="Bots can offer users HTML5 games to play solo or to compete against each other in groups and one-on-one chats. ">
<metaproperty="og:title"content="Games">
<metaproperty="og:image"content="">
<metaproperty="og:description"content="Bots can offer users HTML5 games to play solo or to compete against each other in groups and one-on-one chats. ">
<li>The game's short name obtained from <ahref="https://t.me/botfather">@BotFather</a> or from a <ahref="/api/links#game-links">game link »</a> to <code>inputGameShortName.short_name</code></li>
<li>The current bot's info to <code>inputGameShortName.bot_id</code></li>
</ul>
<p>The sent message will contain a <ahref="/constructor/messageMediaGame">messageMediaGame</a> with a <ahref="/constructor/game">game</a>, that can then be used by users to forward the game using sendMedia with <ahref="/constructor/inputGameID">inputGameID</a>.</p>
<h3><aclass="anchor"href="#starting-a-game"id="starting-a-game"name="starting-a-game"><iclass="anchor-icon"></i></a>Starting a game</h3>
<p>Games are started clicking on the button, which triggers an callback query that returns the game URL, for more info <ahref="/api/bots/buttons#callback-queries">see here »</a>.<br>
The game should then be opened in a WebView or in native UI (specified by the <code>native_ui</code> flag), exposing the <ahref="/api/web-events">appropriate HTML5 APIs</a> in order to receive various JS game events directly from the code of the game, as described <ahref="/api/web-events">here »</a>. </p>
<p>Games are supposed to report back to the MTProto API every time the user looses a game with a new highscore.<br>
Since games run in the browser, they cannot directly report data to the API using the bot token, which must be kept secret.<br>
Instead, they should send highscores to an intermediate server, that will then report scores using <ahref="/method/messages.setGameScore">messages.setGameScore</a> or <ahref="/method/messages.setInlineGameScore">messages.setInlineGameScore</a>, depending on the source of the game. </p>
<ul>
<li>The <code>edit_message</code> flag should be set if the game message should be automatically edited to include the current scoreboard</li>
<li>The <code>force</code> flag should be set if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters.</li>
<p>Every time a highscore is reached, and the <code>edit_message</code> flag is set when reporting the score, a <ahref="/constructor/messageService">messageService</a> with a <ahref="/constructor/messageActionGameScore">messageActionGameScore</a> is generated, indicating that the highscore of a certain game has changed, thanks to a certain <code>user_id</code>.<br>
Our own current position of the scoreboard is also reported as <code>pos</code>. </p>
<p>When receiving such an update, graphical clients should refetch the scoreboard using <ahref="/method/messages.getGameHighScores">messages.getGameHighScores</a> or <ahref="/method/messages.getInlineGameHighScores">messages.getInlineGameHighScores</a>.</p></div>
</div>
</div>
</div>
<divclass="footer_wrap">
<divclass="footer_columns_wrap footer_desktop">
<divclass="footer_column footer_column_telegram">
<h5>Telegram</h5>
<divclass="footer_telegram_description"></div>
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.