## Send a message

`POST /v1/chats/:dialogId/messages`

Sends a text message to the given dialog. The text supports BB codes for formatting; you can add a keyboard and attachments to the message.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `dialogId` (path) | string | yes | Dialog identifier. Numeric user ID for personal messages (user list: [`GET /v1/users`](/docs/entities/users)). `chatXXX` for group chats. Accepts the value `me` — see below |
| `format` (query) | string | no | `v2` turns on the v2 mode — see "The v2 mode" below. Any other value is ignored and the response is unchanged. A repeated `format` is not rejected: with `format=v1&format=v2` the last value wins, so the v2 mode is on, while `format=v2&format=v1` returns the legacy response. The bracket form `format[]=v2` turns on the v2 mode when all its values are `v2` |

**The `me` alias.** Instead of a numeric user ID you can pass the string `me`: the dialog opens with the current key owner. Learn more in [Chats and messages](/docs/chats).

**The v2 mode.** `format=v2` sends the message. The body stays flat — the same fields as below — and `data` carries the object `{ id, uuidMap, failureMap }` instead of a number. The mode accepts only the fields in the table below, including those marked "the v2 mode only". Any other body field, uppercase forms (`MESSAGE`, `REPLY_ID`) and query parameters other than `format` are rejected with `400 INVALID_PARAMS`, which names the field without repeating its value. In the v2 mode `message` must be a string. The message must have content: non-empty text. Whitespace-only text is accepted only with a non-empty `attach`. Without `message`, a non-empty `attach`, `stickerParams` or `block` is required. Otherwise the route returns `400 MESSAGE_REQUIRED` before any call to the Bitrix24 account. Forwarding goes through [`POST /v1/chats/:dialogId/forward`](/docs/chats/messages/forward): in the v2 mode the `forwardIds` field is rejected with an error that points to that endpoint, and `botId` with one that points to [sending as a bot](/docs/bots).

## Request body fields

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `message` | string | no | Message text — up to 20000 Unicode code points. Supports BB codes. Can be omitted when a non-empty `attach`, `keyboard` or `menu` is passed; in the v2 mode — a non-empty `attach`, `stickerParams` or `block` |
| `attach` | array | no | Attachments: cards, tables, images, files, dividers |
| `keyboard` | array | no | Interactive buttons under the message |
| `menu` | array | no | Message context menu items |
| `replyId` | number | no | ID of the quoted message |
| `system` | boolean | no | When `true`, the message uses the system style (no avatar, `authorId = 0`) |
| `urlPreview` | boolean | no | When `false`, disables link preview in the text |
| `skipConnector` | boolean | no | The v2 mode only: do not pass the message to the Open Channels connector. `true`/`false` or `"Y"`/`"N"` |
| `silentConnector` | boolean | no | The v2 mode only: pass the message to the Open Channels connector without notifying the client. `true`/`false` or `"Y"`/`"N"` |
| `templateId` | string | no | The v2 mode only: your own message identifier, from 1 to 255 characters. A longer value is rejected with `400` rather than truncated |
| `stickerParams` | object | no | The v2 mode only: a sticker. If any of the three fields below is missing, the Bitrix24 account rejects the send with `422 BITRIX_ERROR` and `b24Code` `STICKER_SENDING_ERROR` |
| `stickerParams.id` | number | yes | Sticker ID — the `data.stickers[].id` field of the [list of sticker packs](/docs/chats/stickers/packs). Required when `stickerParams` is passed |
| `stickerParams.packId` | number | yes | Sticker pack ID — the `data.stickers[].packId` field of the [list of sticker packs](/docs/chats/stickers/packs). Required when `stickerParams` is passed |
| `stickerParams.packType` | string | yes | Pack type: `vendor` — built-in, `custom` — a user's pack. The `data.stickers[].packType` field of the [list of sticker packs](/docs/chats/stickers/packs). Required when `stickerParams` is passed |
| `block` | object\|array | no | The v2 mode only: message blocks in the Bitrix24 format. The Bitrix24 account validates them and builds the text from them |
| `copilot` | object | no | The v2 mode only: CoPilot parameters for the message, passed as is |
| `aiAssistant` | object | no | The v2 mode only: AI assistant parameters for the message, passed as is |

## Message layout

- [Text formatting](/docs/chats/messages/formatting) — BB codes: bold, italic, links, color
- [Keyboard](/docs/chats/messages/keyboard) — interactive buttons under the message
- [Attachments](/docs/chats/messages/attach) — cards, tables, images, files

The `message` text is limited to 20000 Unicode code points. The complete outgoing string is counted, including markup, URLs and mentions, without truncation or trimming. For example, `😀` is one code point, while a compound emoji may occupy several. The request is rejected before any call to Bitrix24.

Without `format=v2`, matching text aliases `message`, `MESSAGE`, `Message` and `fields.message` are accepted, including other case variants. Their values must agree. A conflict returns `400 INVALID_PARAMS`. An object is never converted to text. The v2 mode keeps its flat body whitelist: case variants and `fields` are not accepted.

## Examples

In the examples, `dialogId` is `42` — the recipient's numeric user ID.

### curl — personal key

```bash
curl -X POST https://vibecode.bitrix24.com/v1/chats/42/messages \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Invoice issued. Please await confirmation."
  }'
```

### curl — OAuth application

```bash
curl -X POST https://vibecode.bitrix24.com/v1/chats/42/messages \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Invoice issued. Please await confirmation."
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/42/messages', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    message: 'Invoice issued. Please await confirmation.',
  }),
})

const { success, data } = await res.json()
console.log('Message ID:', data)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/42/messages', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    message: 'Invoice issued. Please await confirmation.',
  }),
})

const { success, data } = await res.json()
console.log('Message ID:', data)
```

### curl — the v2 mode

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/chats/42/messages?format=v2" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Invoice issued. Please await confirmation.",
    "urlPreview": false
  }'
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | number | ID of the created message |
| `data.id` | number | The v2 mode: ID of the created message |
| `data.uuidMap` | array\|object | The v2 mode: mapping of forwarding identifiers to messages. Empty for a regular send |
| `data.failureMap` | array\|object | The v2 mode: forwarding failures. Empty for a regular send |

## Response example

The regular mode:

```json
{
  "success": true,
  "data": 36889
}
```

The v2 mode — `format=v2`:

```json
{
  "success": true,
  "data": {
    "id": 36889,
    "uuidMap": [],
    "failureMap": []
  }
}
```

## Error response example

400 — no message text was passed:

```json
{
  "success": false,
  "error": {
    "code": "MESSAGE_REQUIRED",
    "message": "Message is empty. Put the message text in the \"message\" field (or send an \"attach\" block)."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `MESSAGE_TOO_LONG` | More than 20000 Unicode code points in the outgoing text. `error.details` contains only `field: "message"`, `used`, `limit: 20000`, `unit: "unicode-code-points"`. No Bitrix24 call is made |
| 400 | `MESSAGE_REQUIRED` | The `message` field is empty and there is no non-empty `attach`, `keyboard` or `menu`. One of the causes is text passed under an unknown field name, for example `text`. The error `message` lists the unrecognized fields. In the v2 mode, the rule from "The v2 mode" paragraph above applies instead |
| 400 | `INVALID_PARAMS` | Conflicting legacy text aliases. The v2 mode only: a body field outside the list, a query parameter other than `format` or an invalid value. Checked before any call to Bitrix24 |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — see [access rights](/docs/access-rights) |
| 404 | `ENTITY_NOT_FOUND` | Bitrix24 reported "not found". The Bitrix24 code is in `error.b24Code` — only in the v2 mode |
| 422 | `BITRIX_ERROR` | Bitrix24 returned an error — dialog not found or unavailable (details in `message`). The Bitrix24 code is in `error.b24Code` |
| 502 | `ME_ALIAS_RESOLUTION_FAILED` | `dialogId=me` — failed to resolve the current user's ID |
| 403 | `BITRIX_ACCESS_DENIED` | The v2 mode only: the user has no access to the chat — Bitrix24 refused with the `ACCESS_DENIED` code |
| 403 | `SCOPE_DENIED` | The key does not have the `im` scope |
| 401 | `TOKEN_MISSING` | The key has no configured tokens |

Full list of common API errors — [Errors](/docs/errors).

## Known specifics

**The Bitrix24 refusal code.** The Bitrix24 refusal code arrives in `error.b24Code`. In a `404 ENTITY_NOT_FOUND` response this field is present only in the v2 mode.

## See also

- [Messages](/docs/chats/messages)
- [Edit a message](/docs/chats/messages/update)
- [Delete a message](/docs/chats/messages/delete)
