GetMyBot ナレッジベース

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 seesData remembered by the button
Coat, ₽12,000 · Buyproduct_id=101, price=12000
Dress, ₽8,000 · Buyproduct_id=102, price=8000
Sneakers, ₽6,000 · Buyproduct_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:

FieldWhat to enterResult
List (over)ctx.productsThe 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 defaultEach 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.

  1. Set the list to ctx.products, the alias to item, and the buttons per row to one.
  2. Set the button template text to {{item.name}} · {{item.price}} ₽.
  3. Choose the "Run reaction" button type and the checkout reaction.
  4. In Carry, add the key product_id with the value {{item.id}}.
  5. 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, 3600 is one hour. 0 selects 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 doUseWhere to read the value
Pass the chosen product to the next reactionCarry{{ctx.product_id}}
Remember the city after the customer chooses itset_params on the button{{param.city}}
Save a value as soon as the message is sentset_params on the message block{{param.key}}

What's next