Using the Wildcard (*) Command¶
No matter how many keyboards, buttons, and help menus you build, users will still send unexpected messages like hello, who are you?, or typos like /sttart.
By default, sending an unknown command results in the bot ignoring it or showing a raw system message. The wildcard command (*) acts as a safety net to catch any messages that don't match your existing commands.
How the Wildcard Works¶
The * command is a catch-all trigger.
- A user sends a message.
- TBL searches all your defined commands and aliases.
- If no command or alias matches, TBL runs your
*command.
Step 1: Create the Wildcard Command¶
Let's build a polite "I didn't get that" responder:
- Open your bot dashboard and click Add Command.
- Command: Type
*(just a single asterisk). - Answer: Type your fallback response:
- Keyboard: (Optional) Add your main menu buttons (e.g.
Help, About) to help them get back on track. - Click Save Command.
Step 2: Test It!¶
- Open Telegram and message your bot.
- Send a valid command, like
/start. Your/startgreeting should run normally. - Now send something completely random, like
hello bot!. - Your bot will execute the
*command and reply: "Hmm, I didn't quite catch that..." along with your menu buttons.
Best Practices for Wildcards¶
- Don't put core features in
*: The wildcard is meant as a friendly safety net or a router. Don't write your main bot logic here. Keep that in specific, named commands. - Give clear navigation: When the wildcard triggers, always tell the user how to get back to the main menu (like suggesting
/startor showing reply keyboard buttons). - Case Sensitivity Safety: If you want to catch simple words like
helpwithout aliases,*will catch them. You can use JavaScriptifconditions in the*command's Logic to inspect the input text (using the globalmessagevariable) and route it accordingly.
Congratulations!¶
You have completed the TBL Hands-on Tutorial Series. You now know how to:
- Create commands and static responses.
- Build reply menus.
- Map multiple buttons to single commands using Aliases.
- Capture user text input step-by-step.
- Build inline buttons and callback handlers.
- Catch unknown messages with a wildcard handler.
To understand how these pieces execute in sequence, check out the Concept Guides: