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 }
Please note that the text
key is required for objects passed in the buttons
tag.
Channel restrictions
-
- The button’s text maximum length is 20 characters. Button text outside the limit moves to the next line.
- There should be at least one text reply in the bot message for each set of buttons.
- Buttons are not supported in the bots for business accounts.
-
- You can place 1, 2, 3, or 6 buttons on a single row.
-
- 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.
-
VK:
- The button’s text maximum length is 20 characters. Button text outside the limit moves to the next line.
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
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: Location
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 text | Button 1 | Button 2 |
---|---|---|
Will the car be used for personal purposes? | Yes | No |
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?