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, decode_payload
link = await get_start_link('foo', encode=True)  # result: 'https://t.me/MyBot?start=Zm9v'
# and decode it back:
payload = decode_payload('Zm9v')  # result: 'foo'

Use this method to handy 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

Use this method to handy 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.

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

Convert payload to text and search for not allowed symbols.