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:

    • 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.

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 }}.