[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-chats\u002Fservice\u002Fbot-context":3,"docs-tabs-chats\u002Fservice\u002Fbot-context":6},{"content":4,"lastmod":5},"## Context for bots\n\n`POST \u002Fv1\u002Fchats\u002F:dialogId\u002Fbot-context`\n\nPasses 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.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|----------|\n| `dialogId` (path) | string | yes | Dialog 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](\u002Fdocs\u002Fchats\u002Fdiscovery\u002Frecent) row; the user ID comes from the [user list](\u002Fdocs\u002Fentities\u002Fusers\u002Flist) |\n\n## Request body fields\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|----------|\n| `context` | object | yes | Data for the bots — any JSON object. Arrays, strings, numbers and `null` are rejected |\n\nAny other body field and any query parameter are rejected with `400 INVALID_PARAMS`.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fbot-context\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"context\": {\"page\": \"deal\", \"dealId\": 128}}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fbot-context\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"context\": {\"page\": \"deal\", \"dealId\": 128}}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fbot-context', {\n  method: 'POST',\n  headers: { 'X-Api-Key': 'YOUR_API_KEY', 'Content-Type': 'application\u002Fjson' },\n  body: JSON.stringify({ context: { page: 'deal', dealId: 128 } }),\n})\n\nconst { data } = await res.json()\nconsole.log('Context delivered:', data.result)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fbot-context', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ context: { page: 'deal', dealId: 128 } }),\n})\n\nconst { data } = await res.json()\nconsole.log('Context delivered:', data.result)\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data.result` | boolean | `true` — the context reached the bots' handlers |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": { \"result\": true }\n}\n```\n\n## Error response example\n\n422 — the chat has no bots with a context handler:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"BITRIX_ERROR\",\n    \"message\": \"BOT_CONTEXT_ERROR\",\n    \"b24Code\": \"BOT_CONTEXT_ERROR\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | `context` is missing or is not a JSON object, or another body field or query parameter was passed |\n| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |\n| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only |\n| 404 | `ENTITY_NOT_FOUND` | Bitrix24 returned \"not found\". The Bitrix24 code is in `error.b24Code` |\n| 422 | `BITRIX_ERROR` | Bitrix24 returned an error. The Bitrix24 code is in `error.b24Code`. `BOT_CONTEXT_ERROR` — the chat has no bots that accepted the context |\n| 502 | `ME_ALIAS_RESOLUTION_FAILED` | Failed to resolve the current user for `me` |\n| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable or returned a server error |\n\nThe full list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n- `context` is passed to the bots as is: the platform does not rename its keys.\n- The chat type, the caller's ID, the chat author and the entity the chat is bound to are added to the context.\n- The call may make the caller a chat member if the chat allows auto-join.\n\n## See also\n\n- [Bot platform](\u002Fdocs\u002Fbots)\n- [Service methods](\u002Fdocs\u002Fchats\u002Fservice)\n","2026-10-07",{},1794739551403]