Skip to main content

Submitting parameters

Description

Sometimes you may need the user to follow a link to a certain dialog. VKontakte uses the vk.me short URL service that redirects users to the specified conversation.

The link has the http://vk.me/{group_name} format. Here group_name is the community identifier. For example: vk.me/exampleclub.

You can also pass the ref arbitrary parameter in the link. It can be used to monitor the performance of links used in different channels or to match the user with the session or an external account. You can vary bot responses in the community depending on the parameter passed.

The link that includes additional parameters will take the following form:

http://vk.me/{group_name}?ref={ref}

Using in a script

A dialog with a VKontakte bot starts with the start message. That is why the start state should be specified as follows for the script to operate properly:

state: start
q!: start
script:
var params;
if ($request.rawRequest.object.message && $request.rawRequest.object.message.ref) {
params = $request.rawRequest.object.message.ref;
$reactions.answer(params);
} else $reactions.answer("Parameter not received");

The arbitrary parameter will be returned to the $request.rawRequest.object.message.ref variable when the Start button is clicked.

Suppose the user clicks the following link:

http://vk.me/exampleBot?ref=TEST

The user will be automatically redirected to the chat with the exampleBot bot. When the user clicks the Start button the q!: start pattern is triggered. Check in the script tag if we have received the desired parameter. If so, output it as a bot response: TEST. Otherwise, output the following message: Parameter not received.