Dynamic Buttons and Parameters
How to show products as buttons, remember a customer's choice, and pass it to the next reaction. Examples of Carry, expiry, and persistent parameters.
このページの内容
Your bot shows three products, each with a "Buy" button. A customer chooses the dress. The next reaction needs to receive that particular dress, even if the bot has shown other products since then.
Two settings make this work: dynamic buttons create buttons from a product list, and Carry remembers which product belongs to each button. Both are configured in the message block of the "Send message" action.
| What the customer sees | Data remembered by the button |
|---|---|
| Coat, ₽12,000 · Buy | product_id=101, price=12000 |
| Dress, ₽8,000 · Buy | product_id=102, price=8000 |
| Sneakers, ₽6,000 · Buy | product_id=103, price=6000 |
Pressing the second button passes product_id=102 to the reaction. The bot does not have to identify the product from the word "Buy".
Dynamic buttons from a list
Instead of adding each product manually, get a list from a collection or an external service. The "Dynamic buttons from list" block creates one button per item. The list is kept in temporary reaction data, called the context (ctx) in settings. Configure four fields:
| Field | What to enter | Result |
|---|---|---|
List (over) | ctx.products | The bot reads products from temporary data. A "Source query", "Web request", or "Compute" action prepares the list first |
Element alias (as) | item, the default | {{item.name}} means the name of one product in the list |
Buttons per row (columns) | 1, the default | Each product appears on its own row |
| Button template | {{item.name}} · {{item.price}} ₽ | For each product, the bot fills in its name and price in the text and other button fields |
When the message is sent, the bot fills in the template for each product. Three products produce three buttons. You can use the same approach for available classes, orders, or menu choices.
Example
ctx.products contains products with id, name, and price fields.
- Set the list to
ctx.products, the alias toitem, and the buttons per row to one. - Set the button template text to
{{item.name}} · {{item.price}} ₽. - Choose the "Run reaction" button type and the checkout reaction.
- In Carry, add the key
product_idwith the value{{item.id}}. - In the checkout reaction, use
{{ctx.product_id}}to read the selected product.
Press the second button and then the first. Each time, the reaction should receive the ID of the product you pressed.
Data passed on press (Carry)
Carry is the data a button passes when pressed. Think of it as a tag attached to a product: each button has its own tag, even if all buttons say "Buy" and run the same reaction.
In the editor, this setting is called "Data on press". Values are captured when the message is sent. When the button is pressed, the bot puts them in ctx, the temporary data for the new reaction run.
- Key: the name of a saved value. For
product_id, read the result as{{ctx.product_id}}. - Value: what to remember. Enter a number or a substitution such as
{{item.id}},{{param.order_id}}, or{{ctx.x}}. Substitutions are evaluated when the message is sent. - One-time (
single_use): the saved data is deleted after the first press and cannot be used again. - Button data lifetime (
ttl_seconds, also called TTL): how many seconds to keep the data. For example,3600is one hour.0selects the default lifetime, currently 30 days; it does not mean indefinite storage.
After the lifetime expires, the old data is unavailable. Let the customer open the catalog again. Each sent button has its own values, even if its text and target reaction match another button. Technical descriptions call this per-invocation data.
Setting parameters via a button (set_params)
Sometimes a choice must be remembered after the reaction ends. For example, a customer chooses a delivery city that the bot should use for their next order. The button's "Parameters" field (set_params) saves the value to the subscriber's profile on press. The city is then available as {{param.city}}.
Carry passes temporary values into the current run ({{ctx.key}}), while set_params saves values between runs ({{param.key}}). The message block also has a set_params field, but it writes the value when the message is sent, even if the customer never presses a button.
A button can also set and clear labels on press, using the same fields as the message block.
Choosing the right mechanism
| What you need to do | Use | Where to read the value |
|---|---|---|
| Pass the chosen product to the next reaction | Carry | {{ctx.product_id}} |
| Remember the city after the customer chooses it | set_params on the button | {{param.city}} |
| Save a value as soon as the message is sent | set_params on the message block | {{param.key}} |
What's next
- Messages and Buttons: message blocks, button types, and on-press behavior.
- Substitutions and Formulas:
{{item.*}},{{ctx.*}}, and{{param.*}}in templates. - Reaction Links: where buttons lead and how to see the transition graph.
- Collections and Data: where to get lists for dynamic buttons.