> For the complete documentation index, see [llms.txt](https://help.bots.business/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.bots.business/bjs-reference/bjs.md).

# Coding with BJS

Write Bots.Business commands with BJS, understand execution and callbacks, and choose the right API for messages, data, and integrations.

BJS is the JavaScript environment used by Bots.Business commands. Use it when a command needs conditions, saved data, buttons, an API request, or another action that a fixed Answer cannot provide.

You write the body of a command in the mobile [command editor](/build-bot-behavior/commands.md). Bots.Business supplies objects such as `Bot`, `User`, `Api`, and `HTTP`; you do not import them.

For editing local command files, see [VS Code](/import-and-integrations/vscode.md). To let an AI client inspect or edit commands through your account, [connect Bots.Business MCP](/import-and-integrations/mcp.md). Each guide explains how its changes reach the bot.

New to programming? Start with [JavaScript basics for BJS beginners](/start-here/javascript-basics.md): variables, conditions, loops, functions, and a small command you can build yourself.

## Your first BJS command

Create a command named `/hello`, open its BJS editor, save this code, then send `/hello` to your bot:

{% code title="Your first BJS command · Example 1" overflow="wrap" %}

```javascript
var name = user && user.first_name ? user.first_name : "there";
Bot.sendMessage("Hello, " + name + "!", { parse_mode: null });
```

{% endcode %}

The bot replies in the current chat. `user` describes the person in this execution; `Bot.sendMessage` requests an outgoing message. Plain-text mode prevents a name containing formatting characters from changing the message.

## How execution works

1. A message, callback, scheduled command, or another supported trigger selects a command.
2. Its BJS code runs with that trigger's context.
3. Calls such as `Bot.sendMessage` and `HTTP.get` create actions for Bots.Business to process.
4. A result callback starts another named command. Read its result from the appropriate callback variables.

Do not assign an HTTP or Telegram action to a variable and expect the remote response immediately. [HTTP](/bjs-reference/http.md) returns response data to a `success` command; [Telegram API](/bjs-reference/telegram-api.md) uses `on_result` and `on_error`.

Local variables are for one execution. Save information needed by a later message in [properties](/bjs-reference/user-properties.md). Calling another command does not make the current execution wait for a JavaScript return value.

## Choose a reference

| Task                                                                  | Start here                                                        |
| --------------------------------------------------------------------- | ----------------------------------------------------------------- |
| Understand `user`, `chat`, `request`, `params`, and `options`         | [Context and variables](/bjs-reference/context.md)                |
| Send/edit messages, add keyboards, or call another command            | [Bot methods](/bjs-reference/bot.md)                              |
| Save settings or a user's progress                                    | [User and bot properties](/bjs-reference/user-properties.md)      |
| Use Telegram methods and result callbacks                             | [Telegram API](/bjs-reference/telegram-api.md)                    |
| Call an external HTTP service                                         | [HTTP requests](/bjs-reference/http.md)                           |
| Create settings editable in the app                                   | [Admin Panel](/bjs-reference/admin-panel.md)                      |
| Work with lists of properties or users                                | [Lists](/bjs-reference/lists.md)                                  |
| Return JSON to a web request; understand the current HTML restriction | [Web App](/bjs-reference/web-app.md)                              |
| Schedule work or reuse command code                                   | [Background work and command hooks](/bjs-reference/background.md) |
| Send a command to multiple chats                                      | [BJS broadcasts](/bjs-reference/broadcasts.md)                    |
| Respond to inline queries or button clicks                            | [Inline interactions](/bjs-reference/inline.md)                   |
| Reuse a stable response                                               | [Caching](/bjs-reference/caching.md)                              |
| Diagnose a failed command                                             | [BJS errors](/bjs-reference/errors.md)                            |

## Language and limits

Use ordinary JavaScript expressions, functions, arrays, objects, conditions, and bounded loops. This environment does not provide a browser DOM, Node.js modules, or a general asynchronous application process. `require`, top-level `await`, Promises, `queueMicrotask`, the `Function` constructor, Proxy construction, and WebAssembly are not available for ordinary BJS use. Use [command scheduling](/bjs-reference/background.md) instead of timers.

Execution has time, memory, and action limits. Keep a command focused and avoid a loop that makes one request for every user. Use Lists pagination and the broadcast task mechanism where appropriate.

## If your command does not reply

Check that the command was saved, the bot is running, and the exact command name matches the message. Open the bot's [error log](/bjs-reference/errors.md), then test a single `Bot.sendMessage("Hello")` before restoring more code. A command triggered without a chat may need an explicit destination or a non-message result, such as `WebApp.render`.

Next: [understand the execution context](/bjs-reference/context.md).
