Ask a question and collect the reply
Ask a question with Wait for answer, process the reply in BJS, save user data, and provide a cancel path.
Ask for a name
Create a command /name with these settings:
Answer
What should I call you? Send /cancel to stop.
Wait for answer
On
Auto retry time in seconds
Empty
Put this in the BJS editor and save:
const displayName = (message || "").trim();
if (!displayName) {
Bot.sendMessage("Please send /name again and reply with text.");
return;
}
User.setProp("display_name", displayName);
Bot.sendMessage({
text: "Thanks, " + displayName + ". Your name is saved.",
parse_mode: null
});The explicit parse mode keeps user input from being interpreted as Markdown. The property belongs to the current bot user; see properties and scopes.
Add a cancel command
Create a separate /cancel command with Answer Cancelled. Send /name when you are ready. Leave Wait for answer off for /cancel.
When a pending reply matches an existing command or alias, Bots.Business cancels the pending wait and processes the matching command. This is why /cancel must actually exist. A string check inside /name is not the only way to cancel.
This also means that a reply such as Help can leave the input flow if Help is a command alias. Choose prompts and button labels with that behavior in mind.
Test the whole conversation
Send
/name; expect the question and no saved-name message yet.Reply
Alex; expect the confirmation.Open that user's Properties and check
display_name.Send
/nameagain, then/cancel; expect cancellation.Send ordinary text after cancellation; it should no longer be treated as the answer to
/name.
Validation and repeated questions
The pending request is consumed after handling the reply, including when its BJS fails. An error does not automatically keep the same question active. The example above explicitly asks the user to start /name again after invalid input.
For a multi-step form, store each accepted value and deliberately start the next question. Keep a cancel command available, and avoid command names or aliases that collide with likely answers.
If no prompt appears, check that the command has an Answer and the bot is running. If the prompt appears but the reply fails, open Errors and confirm that the code uses the reply's message and a valid user context.
For numeric input with validation, repeated prompts, and cancellation, follow the complete quantity dialog.
Last updated
Was this helpful?
