Frontend rule: read initData (the raw signed string) and send it to your backend for verification. initDataUnsafe is for UI display only and is never proof of identity.
Overview
Choose an entry point
After an enabled MiniApp opens inside MPChat, the browser SDK exposes its launch data.
A direct link uses
https://mp.net/{botUsername}/{shortName}and can carry?startapp=.A
sendMessageinlineweb_appbutton normally opens the bot's enabled MiniApp in private chat. For this MiniApp share in a group or supergroup the bot has joined, the keyboard must contain exactly one row and one button. That button may contain onlytextandweb_app.A Reply Keyboard
web_appbutton is for private chats. The chat menu is configured separately withsetChatMenuButtonand accepts a valid HTTPS URL up to 2048 characters. An external menu URL may not have MiniApp launch data.
Send a single inline entry button
Use the bot's registered entryUrl or its full MPChat direct link. The request uses web_app.url to identify the MiniApp. The JSON below also has the required button shape for a group the bot has joined.
{
"chat_id": "987654321",
"text": "Open Demo MiniApp",
"reply_markup": {
"inline_keyboard": [[
{ "text": "Open", "web_app": { "url": "https://mp.net/MyBot/demo" } }
]]
}
}
Load the browser SDK
This script runs in the MiniApp page. The Node.js Bot SDK runs on your server and is a separate package. Keep the bot token on that server.
<script src="https://mp.net/i/mpchat-web-app.js"></script>
const initData = window.MpChat.WebApp.initData; // signed string -> backend
const initDataUnsafe = window.MpChat.WebApp.initDataUnsafe; // UI only, untrusted
initData vs initDataUnsafe
Value | Use for authorization? |
initData (raw signed string) | Yes — after backend verification. |
initDataUnsafe (parsed object) | No — UI display only. |
Field support (current phase)
Signed launch data:
initDatauses keys such asquery_id,auth_date,chat_type, andstart_param. The parsedinitDataUnsafemay expose camelCase fields such asqueryId,authDate,chatType, andstartParamfor display.Partially supported: the
initDataUnsafeobject structure anduser/chatsubsets.Not supported yet: runtime metadata, view state, native UI controls (BackButton/MainButton), storage/device APIs, and methods like
sendData,openLink, popups, QR — do not rely on MiniApp→BotsendData/web_app_datareturn flows. Message-button callbacks are a separate, supported path.
Security must-dos
Never put the bot token in frontend code, WebView storage, URLs, logs, or analytics.
Send the raw
initDatato the backend and verify before trusting any field.
Related
Only call native methods via window.MpChat.WebApp.call(name, params) when your MPChat client version explicitly announces support.
