For AI agents: markdown of this page — /docs-content-en/chats/service/bot-context.md documentation index — /llms.txt

Context for bots

POST /v1/chats/:dialogId/bot-context

Passes an arbitrary context object to the chat's bots. The context is supplemented with chat data and passed to the context handlers of the bots connected to the chat.

Parameters

Parameter Type Required Description
ParameterdialogId (path) Typestring Requiredyes DescriptionDialog ID: chat123 for a group chat, a user ID for a private chat, me for the chat with yourself. chat123 is the id field of a recent dialogs row; the user ID comes from the user list

Request body fields

Field Type Required Description
Fieldcontext Typeobject Requiredyes DescriptionData for the bots — any JSON object. Arrays, strings, numbers and null are rejected

Any other body field and any query parameter are rejected with 400 INVALID_PARAMS.

Examples

curl — personal key

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/chats/chat42/bot-context" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"context": {"page": "deal", "dealId": 128}}'

curl — OAuth application

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/chats/chat42/bot-context" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"context": {"page": "deal", "dealId": 128}}'

JavaScript — personal key

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/chat42/bot-context', {
  method: 'POST',
  headers: { 'X-Api-Key': 'YOUR_API_KEY', 'Content-Type': 'application/json' },
  body: JSON.stringify({ context: { page: 'deal', dealId: 128 } }),
})

const { data } = await res.json()
console.log('Context delivered:', data.result)

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/chat42/bot-context', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ context: { page: 'deal', dealId: 128 } }),
})

const { data } = await res.json()
console.log('Context delivered:', data.result)

Response fields

Field Type Description
Fieldsuccess Typeboolean DescriptionAlways true on success
Fielddata.result Typeboolean Descriptiontrue — the context reached the bots' handlers

Response example

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

Error response example

422 — the chat has no bots with a context handler:

JSON
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "BOT_CONTEXT_ERROR",
    "b24Code": "BOT_CONTEXT_ERROR"
  }
}

Errors

HTTP Code Description
HTTP400 CodeINVALID_PARAMS Descriptioncontext is missing or is not a JSON object, or another body field or query parameter was passed
HTTP401 CodeTOKEN_MISSING DescriptionThe API key has no Bitrix24 tokens configured
HTTP403 CodeSCOPE_DENIED DescriptionThe API key does not have the im scope
HTTP403 CodeWRITE_BLOCKED_READONLY_KEY DescriptionThe key is read-only
HTTP404 CodeENTITY_NOT_FOUND DescriptionBitrix24 returned "not found". The Bitrix24 code is in error.b24Code
HTTP422 CodeBITRIX_ERROR DescriptionBitrix24 returned an error. The Bitrix24 code is in error.b24Code. BOT_CONTEXT_ERROR — the chat has no bots that accepted the context
HTTP502 CodeME_ALIAS_RESOLUTION_FAILED DescriptionFailed to resolve the current user for me
HTTP502 CodeBITRIX_UNAVAILABLE DescriptionBitrix24 is unavailable or returned a server error

The full list of common API errors — Errors.

Known specifics

  • context is passed to the bots as is: the platform does not rename its keys.
  • The chat type, the caller's ID, the chat author and the entity the chat is bound to are added to the context.
  • The call may make the caller a chat member if the chat allows auto-join.

See also