Skip to content

Init Data

When a Mini App launches, the client passes a signed initialization data string through Telegram.WebApp.initData. This string contains information about the user, chat, and launch parameters.

Telegram.WebApp.initDataUnsafe provides the parsed WebAppInitData object for convenient client-side access.

Security Notice

Data in initDataUnsafe has not been server-side verified and should only be used for client-side display. Business-critical data must be verified on the server using the raw initData string through signature validation.

WebAppInitData

Initialization data object, accessed via Telegram.WebApp.initDataUnsafe.

FieldTypeDescription
query_idStringUnique query ID for answerWebAppQuery
userWebAppUserCurrent user information
receiverWebAppUserOther user in the conversation (only available in private chats)
chatWebAppChatCurrent chat information (only available in groups/channels)
chat_typeStringChat type: "sender", "private", "group", "supergroup", "channel"
chat_instanceStringUnique identifier of the chat instance
start_paramStringStart parameter passed via link
can_send_afterIntegerEarliest time to call sendData (Unix timestamp)
auth_dateIntegerAuthentication time (Unix timestamp)
hashStringData signature hash for verification
signatureStringData signature for third-party verification. Bot API 8.0+

WebAppUser

User information object.

FieldTypeDescription
idIntegerUser ID
is_botBooleanWhether the user is a bot
first_nameStringFirst name
last_nameStringLast name (optional)
usernameStringUsername (optional)
language_codeStringUser language code (e.g., "zh-hans", "en")
is_premiumBooleanWhether the user is a Premium user (optional)
added_to_attachment_menuBooleanWhether the user has added the bot to attachment menu (optional)
allows_write_to_pmBooleanWhether the user allows the bot to send private messages (optional)
photo_urlStringUser avatar URL (optional)

WebAppChat

Chat information object.

FieldTypeDescription
idIntegerChat ID
typeStringChat type: "group", "supergroup", "channel"
titleStringChat title
usernameStringChat username (optional)
photo_urlStringChat avatar URL (optional)

Usage Example

javascript
const tg = Telegram.WebApp;
const initData = tg.initDataUnsafe;

// Get user info
if (initData.user) {
  console.log('User ID:', initData.user.id);
  console.log('Name:', initData.user.first_name);
  console.log('Language:', initData.user.language_code);
  console.log('Premium:', initData.user.is_premium);
}

// Get chat info
if (initData.chat) {
  console.log('Chat ID:', initData.chat.id);
  console.log('Chat title:', initData.chat.title);
}

// Get start parameter
if (initData.start_param) {
  console.log('Start param:', initData.start_param);
  handleStartParam(initData.start_param);
}

// Send raw data to server for validation
fetch('/api/auth', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ initData: tg.initData })
});

initData Query String Format

Telegram.WebApp.initData is a URL-encoded query string containing the following parameters:

query_id=AAHd...&user=%7B%22id%22%3A123...%7D&auth_date=1234567890&hash=abc123...

When parsed, it contains the following key-value pairs:

KeyValue
query_idQuery ID string
userJSON-encoded user object
receiverJSON-encoded receiver object
chatJSON-encoded chat object
chat_typeChat type string
chat_instanceChat instance ID
start_paramStart parameter
can_send_afterAllowed send timestamp
auth_dateAuthentication timestamp
hashHMAC-SHA256 signature
signatureEd25519 signature

For detailed validation methods, see Data Validation.