Skip to content

Command Structure in TBL

Every TeleBotHost bot is a collection of commands. Not routes, not controllers, not event listeners — commands. Telegram sends an update, TBL matches exactly one, runs it, and finishes.

One update in. One path through your code out. That's the whole model.


The command-driven model

User action  →  Telegram update  →  TBL matches command  →  Answer + Logic  →  Done

No background process humming away. No while(true) loop. Each message is a fresh, self-contained run — plus automatic @ and @@ wrappers around it (Special Commands).


What a command contains

Think of a command as a small form with a few parts:

Part Role
Name What triggers it (/start, Help, *)
Answer Optional auto-reply before logic
Logic Real JavaScript + built-in bot extras for dynamic behavior
Options Keyboard, aliases, need reply, public web, parse mode

Answer is the fast path — static text TBL sends for you. Logic is where Bot, Api, db, and globals like user and params come in.

Full field reference: Command Fields.


Learn part by part

Flow & matching

  1. Command Flow overview — hub for this section
  2. Matching & Priority — which command wins
  3. Execution Flow@, Answer, Logic, !, @@
  4. Special Commands/start, @, !, @@, *
  5. Dynamic Handlers/handle_{update_type}

Formatting & surfaces

  1. Markdown & Formatting — answers and md2html
  2. Public Web Commandsis_web static pages

User interactions

  1. Handling Callbacks — inline buttons
  2. Handling User Input — need reply sessions
  3. Using Aliases — multiple triggers
  4. Wildcard (*) — catch-all

Hands-on

  1. Your First Botstart here if you haven't built anything yet

Where to go next

Built /start already? Add a keyboard. Need buttons inside messages? Callbacks. Want a landing page? Public web.

The docs are modular — read what you need, skip what you don't.