Creating Links to Bots
Links are a common entry point to using a bot. Deep links can be used for starting bot dialogs with some extra input.
Regular links
The same way as with users, groups, and channels, the link t.me/examplebot
opens the bot with the username @examplebot
.
Deep links
Deep links can start a personal dialog with the bot with some initial data — for example, for a referral program it can be an ID of the user who shared the link. They have the following form: t.me/examplebot?start=YOUR_TEXT
from aiogram.utils.deep_linking import create_start_link
link = await create_start_link(bot, 'from_ad')
Once a user visits a deep link, they see a dialog with the bot and the "Start" button (even if they have already started the dialog). The button sends /start YOUR_TEXT
. The user, however, sees only /start
, like if starting the bot regularly.
Deep links for groups
There is a variant of deep links for groups as well.
The link of form t.me/examplebot?startgroup=YOUR_TEXT
opens a chat selection dialog to add the bot; once the bot is added, the command /start YOUR_TEXT
will immediately be sent to the group.
from aiogram.utils.deep_linking import create_start_link
link = await create_startgroup_link(bot, 'from_ad')
Using tg://
links
Just FIY, all links that we considered above also have tg://
equivalents. These are direct links that can be opened within the app:
- Regular link:
tg://resolve?domain=examplebot
- Deep link:
tg://resolve?domain=examplebot&start=YOUR_TEXT
- Group deep link:
tg://resolve?domain=examplebot&startgroup=true
There are more direct links that may replace t.me
links or do special actions. For example, the link to tg://settings opens settings in some Telegram apps. Such links are listed in API documentation and in the unofficial @DeepLink channel.