Skip to main content

Submitting parameters

Description

Sometimes you need your bot to obtain additional parameters from the user at start time. It can be a command that starts the bot, an authentication token used to connect the user’s telegram account to an external account, or its name.

These parameters are passed in the https://t.me/<bot username>?start=<test> link of the telegram bot as a /start text request. Clicking the link with the parameter set will open a personal dialog with the bot, with the Start button instead of the input field.

When the user clicks the Start button, the bot will receive a message from that user in the form of /start text where text is the value of the start parameter passed via the link.

Using in a script

Here is an example of getting a parameter from a script. An arbitrary parameter specified in the link is returned to the $parseTree.Text[0].value variable.

state: Start
q!: *start $Text $weight<+0.5>
a: Here: {{$parseTree.Text[0].value}}

Suppose the user clicks the following link:

https://t.me/exampleBot?start=test

The user will be automatically redirected to the chat with the exampleBot bot. When the user clicks the Start button the q!: *start $Text $weight<+0.5> pattern is triggered. The bot will output the Here: test message.

You can check if you have received the required parameters:

var params;

if ($parseTree._Text) {
params = $parseTree.Text[0].value;
} else if ...