telegramtelegram-botpython-telegram-bottelegram-webhooknode-telegram-bot-api

Deeplinking into a telegram bot


I have a simple use case. When a user clicks the link below,

T.me/MycompanynameBot?start=Microsoft

I want to show him 3 inline buttons corresponding to 3 Telegram channels within Microsoft. Is this possible?

The key is the bot must be able to retrieve the parameters from the URL.

Thank you.


Solution

  • Yes it's possible to retrieve bot parameter via answerCallbackQuery

    Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via @Botfather and accept the terms. Otherwise, you may use links like:
    t.me/your_bot?start=XXXX
    that open your bot with a parameter.

    Here is an example I made for you :

     {
       "ok": true,
       "result": [{
         "update_id": 89590932,
         "message": {
           "message_id": 5978,
           "from": {
             "id": 156878147,
             "is_bot": false,
             "first_name": "Unrivaled",
             "last_name": "ir",
             "username": "Unrivaledir",
             "language_code": "en"
           },
           "chat": {
             "id": 223110107,
             "first_name": "Unrivaled",
             "last_name": "ir",
             "username": "Unrivaledir",
             "type": "private"
           },
           "date": 1579094448,
           "text": "/start Microsoft",
           "entities": [{
             "offset": 0,
             "length": 6,
             "type": "bot_command"
           }]
         }
       }]
     }
    

    As you can see type=bot_command so you can parse the message if (type == "bot_command") and get text and substring /start from the original text or what ever you want to do.

    In many cases I detect users with the parameters for example when I wanna to know who invited this user to bot I share the link in this format:

    t.me/BotName?start=ReferUserID

    for example :

    t.me/BotName?start=156878147

    is my ID and I can see how many user I've invited to the bot.

    Hope be useful.