Skip to main content

buttons

buttons execute transitions between script’s states.

Syntax

Button name is added in quotation marks after the buttons tag.

  • By clicking, the text specified inside the buttons tag will be sent in the chat:
buttons:
"Button 1"
"Button 2"
  • By clicking on the button, the transition to the specified state can be made if:
    • on the left side of the tag is a string that defines a button text,
    • on the right side is a string that determines the transition path.
# By clicking the button, the transition to the /RememberCity state will be made
buttons:
"New York" -> ./RememberCity
"Washington" -> ./RememberCity
  • You can use string substitutions:
buttons:
"Move to the {{ $request.query }} section" -> ./
buttons:
"Button" -> {{$temp.match.targetState}}
  • You can pass objects in the buttons tag:
buttons:
{ text: "Send location", request_location: true, one_time_keyboard: false }
info

Please note that the text key is required for objects passed in the buttons tag.

Channel restrictions

  1. Telegram and VK:

    • The button’s text maximum length is 20 characters. Button text outside the limit moves to the next line.
    • In Telegram, there should be at least one text reply in the bot message for each set of buttons.
  2. Viber:

    • You can place 1, 2, 3, or 6 buttons on a single row.
  3. i-Digital: WhatsApp:

    • Text buttons and inline URL buttons cannot be combined in one state.
    • The maximum number of buttons in a single message is 3.
    • The button’s text maximum length is 20 characters.
    • The buttons which are added to the first bot message in the messaging campaign must be registered in advance. Other buttons do not require registration.

Character limit

You can control the number of characters in the button row from the script for the VK and Telegram channels. Run script in the state:

script:
$response._buttonsRowLength = 30; // 30 characters in a row

How to use

caution
The buttons and inlineButtons tags cannot be applied to a single response specified in the a tag simultaneously. Instead, several responses can be added to a single state and different types of buttons can be applied to each response.

Telegram

  • You can use buttons to request the client’s location:
state: Buttons
a: Share your location.
buttons:
{ text: "Send location", request_location: true, one_time_keyboard: false }

state:
event: telegramSendLocation
a: Your location has been received.
  • You can use buttons to request the client’s phone number:
state: Order
a: If everything is correct, send your phone number and our manager will contact you.
buttons:
{text: "Send phone number", request_contact: true}
"Menu" -> /ChoosePizza

state: GetPhoneNumber
event: telegramSendContact
script:
$client.phone_number = $request.rawRequest.message.contact.phone_number;
a: Thank you! Our manager will contact you by phone number {{ $client.phone_number }}.

i-Digital: WhatsApp

Template

To add buttons to the first bot message in the messaging campaign for the i-Digital: WhatsApp channel, you have to register them as a template in i-Digital.

In the template, you need to specify the message text and the button content.

Other buttons do not require registration. Also, you do not need to register buttons you are going to use in scripts for processing inbound requests.

Template with text buttons

Message textButton 1Button 2
Will the car be used for personal purposes?YesNo
tip
To receive a template for buttons, contact your account manager.

Script

In the following script the buttons were registered in advance. The state will switch to /NormalButtons1 or /NormalButtons2 by clicking Yes or No buttons.

state: Buttons
q!: buttons
a: Will the car be used for personal purposes?
buttons:
"Yes" -> /NormalButtons1
"No" -> /NormalButtons2

state: NormalButtons1
a: Let’s proceed with the order.

state: NormalButtons2
a: Then what will the car be used for?