From fc9e2b82c6547099a1b2c924d85f4d893cc4cc31 Mon Sep 17 00:00:00 2001 From: JRoot Junior Date: Fri, 24 Nov 2023 21:27:03 +0200 Subject: [PATCH] Added page for deep linking util --- aiogram/utils/deep_linking.py | 46 --------------------------- docs/utils/deep_linking.rst | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 46 deletions(-) create mode 100644 docs/utils/deep_linking.rst diff --git a/aiogram/utils/deep_linking.py b/aiogram/utils/deep_linking.py index bfd62a16..19cc64c6 100644 --- a/aiogram/utils/deep_linking.py +++ b/aiogram/utils/deep_linking.py @@ -1,49 +1,3 @@ -""" -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 added some utils to get deep links more handy. - -Basic link example: - - .. code-block:: python - - from aiogram.utils.deep_linking import create_start_link - - link = await create_start_link(bot, 'foo') - - # result: 'https://t.me/MyBot?start=foo' - -Encoded link example: - - .. code-block:: python - - from aiogram.utils.deep_linking import create_start_link - - link = await create_start_link(bot, 'foo', encode=True) - # result: 'https://t.me/MyBot?start=Zm9v' - -Decode it back example: - .. code-block:: python - - from aiogram.utils.deep_linking import decode_payload - from aiogram.filters import CommandStart, CommandObject - from aiogram.types import Message - - @router.message(CommandStart(deep_link=True)) - async def handler(message: Message, command: CommandObject): - args = command.args - payload = decode_payload(args) - await message.answer(f"Your payload: {payload}") - -""" from __future__ import annotations __all__ = [ diff --git a/docs/utils/deep_linking.rst b/docs/utils/deep_linking.rst new file mode 100644 index 00000000..c115136c --- /dev/null +++ b/docs/utils/deep_linking.rst @@ -0,0 +1,60 @@ +============ +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 added some utils to get deep links more handy. + +Examples +======== + +Basic link example +------------------ + +.. code-block:: python + + from aiogram.utils.deep_linking import create_start_link + + link = await create_start_link(bot, 'foo') + + # result: 'https://t.me/MyBot?start=foo' + +Encoded link +------------ + +.. code-block:: python + + from aiogram.utils.deep_linking import create_start_link + + link = await create_start_link(bot, 'foo', encode=True) + # result: 'https://t.me/MyBot?start=Zm9v' + +Decode it back +-------------- + +.. code-block:: python + + from aiogram.utils.deep_linking import decode_payload + from aiogram.filters import CommandStart, CommandObject + from aiogram.types import Message + + @router.message(CommandStart(deep_link=True)) + async def handler(message: Message, command: CommandObject): + args = command.args + payload = decode_payload(args) + await message.answer(f"Your payload: {payload}") + + +References +========== + +.. autofunction:: aiogram.utils.deep_linking.create_start_link + +.. autofunction:: aiogram.utils.deep_linking.decode_payload