Deep linking

Deep linking

Telegram bots have a deep linking mechanism, that allows for passing additional parameters to the bot on startup. It could be a command that launches the bot — or an auth token to connect the user’s Telegram account to their account on some external service.

You can read detailed description in the source: https://core.telegram.org/bots#deep-linking

We have add some utils to get deep links more handy.

Basic link example:

from aiogram.utils.deep_linking import get_start_link
link = await get_start_link('foo')

# result: 'https://t.me/MyBot?start=foo'

Encoded link example:

from aiogram.utils.deep_linking import get_start_link

link = await get_start_link('foo', encode=True)
# result: 'https://t.me/MyBot?start=Zm9v'
Decode it back example:
from aiogram.utils.deep_linking import decode_payload
from aiogram.types import Message

@dp.message_handler(commands=["start"])
async def handler(message: Message):
    args = message.get_args()
    payload = decode_payload(args)
    await message.answer(f"Your payload: {payload}")

Get ‘start’ deep link with your payload.

If you need to encode payload or pass special characters -

set encode as True

Parameters
  • payload – args passed with /start

  • encode – encode payload with base64url

Returns

link

Get ‘startgroup’ deep link with your payload.

If you need to encode payload or pass special characters -

set encode as True

Parameters
  • payload – args passed with /start

  • encode – encode payload with base64url

Returns

link

aiogram.utils.deep_linking.encode_payload(payload: str)str[source]

Encode payload with URL-safe base64url.

aiogram.utils.deep_linking.decode_payload(payload: str)str[source]

Decode payload with URL-safe base64url.