Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(api): state the chat id form on send and action bodies

Yudhi Armyndharis7813693a01c2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d0cd488eb..1dfe525e2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -321,6 +321,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix the PHP SDK reading a `Retry-After` header of 309 or more digits as 0 seconds; it is now capped like a smaller oversized value.
- Do not mark a patch release on an older line as the GitHub Latest release, which the update check reads.
- Answer a body over `BODY_SIZE_LIMIT`, malformed JSON, a body nested past the bound and an undecodable path parameter under `/api` and `/mcp` with 413 or 400 when the bundled dashboard is served, where they answered `404 Cannot POST` ([#1921](https://github.com/rmyndharis/OpenWA/issues/1921)). Thanks @ScalingMBA for the report.
+- Answer a `chatId` that is not `localpart@host` on a send or message-action body, and on the MCP message tools, with `400` instead of `500`; a bare phone number reached the engine, and every such request counted against the session's send breaker.
### Dependencies
@@ -366,6 +367,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- A plugin catalog with an entry whose `id`, `name`, `version` or text field is not text is refused with `400`, naming the entry; the default catalog is unaffected, and a private `PLUGIN_CATALOG_URL` catalog must correct the entry.
- `POST /api/integration/instances/{pluginId}/{instanceId}/redrive` replays and counts only the dead letters written under the instance's current session binding; rows of an earlier binding stay in the dead-letter table.
- A per-session plugin config or an integration instance that sets a `net.allowConfigHosts` key (for example `baseUrl`) to another origin than the layer beneath no longer inherits that layer's `secret` fields, and a list holding one is not inherited either; put the secret in that config or instance, or the plugin reaches the new host without it. A deployment that shared one token across per-session hosts must copy the token to each.
+- A send or message-action body whose `chatId`, `fromChatId` or `toChatId` has no domain (`6281234567890` instead of `[email protected]`), or is a JSON number, answers `400`; it answered `500` before and never sent.
### Security
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index 6928df92c..f9996c5c0 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -147,7 +147,7 @@ All media send routes (`send-image`, `send-video`, `send-audio`, `send-document`
| Field | Type | Required | Constraints | Description |
| ---------- | -------- | ----------- | --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `chatId` | string | yes | non-empty, max 255 chars | Recipient — `<phone>@c.us` or `<groupId>@g.us` |
+| `chatId` | string | yes | non-empty, max 255 chars, `localpart@host` | Recipient — `<phone>@c.us` or `<groupId>@g.us` |
| `url` | string | conditional | valid http/https URL; required when `base64` absent | Remote media URL. Fetched server-side through an SSRF guard; a blocked/internal URL, a non-2xx answer, a timeout or a failed connection yields `400`, a download over the media cap `413` |
| `base64` | string | conditional | required when `url` absent | Raw base64 media data. Decoded size is checked against the media cap |
| `mimetype` | string | conditional | required when `base64` is used | MIME type, e.g. `image/jpeg`, `video/mp4`, `application/pdf` |
@@ -1257,10 +1257,10 @@ Send a typing/recording presence indicator to a chat (or clear it with `paused`)
**Request body** — `SendChatStateDto`
-| Field | Type | Required | Constraints | Description |
-| -------- | ----------------------------------- | -------- | --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
-| `chatId` | string | Yes | `@IsString`; `@IsNotEmpty`; `@MaxLength(255)` (no JID regex; engine-neutral, the adapter validates) | Engine-native chat id, e.g. `[email protected]` |
-| `state` | `typing` \| `recording` \| `paused` | Yes | `@IsIn(['typing','recording','paused'])` | `typing`/`recording` show the indicator; `paused` clears it |
+| Field | Type | Required | Constraints | Description |
+| -------- | ----------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
+| `chatId` | string | Yes | `@IsString`; `@IsNotEmpty`; `@MaxLength(255)`; `@Matches(/^[^\s@]+@[^\s@]+$/)` (localpart@host, no whitespace) | Engine-native chat id, e.g. `[email protected]` |
+| `state` | `typing` \| `recording` \| `paused` | Yes | `@IsIn(['typing','recording','paused'])` | `typing`/`recording` show the indicator; `paused` clears it |
```json
{ "chatId": "[email protected]", "state": "typing" }
@@ -1300,6 +1300,10 @@ The delete first removes the session's messages, webhook outbox rows and webhook
All routes are mounted under `/api/sessions/:sessionId/messages`. Reads (`GET` history, batch status, reactions) accept any valid API key (including VIEWER). All write/send routes require **API key (OPERATOR)** or higher. Single-recipient send routes return `MessageResponseDto { messageId, timestamp }` (`timestamp` is an epoch **number** in seconds; there is no `status` field); `POST send-bulk` instead returns `202` with `BulkMessageResponseDto`. The global ValidationPipe runs `whitelist` + `forbidNonWhitelisted`, so any body field not listed below is rejected with `400`.
+#### Chat ids
+
+A `chatId` (and `fromChatId` / `toChatId` on `forward`) in a send or message-action body, and the matching `chatId` of the MCP message tools, must be `localpart@host` with no whitespace, for example `[email protected]`, `[email protected]`, `[email protected]` or `1234567890123@lid`. A bare phone number, a number sent as a JSON number, or any other text without a domain answers `400` with `chatId must be a valid chat JID in the form localpart@host`; it used to reach the engine and answer `500`.
+
#### Idempotent sends
The single-recipient send routes (`send-text`, `send-template`, `send-image`, `send-video`, `send-audio`, `send-document`, `send-location`, `send-contact`, `send-sticker`, `send-poll`, `reply`, `forward`) accept an optional `Idempotency-Key` request header, so a client can retry after a timeout or a dropped connection without sending the message twice. Without the header nothing changes.
@@ -1768,7 +1772,7 @@ Send a plain text message.
| Field | Type | Required | Constraints | Description |
| ----------------- | -------- | -------- | ---------------------------------------- | -------------------------------------------------------------------------------------------- |
-| chatId | string | Yes | non-empty, max 255 | `[email protected]` or `[email protected]` |
+| chatId | string | Yes | non-empty, max 255, `localpart@host` | `[email protected]` or `[email protected]` |
| text | string | Yes | non-empty, max 4096 | Message text |
| mentions | string[] | No | array of WIDs, max 1024 of 64 characters | WIDs to @mention (e.g. `["[email protected]"]`). See **Mentions** below |
| linkPreview | boolean | No | — | `false` suppresses it; on Baileys `true` is required to get one. See **Link previews** below |
@@ -1894,7 +1898,7 @@ Render a stored text template (header/body/footer joined by blank lines, `{{vars
| Field | Type | Required | Constraints | Description |
| ------------ | ----------------------- | ----------- | ------------------------------------------------- | ----------------------------------------------------------- |
-| chatId | string | Yes | non-empty, max 255 | Target chat |
+| chatId | string | Yes | non-empty, max 255, `localpart@host` | Target chat |
| templateId | string | Conditional | non-empty; required when `templateName` is absent | Stored template id |
| templateName | string | Conditional | non-empty; required when `templateId` is absent | Stored template name |
| vars | Record\<string,string\> | No | object | Substituted into `{{placeholder}}` tokens; defaults to `{}` |
@@ -1935,7 +1939,7 @@ Send an image (by URL or base64) with an optional caption.
| Field | Type | Required | Constraints | Description |
| --------------- | -------- | ----------- | ---------------------------------------- | ---------------------------------------------------------------------------------------- |
-| chatId | string | Yes | non-empty, max 255 | Target chat |
+| chatId | string | Yes | non-empty, max 255, `localpart@host` | Target chat |
| url | string | Conditional | URL; required when `base64` is absent | http/https media URL (SSRF-guarded; a blocked internal or unreachable URL maps to `400`) |
| base64 | string | Conditional | string; required when `url` is absent | Base64 media data (capped to the media byte limit) |
| mimetype | string | Conditional | string; required when using `base64` | MIME type of the media |
@@ -2055,14 +2059,14 @@ Send a location pin.
**Request body** — `SendLocationDto`
-| Field | Type | Required | Constraints | Description |
-| --------------- | ------ | -------- | ------------------ | --------------------------------------------------------------------------------- |
-| chatId | string | Yes | non-empty, max 255 | Target chat |
-| latitude | number | Yes | valid latitude | Latitude (out-of-range → `400`) |
-| longitude | number | Yes | valid longitude | Longitude (out-of-range → `400`) |
-| description | string | No | string, max 1024 | Pin description |
-| address | string | No | string, max 1024 | Pin address |
-| quotedMessageId | string | No | non-empty | Quote an earlier message, making this a reply — see [Quoted sends](#quoted-sends) |
+| Field | Type | Required | Constraints | Description |
+| --------------- | ------ | -------- | ------------------------------------ | --------------------------------------------------------------------------------- |
+| chatId | string | Yes | non-empty, max 255, `localpart@host` | Target chat |
+| latitude | number | Yes | valid latitude | Latitude (out-of-range → `400`) |
+| longitude | number | Yes | valid longitude | Longitude (out-of-range → `400`) |
+| description | string | No | string, max 1024 | Pin description |
+| address | string | No | string, max 1024 | Pin address |
+| quotedMessageId | string | No | non-empty | Quote an earlier message, making this a reply — see [Quoted sends](#quoted-sends) |
```json
{
@@ -2096,12 +2100,12 @@ Send a contact card (vCard).
**Request body** — `SendContactDto`
-| Field | Type | Required | Constraints | Description |
-| --------------- | ------ | -------- | ------------------ | --------------------------------------------------------------------------------- |
-| chatId | string | Yes | non-empty, max 255 | Target chat |
-| contactName | string | Yes | non-empty, max 255 | Display name for the contact card |
-| contactNumber | string | Yes | non-empty, max 30 | Contact phone number |
-| quotedMessageId | string | No | non-empty | Quote an earlier message, making this a reply — see [Quoted sends](#quoted-sends) |
+| Field | Type | Required | Constraints | Description |
+| --------------- | ------ | -------- | ------------------------------------ | --------------------------------------------------------------------------------- |
+| chatId | string | Yes | non-empty, max 255, `localpart@host` | Target chat |
+| contactName | string | Yes | non-empty, max 255 | Display name for the contact card |
+| contactNumber | string | Yes | non-empty, max 30 | Contact phone number |
+| quotedMessageId | string | No | non-empty | Quote an earlier message, making this a reply — see [Quoted sends](#quoted-sends) |
```json
{ "chatId": "[email protected]", "contactName": "John Doe", "contactNumber": "628987654321" }
@@ -3812,11 +3816,11 @@ Send a product message (catalog product card) to a chat. Note: this route lives
**Request body** — `SendProductDto`
-| Field | Type | Required | Constraints | Description |
-| ----------- | ------ | -------- | --------------------------------------- | ----------------------------------------------------------------- |
-| `chatId` | string | Yes | `@IsString @IsNotEmpty @MaxLength(255)` | Target chat/recipient id (e.g. `[email protected]`). |
-| `productId` | string | Yes | `@IsString @IsNotEmpty @MaxLength(255)` | Catalog product id to send. |
-| `body` | string | No | `@IsString @MaxLength(4096)` | Optional message body/caption; `null` is the same as omitting it. |
+| Field | Type | Required | Constraints | Description |
+| ----------- | ------ | -------- | --------------------------------------------------------------------- | ----------------------------------------------------------------- |
+| `chatId` | string | Yes | `@IsString @IsNotEmpty @MaxLength(255) @Matches(/^[^\s@]+@[^\s@]+$/)` | Target chat/recipient id (e.g. `[email protected]`). |
+| `productId` | string | Yes | `@IsString @IsNotEmpty @MaxLength(255)` | Catalog product id to send. |
+| `body` | string | No | `@IsString @MaxLength(4096)` | Optional message body/caption; `null` is the same as omitting it. |
```json
{