Skip to main content

Telegram bot and Mini App

Send events to POST /v1/events from your backend with your secret key. Set context.platform to telegram for both flows.

  • Bot. Send an event when your server handles the bot action. You can send bot events without a browser fingerprint. Omit context.ip. Your server's IP would group all bot users together.
  • Mini App. A Mini App is a web page. Use the browser SDK as you would on a website and pass its fp_id to your backend for the event. Also pass the raw Telegram.WebApp.initData to your backend and send it as telegram.init_data to verify the Telegram identity.

Set up​

#WhereWhat to doBotMini App
1Dashboard → API keysCreate a secret key for your backend.✓✓
2Dashboard → API keysCreate a publishable key for the Mini App page.✓
3Dashboard → Settings → Project → Allowed originsAdd the origin your Mini App page is served from, for example https://app.example.com.✓
4Dashboard → Settings → Project → TelegramEnter the Bot ID: the digits before the colon in the token BotFather gives you. For the token 123456789:AAE... the Bot ID is 123456789. Never enter the whole token.✓
5Your Mini App pageRun the browser SDK with the publishable key and pass fp_id and Telegram.WebApp.initData to your backend.✓
6Your backendSend events as shown below.✓✓

Do the setup in each project you use: the sandbox and live projects have their own keys and settings. Without a Bot ID, every event that carries init_data is untrusted. Bot events need no Bot ID.

To check your integration, send a test event and open it in the dashboard under Events.

Map actions to events​

Actionevent_type
First /start or referral claim that creates an accountregistration
Repeat /start for an existing accountlogin
Referral bonus payoutpayout

Use your own opaque user key as external_account_id. Keep the raw Telegram ID in telegram.user_id only.

Telegram fields​

The telegram object is optional. If you send it, user_id is required. Use only the fields below.

FieldType and limits
user_idRequired string of up to 20 decimal digits. The value must be between 1 and 2^52, inclusive. Leading zeros are ignored.
referrer_codeOptional string of 1–64 characters. Use the referral code your system issued.
referrer_account_idOptional string of 1–64 characters. Use your own opaque account key for the owner of the referral code.
has_usernameOptional boolean. Whether the Telegram user has a username.
language_codeOptional string of up to 35 characters. Start with 1–8 ASCII letters. Each additional part starts with a hyphen and contains 1–8 ASCII letters or digits.
is_premiumOptional boolean. Whether the Telegram user has Telegram Premium.
init_dataOptional string of up to 4,096 characters and 4,096 UTF-8 bytes. Send the raw Telegram initData query string for Mini App events only.

Examples​

Bot registration with a referrer​

{
"event_id": "3f2b8c1e-5d47-4a9e-9c6b-0e1f2a3b4c5d",
"event_type": "registration",
"external_account_id": "user-1001",
"context": { "platform": "telegram" },
"telegram": {
"user_id": "123456789",
"referrer_code": "welcome-7f4x",
"referrer_account_id": "user-1000",
"has_username": true,
"language_code": "en",
"is_premium": false
}
}

Mini App login​

Replace the init_data value with the raw query string from the current Mini App session. Replace fp_id with the ID returned by the browser SDK.

{
"event_id": "0192f3c4-8b7a-7c3e-9d21-5f6a7b8c9d0e",
"event_type": "login",
"external_account_id": "user-1001",
"context": { "platform": "telegram", "fp_id": "<fp_id from the browser SDK>" },
"telegram": {
"user_id": "123456789",
"init_data": "<raw Telegram.WebApp.initData>"
}
}

Identity trust and referral counting​

Trust levelWhen it applies
telegram_verifiedThe signature in init_data is valid for the configured bot, the data is recent, and the signed user ID matches telegram.user_id. We use the signed profile fields.
client_assertedYou omit init_data. We use the profile fields sent by your server. This is the normal level for bot events.
untrustedYou send init_data and verification fails. This includes invalid or expired data, a different user ID, or missing project configuration.

To count an invite, send external_account_id, telegram.referrer_code and telegram.referrer_account_id on the invitee's registration event. Look up the owner of the code on your server. The referrer's account key must differ from the invitee's account key. We count a Telegram user only once per project. Both telegram_verified and client_asserted events are eligible, so omitting init_data is fine. Self-invites and untrusted events are excluded.

We score referral patterns in shadow mode, with results visible to your team for review. Shadow results leave the live decision and risk score unchanged.

Privacy​

We store the Telegram user ID only as a hash scoped to your organization. We check init_data during intake and discard the raw string. We keep only the derived Telegram fields.