Mini Apps
Use TelegramMiniAppInitDataValidator to validate Telegram.WebApp.initData on your server before trusting Mini App user, chat, or start-parameter values.
Official reference:
The helper validates Telegram's bot-token HMAC flow:
parse the raw query string from
Telegram.WebApp.initDataremove the
hashfieldsort remaining fields alphabetically
build the
key=valuedata-check-string joined by line feedsderive the secret key with
HMAC_SHA256(bot_token, "WebAppData")compare the calculated SHA-256 hex digest with Telegram's
hashusing a constant-time comparisonoptionally reject stale data with
auth_dateandmaxAgeSeconds
Do not send Telegram.WebApp.initDataUnsafe to the backend. The frontend should send the raw Telegram.WebApp.initData string.
Laravel Controller
The validator is registered in the Laravel container, so controllers, actions, services, and jobs can use constructor injection:
Use the same helper with tenant-owned bots by passing the tenant token resolved by the host application:
Framework-Agnostic Usage
The validator does not depend on Laravel:
Use isValid() when a boolean result fits better than exception handling:
Accessors
validate() returns TelegramMiniAppInitData.
Common accessors:
raw()fields()hash()signature()queryId()user()receiver()chat()chatType()chatInstance()startParam()canSendAfter()authDate()toArray()
user() and receiver() return TelegramMiniAppUserData with accessors such as id(), firstName(), lastName(), username(), languageCode(), isPremium(), addedToAttachmentMenu(), allowsWriteToPm(), and photoUrl().
chat() returns TelegramMiniAppChatData with id(), type(), title(), username(), and photoUrl().
Keep raw access available with fields() and toArray() when Telegram adds Mini App fields before the SDK adds dedicated accessors.
Third-Party Validation
Telegram also documents Ed25519-based third-party validation using the signature field and Telegram's public keys. This package validates Mini App init data with the bot token. Use the official third-party flow separately when you need a service without access to the bot token to verify the data.