Learning TBL¶
TBL is JavaScript — not a lookalike, not a dialect. You write real JavaScript in the Logic field: variables, if, loops, await, objects, all of it.
What makes it faster for bot building is what's already there: Bot, Api, user, chat, db, modules, and Libs. No npm install, no Express server, no wiring up a Telegram library before your first Bot.sendMessage().
You write logic inside commands. Telegram sends an update, TBL picks a command, your JavaScript runs, execution ends. That's the whole lifecycle. No event loop babysitting required.
The command lifecycle¶
Every interaction follows the same path:
Special wrappers @ (before) and @@ (after) run automatically around other commands. Details: Execution Flow.
Think of it like a vending machine: user picks a snack (sends a command), machine dispenses (Answer + Logic), transaction complete. No machine sitting there idle between customers.
Sync by default¶
Lines run in order. Most Bot and Api calls work that way out of the box — call it, move on.
When you need a response before continuing — grab a message id, check whether send succeeded, verify channel membership — add await:
Don't sprinkle await on calls where you ignore the result. Async isn't a seasoning — use it when you're actually waiting for something.
Common async cases:
| What | Example |
|---|---|
| Edit a message you just sent | await Api.sendMessage(...) |
| Check channel membership | await Libs.mcl.quick(user.id, ["@Channel"]) |
| Parse CSV / hash password | await modules.ParseCSV.parse(...) |
Your first line of code¶
Drop this in a command's Logic field:
Trigger the command on Telegram — you get a reply. For simple text responses, you often only need the Answer field — no Logic required. Logic is where things get interesting.
Globals
chat.id is where the message goes. user is who sent the command. Full list: Global Variables.
JavaScript extras — already there¶
You never write import or require. On top of standard JavaScript, these bot-building globals are ready on day one:
| Global | What it is |
|---|---|
Bot | High-level bot helpers — send messages, run commands, storage |
Api | Raw Telegram API — keyboards, edits, file uploads |
user | Who triggered this command |
chat | Where the message came from |
params | Text after the command (e.g. /start promo → "promo") |
modules | npm-style utilities — JWT, bcrypt, CSV, etc. |
Libs | Bot helpers — referrals, random, channel checks |
When to use Bot vs Api? Bot vs Api — short answer: Bot for everyday replies, Api when you need full control.
Beyond basic replies¶
| Feature | Start here |
|---|---|
| Formatted answers | Markdown & Formatting |
| Reply keyboard menus | Adding a Keyboard |
| Inline button taps | Handling Callbacks |
| Wait for user text | Handling User Input |
| Static web page | Public Web Commands |
| HTTP API from command | Webapps |
Where to go¶
- Command Flow — structured multi-page guide
- Tutorials — hands-on lessons in order
- Command Fields — Answer, Logic, keyboard,
is_web - Global Variables —
user,chat,update - Bot and Api — main instances
- Modules and Libs — built-in toolboxes