For AI agents: markdown of this page — /docs-content-en/bots/commands/answer.md documentation index — /llms.txt

Answer a command

POST /v1/bots/:botId/commands/:commandId/answer

Sends a reply to a slash-command invocation. Call it from the ONIMBOTV2COMMANDADD event handler.

Parameters

Parameter Type Required Description
ParameterbotId (path) Typenumber Requiredyes DescriptionBot ID. List: GET /v1/bots
ParametercommandId (path) Typenumber Requiredyes DescriptionCommand ID. Returned in the command.id field of the ONIMBOTV2COMMANDADD bot event. The bot's commands: GET /v1/bots/:botId/commands

Request fields (body)

Parameter Type Required Description
ParametermessageId Typenumber Requiredyes DescriptionID of the message that invoked the command. Returned in the message.id field of the ONIMBOTV2COMMANDADD event
ParameterdialogId Typestring Requiredyes DescriptionDialog ID. For a group chat — chat{chatId}, for a private chat — {userId}. Returned in the chat.dialogId field of the ONIMBOTV2COMMANDADD event
Parameterfields Typeobject Requiredno DescriptionReply message fields
Parameterfields.message Typestring Requiredno DescriptionReply text. Supports BB-codes
Parameterfields.keyboard Typearray Requiredno DescriptionInteractive keyboard
Parameterfields.attach Typearray/object Requiredno DescriptionATTACH blocks
Parameterfields.system Typeboolean Requiredno DescriptionSystem message. Defaults to false
Parameterfields.urlPreview Typeboolean Requiredno DescriptionShow link previews. Defaults to true

Examples

curl — personal key

Terminal
curl -X POST https://vibecode.bitrix24.com/v1/bots/42/commands/7/answer \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messageId": 1510,
    "dialogId": "chat123",
    "fields": {
      "message": "[b]Task help[/b]\n\nAvailable actions:\n[SEND=/status]Check status[/SEND]\n[SEND=/create]Create task[/SEND]"
    }
  }'

curl — OAuth application

Terminal
curl -X POST https://vibecode.bitrix24.com/v1/bots/42/commands/7/answer \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "messageId": 1510,
    "dialogId": "chat123",
    "fields": {
      "message": "[b]Task help[/b]\n\nAvailable actions:\n[SEND=/status]Check status[/SEND]\n[SEND=/create]Create task[/SEND]"
    }
  }'

JavaScript — personal key

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/commands/7/answer', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    messageId: 1510,
    dialogId: 'chat123',
    fields: {
      message: '[b]Task help[/b]\n\nAvailable actions:\n[SEND=/status]Check status[/SEND]',
    },
  }),
})

const { success, data } = await res.json()

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/commands/7/answer', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    messageId: 1510,
    dialogId: 'chat123',
    fields: {
      message: '[b]Task help[/b]\n\nAvailable actions:\n[SEND=/status]Check status[/SEND]',
    },
  }),
})

const { success, data } = await res.json()

Response fields

Field Type Description
Fieldsuccess Typeboolean DescriptionAlways true on success
Fielddata Typeobject DescriptionResult of sending the reply
Fielddata.result Typeboolean Descriptiontrue when the reply was sent successfully

Response example

JSON
{
  "success": true,
  "data": {
    "result": true
  }
}

Error response example

404 — bot not found:

JSON
{
  "success": false,
  "error": {
    "code": "BOT_NOT_FOUND",
    "message": "Bot 999 not found. Register it first via POST /v1/bots."
  }
}

Errors

HTTP Code Description
HTTP400 CodeINVALID_BOT_ID DescriptionbotId is not a number
HTTP400 CodeINVALID_PARAMS DescriptioncommandId in the path must be a positive integer from 1 to 9007199254740991, without a sign, leading zeros, fraction, exponent or whitespace. Rejected before calling Bitrix24
HTTP404 CodeBOT_NOT_FOUND DescriptionNo bot found with this ID
HTTP403 CodeBOT_ACCESS_DENIED DescriptionThe bot belongs to a different API key
HTTP422 CodeBITRIX_ERROR DescriptionBitrix24 error (error text in message)
HTTP403 CodeSCOPE_DENIED DescriptionAPI key lacks the imbot scope
HTTP403 CodeWRITE_BLOCKED_READONLY_KEY DescriptionThe key is read-only — see access rights
HTTP410 CodeBOT_DISABLED DescriptionThe bot is disabled and does not process API calls. How to restore it — Bot disabled
HTTP401 CodeTOKEN_MISSING DescriptionAPI key has no configured tokens

Full list of common API errors — Errors.

Known specifics

No chat membership required: the bot can answer a command even if it is not a member of the chat. Access is granted temporarily through the messageId + commandId pair. If the bot is not a member, the reply is sent as a system message under the bot's name.

See also