
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. Bots.Business supplies objects such as Bot, User, Api, and HTTP; you do not import them.
For editing local command files, see VS Code. To let an AI client inspect or edit commands through your account, connect Bots.Business MCP. Each guide explains how its changes reach the bot.
New to programming? Start with JavaScript basics for BJS beginners: 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:
var name = user && user.first_name ? user.first_name : "there";
Bot.sendMessage("Hello, " + name + "!", { parse_mode: null });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
A message, callback, scheduled command, or another supported trigger selects a command.
Its BJS code runs with that trigger's context.
Calls such as
Bot.sendMessageandHTTP.getcreate actions for Bots.Business to process.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 returns response data to a success command; Telegram API uses on_result and on_error.
Local variables are for one execution. Save information needed by a later message in properties. Calling another command does not make the current execution wait for a JavaScript return value.
Choose a reference
Understand user, chat, request, params, and options
Send/edit messages, add keyboards, or call another command
Save settings or a user's progress
Use Telegram methods and result callbacks
Call an external HTTP service
Create settings editable in the app
Work with lists of properties or users
Return JSON to a web request; understand the current HTML restriction
Schedule work or reuse command code
Send a command to multiple chats
Respond to inline queries or button clicks
Reuse a stable response
Diagnose a failed command
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 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, 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.
Last updated
Was this helpful?