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_idto your backend for the event. Also pass the rawTelegram.WebApp.initDatato your backend and send it astelegram.init_datato verify the Telegram identity.
Set up
| # | Where | What to do | Bot | Mini App |
|---|---|---|---|---|
| 1 | Dashboard → API keys | Create a secret key for your backend. | ✓ | ✓ |
| 2 | Dashboard → API keys | Create a publishable key for the Mini App page. | ✓ | |
| 3 | Dashboard → Settings → Project → Allowed origins | Add the origin your Mini App page is served from, for example https://app.example.com. | ✓ | |
| 4 | Dashboard → Settings → Project → Telegram | Enter 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. | ✓ | |
| 5 | Your Mini App page | Run the browser SDK with the publishable key and pass fp_id and Telegram.WebApp.initData to your backend. | ✓ | |
| 6 | Your backend | Send 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
| Action | event_type |
|---|---|
First /start or referral claim that creates an account | registration |
Repeat /start for an existing account | login |
| Referral bonus payout | payout |
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.
| Field | Type and limits |
|---|---|
user_id | Required string of up to 20 decimal digits. The value must be between 1 and 2^52, inclusive. Leading zeros are ignored. |
referrer_code | Optional string of 1–64 characters. Use the referral code your system issued. |
referrer_account_id | Optional string of 1–64 characters. Use your own opaque account key for the owner of the referral code. |
has_username | Optional boolean. Whether the Telegram user has a username. |
language_code | Optional 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_premium | Optional boolean. Whether the Telegram user has Telegram Premium. |
init_data | Optional 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 level | When it applies |
|---|---|
telegram_verified | The 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_asserted | You omit init_data. We use the profile fields sent by your server. This is the normal level for bot events. |
untrusted | You 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.