Skip to main content

Submitting parameters

Description

Sometimes you may need to redirect the user by the link to a certain bot or to a certain part within the bot script. For example, you may need to refer the client to some personal content or features available in the chatbot. In this case, you can pass parameters by the link in Viber.

The following parameters can be passed in Viber:

  • link — link to the chat. Clicking this link will open a conversation with the bot and trigger the conversation start event.
  • context — context. The value of this parameter will be passed as a string and has length restrictions.
  • text — text. The value of this parameter will be displayed in the text input field when you open the chat with the bot by the link. The user can submit the text specified by the parameter without any changes, modify or remove it.

The link that includes all the parameters will look as follows:

viber://pa?chatURI=<URI>&context=<Your Context>&text=<Your Text>

Using in a script

Here is an example of getting parameters. The context arbitrary parameter will be returned to the $context.request.rawRequest.context variable in response to the event!: conversationStarted event.

state: vibertest
event!: conversationStarted
a: Here: {{ $context.request.rawRequest.context }}

Suppose the user clicks the following link from the chat:

viber://pa?chatURI=exampleBot&context=1234124&text=start

The user will be automatically redirected to the chat with the exampleBot bot, and the conversationStarted event is triggered. The bot will output the Here: 1234124 message, and the start text will appear in the input field.

You can check if you have received the required parameters:

var params;

if ($context.request.rawRequest.context) {
params = $context.request.rawRequest.context;
} else if ...