BotNetwork

Telegram deep links: the start parameter for onboarding and account linking

A deep link is the simplest way to send someone into your bot with context: which campaign they came from, which account they want to connect, or which group they want to set up. It is also untrusted input that anyone can type, so the parameter needs the same care as any other request.

Published 8 min read

Every bot has a public link that opens a chat with it: https://t.me/<bot_username>. Telegram lets you add parameters to that link so the bot receives extra information the moment the user arrives, without the user typing anything. Telegram's Bot Features page lists two main uses: launching the bot with a specific command, and passing an authentication token to connect the user's Telegram account to an account on another platform.

The rules for the parameter, at the time of writing:

  • Allowed characters are A-Z, a-z, 0-9, _ and -.
  • The parameter can be up to 64 characters long.
  • For binary or arbitrary content, Telegram recommends base64url encoding (the URL-safe alphabet from RFC 4648, section 5).

Anything outside that alphabet, such as spaces, dots or = padding, does not belong in a start parameter. Design your payloads to fit from the start rather than escaping them later.

Link What happens What the bot receives
t.me/your_bot?start=PARAM Opens the private chat and shows a Start button A message with text /start PARAM
t.me/your_bot?startgroup=PARAM Asks the user to pick a group to add the bot to /start@your_bot PARAM in that group
t.me/your_bot?startgroup&admin=RIGHTS Asks for a group where the user can manage admins, then adds the bot as admin The bot joins with the requested rights
t.me/your_bot?startchannel&admin=RIGHTS Asks for a channel and adds the bot as admin No start parameter for channels
t.me/your_bot?startapp=PARAM Opens the bot's Main Mini App start_param inside the Mini App's init data

Telegram's client documentation adds a useful detail: when a link carries a start parameter, the app shows the Start button even if the user has already started the bot. Pressing it sends the new /start PARAM message, so returning users can follow a deep link too.

The admin value is a +-separated list of rights, for example delete_messages+restrict_members+pin_messages. Request only the rights the bot actually uses; a moderation bot that never pins messages should not ask for pin_messages. The same principle appears in our post on Telegram group privacy mode, which explains what a bot sees in a group with and without admin rights.

Two other places use the same parameter format. An inline bot can show a button above its results that sends the user to the private chat with a start_parameter (the InlineQueryResultsButton object in the Bot API, 1 to 64 characters). And Business bots receive a deep link message in the form /start bizChat<user_chat_id> when the account owner taps Manage Bot in a managed chat.

Parsing /start safely

The start parameter arrives as plain message text. That has two consequences. First, you parse it from the text yourself (most libraries help, but the raw format is simple). Second, anyone can type /start whatever by hand, so the parameter proves nothing about where the user came from. Treat it as a hint, validate its format and look it up on your side.

A framework-agnostic parser in Python, working on the message.text field of a Bot API update:

import re

START_RE = re.compile(r"^/start(?:@(\w+))?(?:\s+(.*))?$", re.S)
PARAM_RE = re.compile(r"[A-Za-z0-9_-]{1,64}")

def parse_start(text, bot_username):
    """Return None if this is not /start for this bot,
    "" if there is no valid parameter, or the parameter."""
    m = START_RE.match(text or "")
    if not m:
        return None
    target, raw = m.group(1), (m.group(2) or "").strip()
    if target and target.lower() != bot_username.lower():
        return None  # /start@other_bot in a group
    return raw if PARAM_RE.fullmatch(raw) else ""

Then route on a short prefix, so one bot can serve several flows with clear rules for each:

  • ref_<code>: a referral or campaign code. Look it up in a table of known codes; ignore unknown ones.
  • link_<token>: an account linking token (next section).
  • g_<id>: a setup flow for a group, sent with startgroup.

Keep the payload opaque. A random code that maps to data in your database is safer than putting the data itself in the link. The parameter ends up in browser history, chat messages, screenshots and analytics. Do not put email addresses, names, prices or internal IDs in it. The short deep links guide on this site summarizes the same rules as a checklist.

Account linking with a one-time token

The most valuable use of deep links is connecting an account on your website to a Telegram user so the bot can send that person notifications. A safe flow looks like this:

  1. The logged-in user clicks "Connect Telegram" on your website.
  2. Your backend creates a random, single-use token with a short expiry and stores it next to the website user ID.
  3. The site shows a link (and optionally a QR code) to https://t.me/your_bot?start=link_<token>.
  4. The user opens it and presses Start. The bot receives /start link_<token> with the sender's Telegram user ID in message.from.id.
  5. The bot looks up the token, checks it has not expired, deletes it and stores the pairing.
import secrets, time

BOT_USERNAME = "your_bot"
LINK_TTL = 600            # seconds; keep it short
pending = {}              # use a database table or Redis in production

def create_link(web_user_id):
    token = secrets.token_urlsafe(24)    # 32 URL-safe characters
    pending[token] = (web_user_id, time.time() + LINK_TTL)
    return f"https://t.me/{BOT_USERNAME}?start=link_{token}"

def redeem(token, telegram_user_id):
    entry = pending.pop(token, None)     # single use: removed on first try
    if entry is None or entry[1] < time.time():
        return None
    web_user_id = entry[0]
    # save (web_user_id, telegram_user_id) in your users table here
    return web_user_id

secrets.token_urlsafe produces base64url text, which fits Telegram's allowed alphabet, and link_ plus 32 characters stays well under the 64-character limit. A few details make the difference between a convenient flow and an account takeover:

  • Single use and short expiry. A token that works forever can be replayed by anyone who later sees the link.
  • Confirm before linking. Whoever opens the link becomes the linked Telegram user. If the link was forwarded by mistake, the wrong person gets the notifications. Have the bot reply with an inline button that names the website account in masked form (for example, a partly hidden email address) and only save the pairing after the button press. Our post on inline keyboards and callback queries shows how to handle that button.
  • Store the numeric user ID, not the username. Usernames can change; from.id does not. See store platform IDs as text for why the column type matters.
  • Let users disconnect. Offer an unlink option on the website and in the bot.

If you need the user's identity on the website itself rather than in the bot, a deep link is the wrong tool; use Log in with Telegram and OpenID Connect instead, which gives you a signed token.

Mini Apps and startapp

Links with startapp open the bot's Main Mini App (configured in BotFather) or a named Mini App at t.me/your_bot/appname?startapp=PARAM. The Mini App receives the value in two places: the start_param field of the init data and the tgWebAppStartParam GET parameter. The GET parameter is convenient for loading the right screen immediately, but only the init data is signed, so validate it on the server before acting on the value. Our guide to validating Mini App initData covers the check. An optional mode=compact or mode=fullscreen controls how the app opens.

Deep links work anywhere a URL works: a website button, a QR code on a printed flyer, an email signature or a post in a community. Most bots end up with a small landing page that explains what the bot does, links to the privacy policy and offers a "Start the bot" button with a campaign parameter per source.

That page does not need much. A short domain is easy to print on a QR code and to say out loud; you can register one through Namecheap domains or any registrar. A static page can run on a basic plan such as Namecheap hosting, as long as the account linking step (creating tokens) runs on a backend you control. For the HTTPS setup, follow our guide to a custom domain and HTTPS, and use the QR code generator to turn each campaign link into a printable code.

Checklist

  1. Build links from the bot's real username (you can read it with getMe) and keep payloads within 64 characters of A-Z a-z 0-9 _ -.
  2. Use prefixes such as ref_ and link_ to route flows, and reject anything that does not match a known pattern.
  3. Never put personal data or secrets in a start parameter; map short random codes to data on your server.
  4. For account linking, use single-use tokens with a short expiry and confirm with a button before saving the pairing.
  5. In group links, request only the admin rights the bot needs.
  6. For Mini Apps, trust start_param only after validating the signed init data.
  7. Give the links a home: a simple landing page on your own domain (Namecheap is one option) with a clear privacy note.

Sources