Dialogue and buttons
| Function | What it does |
|---|---|
bot.buttons(items) | a menu under the bot's last message |
bot.wait() | stops the script; the visitor's next message runs it again |
bot.buttons
An item is a label (a string or a number) or a link {text, url}. Pressing a label sends it as the visitor's next message; a link opens and sends nothing.
include bot
bot.say("How will you pay?")
bot.buttons(["Card", "Cash", {text: "Pricing", url: "https://example.com/prices"}])How will you pay?
[Card] [Cash] [Pricing ↗]The menu sits under the bot's last message — bot.say first, then the buttons. Empty labels are skipped, extra spaces collapse.
A menu from data:
include bot
include json
r = bot.http({url: "https://cafe.example.com/products"})
menu = json.parse(r["body"])["items"]
bot.say("What would you like?")
bot.buttons(menu.map { "${it["name"]} — ${it["price"]} ₽" }.take(10))What would you like?
[Cappuccino — 220 ₽] [Latte — 250 ₽] [Raf — 280 ₽]Up to 10 buttons per call, up to 3 calls per run, a label up to 64 characters, url only http(s).
bot.wait
A script can't wait in the middle of its code. bot.wait() ends the run (like exit(); try doesn't catch it), the block waits, and the visitor's answer runs the script from the first line — with the answer in $message.
include bot
bot.say("What is your name?")
bot.wait()
bot.say("never")What is your name?Only bot.set variables live between runs. So the order is:
- ask the question and remember the step —
bot.set("step", "name"); bot.wait();- in the next run, read the step and save
$messageas the answer to it.
While the block waits, its exit doesn't matter. The scenario's global blocks fire before it.
Step by step
include bot
step = bot.get("order_step") ?? ""
answer = $message.trim
fn ask(field, question, options = nil) {
bot.set("order_step", field)
bot.say(question)
bot.buttons(options) if options != nil
bot.wait()
}
if step == "size" && answer in ["S", "M", "L"] {
bot.set("size", answer)
} else if step == "phone" && answer.replace(/\D/, "").len >= 10 {
bot.set("phone", answer.replace(/\D/, ""))
}
ask("size", "What size?", ["S", "M", "L"]) if (bot.get("size") ?? "").blank
ask("phone", "Your phone number?") if (bot.get("phone") ?? "").blank
bot.set("order_step", "")
bot.say("Done: size ${bot.get("size")}, phone ${bot.get("phone")}.")
bot.exit("next")What size?
[S] [M] [L]| The visitor's message | What the bot answers |
|---|---|
| «I want a T-shirt» | «What size?» and buttons, waits |
| pressed «M» | «Your phone number?», waits |
| «hi» | «Your phone number?» again — not a valid answer |
| «+7 999 123-45-67» | «Done: …», leaves by «дальше» (next) |
ask ends with bot.wait(), so nothing runs after the call. A wrong answer isn't saved — the same question is asked again.
Editing the question after the answer
The question's id is saved in a variable — the next run replaces the question with the choice:
include bot
if bot.get("menu_msg") == nil {
bot.set("menu_msg", bot.say("What are you interested in?"))
bot.buttons(["Delivery", "Payment"])
bot.wait()
}
bot.edit(bot.get("menu_msg"), "You chose: **${$message}**")What are you interested in?
[Delivery] [Payment]Common mistakes
| Mistake | What the visitor sees | The fix |
|---|---|---|
a question without bot.wait() | all the questions at once | bot.wait() after each question |
bot.exit("next") instead of waiting | the scenario goes on without an answer | bot.wait() |
| no step variable | the first "hi" saved as the name | save the answer only when step == "…" |
bot.say("Hello!") at the top, unconditionally | a greeting before every question | greet only when step == "" |
the answer not saved with bot.set | the same question over and over | bot.set(step, $message) |
Several such scripts in one bot — use different step names (order_step, profile_step): dialogue variables are shared.