Handling User Input with Need Reply¶
Fire-and-forget commands are great, but eventually you will want to ask your user for information—like a username, email, phone number, or age.
With the Need Reply setting, you can pause your command, wait for the user to type their response, and then run JavaScript logic on the input they sent.
How Need Reply Works¶
Instead of running your code immediately, a Need Reply command works like a two-step conversation:
- Step 1: User triggers the command. The bot sends the Answer text (e.g., "What is your name?") and pauses.
- Step 2: The user types their answer (e.g., "Alice") and sends it.
- Step 3: The command wakes up and runs your JavaScript Logic field. The text they typed is automatically saved in the global variable
message.
Step 1: Create the Command¶
Let's build a name-prompting command:
- Open your dashboard and click Add Command.
- Command: Type
/askname. - Answer: Type the question:
- Need Reply: Toggle this setting ON (enabled).
- Logic: Paste this standard JavaScript code:
- Click Save Command.
Step 2: Test It!¶
- Open Telegram and send
/asknameto your bot. - The bot will send "Please type your name below!" and wait.
- Type your name (e.g.
Sam) and hit send. - The bot will run your logic and reply: "Nice to meet you, Sam!"
The Escape Hatch: Canceling Input Mode¶
What if a user changes their mind and doesn't want to enter their name? They shouldn't get stuck forever.
If a user is in a "Need Reply" waiting state and they send any valid existing command (like /start or Help), TBL will automatically cancel the input mode and run that command instead.
Beginner Tip
Always tell your users how to cancel in your Answer field! Add a quick line like: (send /start to cancel). It prevents users from feeling stuck or thinking your bot is broken.
What's Next?¶
Now that you can capture user text, let's look at Inline Keyboards—buttons that sit directly inside message bubbles and execute actions behind the scenes without sending chat spam!