4

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.

GameO7er
  • 2,028
  • 1
  • 18
  • 33
Carlos F
  • 893
  • 2
  • 12
  • 30

1 Answers1

5

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": 223110107,
         "is_bot": false,
         "first_name": "Ğąme",
         "last_name": "Ǿver!",
         "username": "GameO7er",
         "language_code": "en"
       },
       "chat": {
         "id": 223110107,
         "first_name": "Ğąme",
         "last_name": "Ǿver!",
         "username": "GameO7er",
         "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/NameBot?start=ReferUserID

for example :

t.me/NameBot?start=223110107

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

Hope be useful.

GameO7er
  • 2,028
  • 1
  • 18
  • 33