Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(api): publish quotedMessageId and mirror it on the MCP send tools

Yudhi Armyndharisf4b738ec4021
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9ce901c80..b49b8e703 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Turkish (`tr`) dashboard translation. Thanks @codedByCan.
- `AUDIT_RETENTION_DAYS` is checked at boot, so a typo fails startup with a named error instead of silently reverting to the 90-day default. It is validated as non-negative rather than positive, because `0` is the documented switch that disables audit-log pruning entirely.
- `message.controller.spec.ts` holds the two headers the stored-media download sends, `X-Content-Type-Options: nosniff` and `Content-Disposition: attachment`; deleting either had passed every suite in the repo.
+- Optional `quotedMessageId` on every `send-*` message endpoint and its MCP tool, so a reply can carry media, a location, a contact card or a poll instead of only text. An id the engine cannot resolve now fails the send rather than delivering the message unquoted. Thanks @nirizr for the report.
### Fixed
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index 599b7388c..302d2859d 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -1439,6 +1439,7 @@ Send a plain text message.
| mentions | string[] | No | array of WIDs | 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 |
| customLinkPreview | object | No | `{ url, title, description? }` | Attach a preview you supply. **Baileys only.** See **Link previews** below |
+| quotedMessageId | string | No | non-empty | Quote an earlier message, making this a reply. See [Quoted sends](#quoted-sends) below |
```json
{ "chatId": "[email protected]", "text": "Hello from OpenWA!" }
@@ -1493,6 +1494,40 @@ rejected with `400` rather than guessing which half was meant.
**Errors:** `400` unknown body field, validation failure, or session not active / blocked by a plugin hook · `401` missing/invalid API key · `403` key role below OPERATOR · `404` session not found · `500` engine error
+##### Quoted sends
+
+Every `send-*` route above accepts an optional `quotedMessageId`. Supplying it turns that send into a
+reply, so a reply can carry media, a location, a contact card or a poll — not only text.
+`POST .../messages/reply` is unchanged and remains the text shorthand.
+
+```json
+{
+ "chatId": "[email protected]",
+ "contactName": "Alice",
+ "contactNumber": "628999888777",
+ "quotedMessageId": "[email protected]_3EB0ABCD"
+}
+```
+
+**The id is engine-specific and is deliberately not harmonised.**
+
+| | whatsapp-web.js | Baileys |
+| -------------------- | ------------------------------------------------ | --------------------------------- |
+| id to supply | the serialized message id (`true_<chat>_<hash>`) | the raw message key id |
+| where it is resolved | in the WhatsApp Web page | the gateway's local message store |
+| message not found | `404` — the send is refused | `404` — the send is refused |
+
+An id the engine cannot resolve **fails the send** rather than delivering the message unquoted. On
+whatsapp-web.js that is a deliberate choice: the library's default is to send anyway and report
+success, which would hand back `201` for a message that is not a reply.
+
+One upstream gap remains on whatsapp-web.js and cannot be switched off from here: if the quoted
+message resolves but the page decides it is not replyable, the message is sent without the quote and
+the call still succeeds.
+
+Quoting a message from a **different chat** is not validated on either engine; the id is passed
+through as given.
+
#### POST /api/sessions/:sessionId/messages/send-template
Render a stored text template (header/body/footer joined by blank lines, `{{vars}}` substituted) and send it as text.
@@ -1546,14 +1581,15 @@ Send an image (by URL or base64) with an optional caption.
**Request body** — `SendMediaMessageDto`
-| Field | Type | Required | Constraints | Description |
-| -------- | ------ | ----------- | ------------------------------------- | ------------------------------------------------------------------------- |
-| chatId | string | Yes | non-empty | Target chat |
-| url | string | Conditional | URL; required when `base64` is absent | http/https media URL (SSRF-guarded; a blocked internal 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 |
-| filename | string | No | max 255 | File name |
-| caption | string | No | max 1024 | Caption text |
+| Field | Type | Required | Constraints | Description |
+| --------------- | ------ | ----------- | ------------------------------------- | --------------------------------------------------------------------------------- |
+| chatId | string | Yes | non-empty | Target chat |
+| url | string | Conditional | URL; required when `base64` is absent | http/https media URL (SSRF-guarded; a blocked internal 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 |
+| filename | string | No | max 255 | File name |
+| caption | string | No | max 1024 | Caption text |
+| quotedMessageId | string | No | non-empty | Quote an earlier message, making this a reply — see [Quoted sends](#quoted-sends) |
```json
{ "chatId": "[email protected]", "url": "https://example.com/image.jpg", "caption": "Check out this image!" }
@@ -1579,7 +1615,7 @@ Send a video (by URL or base64) with an optional caption. Uses the same `SendMed
| --------- | ------ | ----------- |
| sessionId | string | Session ID |
-**Request body** — `SendMediaMessageDto` (fields `chatId`, `url`, `base64`, `mimetype`, `filename`, `caption` — see `send-image`)
+**Request body** — `SendMediaMessageDto` (fields `chatId`, `url`, `base64`, `mimetype`, `filename`, `caption`, `quotedMessageId` — see `send-image`)
```json
{ "chatId": "[email protected]", "url": "https://example.com/clip.mp4", "caption": "video" }
@@ -1631,7 +1667,7 @@ Send a document/file (by URL or base64). Uses `SendMediaMessageDto`; `filename`
| --------- | ------ | ----------- |
| sessionId | string | Session ID |
-**Request body** — `SendMediaMessageDto` (fields `chatId`, `url`, `base64`, `mimetype`, `filename`, `caption` — see `send-image`)
+**Request body** — `SendMediaMessageDto` (fields `chatId`, `url`, `base64`, `mimetype`, `filename`, `caption`, `quotedMessageId` — see `send-image`)
```json
{
@@ -1666,13 +1702,14 @@ Send a location pin.
**Request body** — `SendLocationDto`
-| Field | Type | Required | Constraints | Description |
-| ----------- | ------ | -------- | --------------- | -------------------------------- |
-| chatId | string | Yes | non-empty | 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 | Pin description |
-| address | string | No | string | Pin address |
+| Field | Type | Required | Constraints | Description |
+| --------------- | ------ | -------- | --------------- | --------------------------------------------------------------------------------- |
+| chatId | string | Yes | non-empty | 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 | Pin description |
+| address | string | No | string | Pin address |
+| quotedMessageId | string | No | non-empty | Quote an earlier message, making this a reply — see [Quoted sends](#quoted-sends) |
```json
{
@@ -1706,11 +1743,12 @@ Send a contact card (vCard).
**Request body** — `SendContactDto`
-| Field | Type | Required | Constraints | Description |
-| ------------- | ------ | -------- | ----------- | --------------------------------- |
-| chatId | string | Yes | non-empty | Target chat |
-| contactName | string | Yes | non-empty | Display name for the contact card |
-| contactNumber | string | Yes | non-empty | Contact phone number |
+| Field | Type | Required | Constraints | Description |
+| --------------- | ------ | -------- | ----------- | --------------------------------------------------------------------------------- |
+| chatId | string | Yes | non-empty | Target chat |
+| contactName | string | Yes | non-empty | Display name for the contact card |
+| contactNumber | string | Yes | non-empty | 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" }
@@ -1736,7 +1774,7 @@ Send a sticker (by URL or base64; typically webp). Reuses `SendMediaMessageDto`.
| --------- | ------ | ----------- |
| sessionId | string | Session ID |
-**Request body** — `SendMediaMessageDto` (fields `chatId`, `url`, `base64`, `mimetype`, `filename`, `caption` — see `send-image`)
+**Request body** — `SendMediaMessageDto` (fields `chatId`, `url`, `base64`, `mimetype`, `filename`, `caption`, `quotedMessageId` — see `send-image`)
```json
{ "chatId": "[email protected]", "url": "https://example.com/sticker.webp", "mimetype": "image/webp" }
@@ -1764,12 +1802,13 @@ Send a native WhatsApp poll.
**Request body** — `SendPollDto`
-| Field | Type | Required | Constraints | Description |
-| -------------------- | -------- | -------- | ----------------------------------------- | ----------------------------------------------------- |
-| chatId | string | Yes | non-empty | Target chat |
-| name | string | Yes | max 255 | Poll question / title |
-| options | string[] | Yes | 2–12 items, each non-empty, max 100 chars | Options to vote on |
-| allowMultipleAnswers | boolean | No | — | Allow picking several options (default single choice) |
+| Field | Type | Required | Constraints | Description |
+| -------------------- | -------- | -------- | ----------------------------------------- | ------------------------------------------------------------ |
+| chatId | string | Yes | non-empty | Target chat |
+| name | string | Yes | max 255 | Poll question / title |
+| options | string[] | Yes | 2–12 items, each non-empty, max 100 chars | Options to vote on |
+| allowMultipleAnswers | boolean | No | — | Allow picking several options (default single choice) |
+| quotedMessageId | string | No | non-empty | Quote an earlier message — see [Quoted sends](#quoted-sends) |
```json
{
diff --git a/openapi.json b/openapi.json
index aee8d6f86..e0e982596 100644
--- a/openapi.json
+++ b/openapi.json
@@ -2501,6 +2501,17 @@
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendLocationDto"
+ },
+ "examples": {
+ "minimal": {
+ "summary": "Share a location",
+ "value": {
+ "chatId": "[email protected]",
+ "latitude": -6.2088,
+ "longitude": 106.8456,
+ "description": "Jakarta"
+ }
+ }
}
}
}
@@ -2549,6 +2560,16 @@
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendContactDto"
+ },
+ "examples": {
+ "minimal": {
+ "summary": "Share a contact card",
+ "value": {
+ "chatId": "[email protected]",
+ "contactName": "Alice",
+ "contactNumber": "628999888777"
+ }
+ }
}
}
}
@@ -2657,6 +2678,19 @@
"application/json": {
"schema": {
"$ref": "#/components/schemas/SendPollDto"
+ },
+ "examples": {
+ "minimal": {
+ "summary": "Ask a single-choice poll",
+ "value": {
+ "chatId": "[email protected]",
+ "name": "Where should we meet?",
+ "options": [
+ "Park",
+ "Beach"
+ ]
+ }
+ }
}
}
}
@@ -10570,6 +10604,11 @@
"$ref": "#/components/schemas/CustomLinkPreviewDto"
}
]
+ },
+ "quotedMessageId": {
+ "type": "string",
+ "description": "Quote an earlier message, turning this send into a reply. The id is engine-specific: whatsapp-web.js matches the serialized message id, Baileys matches the raw message key id and can only quote a message it has already stored. An id that cannot be resolved fails the send rather than delivering it unquoted.",
+ "example": "[email protected]_3EB0ABCD"
}
},
"required": [
@@ -10669,6 +10708,11 @@
"items": {
"type": "string"
}
+ },
+ "quotedMessageId": {
+ "type": "string",
+ "description": "Quote an earlier message, turning this send into a reply. The id is engine-specific: whatsapp-web.js matches the serialized message id, Baileys matches the raw message key id and can only quote a message it has already stored. An id that cannot be resolved fails the send rather than delivering it unquoted.",
+ "example": "[email protected]_3EB0ABCD"
}
},
"required": [
@@ -10718,6 +10762,11 @@
"type": "string"
}
},
+ "quotedMessageId": {
+ "type": "string",
+ "description": "Quote an earlier message, turning this send into a reply. The id is engine-specific: whatsapp-web.js matches the serialized message id, Baileys matches the raw message key id and can only quote a message it has already stored. An id that cannot be resolved fails the send rather than delivering it unquoted.",
+ "example": "[email protected]_3EB0ABCD"
+ },
"ptt": {
"type": "boolean",
"description": "Send as a WhatsApp voice note (PTT — mic bubble + waveform). Provide audio/ogg; codecs=opus bytes for reliable playback; when the mimetype is omitted it defaults to that for voice notes. Expects a JSON boolean. Default false = plain audio file. Only valid on send-audio."
@@ -10749,6 +10798,11 @@
"address": {
"type": "string",
"maxLength": 1024
+ },
+ "quotedMessageId": {
+ "type": "string",
+ "description": "Quote an earlier message, turning this send into a reply. The id is engine-specific: whatsapp-web.js matches the serialized message id, Baileys matches the raw message key id and can only quote a message it has already stored. An id that cannot be resolved fails the send rather than delivering it unquoted.",
+ "example": "[email protected]_3EB0ABCD"
}
},
"required": [
@@ -10770,6 +10824,11 @@
"contactNumber": {
"type": "string",
"maxLength": 30
+ },
+ "quotedMessageId": {
+ "type": "string",
+ "description": "Quote an earlier message, turning this send into a reply. The id is engine-specific: whatsapp-web.js matches the serialized message id, Baileys matches the raw message key id and can only quote a message it has already stored. An id that cannot be resolved fails the send rather than delivering it unquoted.",
+ "example": "[email protected]_3EB0ABCD"
}
},
"required": [
@@ -10806,6 +10865,11 @@
"allowMultipleAnswers": {
"type": "boolean",
"description": "Allow voters to pick several options (default single choice)"
+ },
+ "quotedMessageId": {
+ "type": "string",
+ "description": "Quote an earlier message, turning this send into a reply. The id is engine-specific: whatsapp-web.js matches the serialized message id, Baileys matches the raw message key id and can only quote a message it has already stored. An id that cannot be resolved fails the send rather than delivering it unquoted.",
+ "example": "[email protected]_3EB0ABCD"
}
},
"required": [
diff --git a/src/core/agent-tools/tools/message.tools.ts b/src/core/agent-tools/tools/message.tools.ts
index 70e8b771a..59d76c0f4 100644
--- a/src/core/agent-tools/tools/message.tools.ts
+++ b/src/core/agent-tools/tools/message.tools.ts
@@ -12,6 +12,19 @@ import { defineTool, type AnyToolDescriptor } from '../tool-descriptor';
const sessionId = z.string().min(1).describe('Session UUID (the session id, not the name)');
+/**
+ * Mirrors the REST `quotedMessageId` field so an agent can reply with media, a location, a contact
+ * card or a poll — the same capability, on the same endpoints, through the MCP surface.
+ */
+const quotedMessageIdSchema = z
+ .string()
+ .min(1)
+ .optional()
+ .describe(
+ 'Quote an earlier message, making this send a reply. Engine-specific: whatsapp-web.js takes ' +
+ 'the serialized message id, Baileys the raw key id of a message it has already stored.',
+ );
+
export function messageTools(message: MessageService): AnyToolDescriptor[] {
return [
defineTool({
@@ -86,12 +99,14 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
'Set false to suppress the URL preview. Guaranteed only in that direction — leaving it ' +
'unset means the engine default, and the engines differ.',
),
+ quotedMessageId: quotedMessageIdSchema,
}),
handler: input =>
message.sendText(input.sessionId, {
chatId: input.chatId,
text: input.text,
...(input.linkPreview === undefined ? {} : { linkPreview: input.linkPreview }),
+ quotedMessageId: input.quotedMessageId,
}),
}),
defineTool({
@@ -108,6 +123,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
mimetype: z.string().optional().describe('MIME type (required when using base64)'),
filename: z.string().max(255).optional(),
caption: z.string().max(1024).optional(),
+ quotedMessageId: quotedMessageIdSchema,
}),
handler: input =>
message.sendImage(input.sessionId, {
@@ -117,6 +133,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
mimetype: input.mimetype,
filename: input.filename,
caption: input.caption,
+ quotedMessageId: input.quotedMessageId,
}),
}),
defineTool({
@@ -133,6 +150,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
mimetype: z.string().optional().describe('MIME type (required when using base64)'),
filename: z.string().max(255).optional(),
caption: z.string().max(1024).optional(),
+ quotedMessageId: quotedMessageIdSchema,
}),
handler: input =>
message.sendVideo(input.sessionId, {
@@ -142,6 +160,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
mimetype: input.mimetype,
filename: input.filename,
caption: input.caption,
+ quotedMessageId: input.quotedMessageId,
}),
}),
defineTool({
@@ -159,6 +178,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
filename: z.string().max(255).optional(),
caption: z.string().max(1024).optional(),
ptt: z.boolean().optional().describe('Send as a WhatsApp voice note (PTT)'),
+ quotedMessageId: quotedMessageIdSchema,
}),
handler: input =>
message.sendAudio(input.sessionId, {
@@ -169,6 +189,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
filename: input.filename,
caption: input.caption,
ptt: input.ptt,
+ quotedMessageId: input.quotedMessageId,
}),
}),
defineTool({
@@ -185,6 +206,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
mimetype: z.string().optional().describe('MIME type (required when using base64)'),
filename: z.string().max(255).optional(),
caption: z.string().max(1024).optional(),
+ quotedMessageId: quotedMessageIdSchema,
}),
handler: input =>
message.sendDocument(input.sessionId, {
@@ -194,6 +216,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
mimetype: input.mimetype,
filename: input.filename,
caption: input.caption,
+ quotedMessageId: input.quotedMessageId,
}),
}),
defineTool({
@@ -209,6 +232,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
longitude: z.number().min(-180).max(180).describe('Longitude coordinate'),
description: z.string().max(LOCATION_TEXT_MAX_LENGTH).optional().describe('Location label/description'),
address: z.string().max(LOCATION_TEXT_MAX_LENGTH).optional().describe('Street address'),
+ quotedMessageId: quotedMessageIdSchema,
}),
handler: input =>
message.sendLocation(input.sessionId, {
@@ -217,6 +241,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
longitude: input.longitude,
description: input.description,
address: input.address,
+ quotedMessageId: input.quotedMessageId,
}),
}),
defineTool({
@@ -234,12 +259,14 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
.min(1)
.max(CONTACT_NUMBER_MAX_LENGTH)
.describe('Phone number of the contact to share'),
+ quotedMessageId: quotedMessageIdSchema,
}),
handler: input =>
message.sendContact(input.sessionId, {
chatId: input.chatId,
contactName: input.contactName,
contactNumber: input.contactNumber,
+ quotedMessageId: input.quotedMessageId,
}),
}),
defineTool({
@@ -256,6 +283,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
mimetype: z.string().optional().describe('MIME type (required when using base64)'),
filename: z.string().max(255).optional(),
caption: z.string().max(1024).optional(),
+ quotedMessageId: quotedMessageIdSchema,
}),
handler: input =>
message.sendSticker(input.sessionId, {
@@ -265,6 +293,7 @@ export function messageTools(message: MessageService): AnyToolDescriptor[] {
mimetype: input.mimetype,
filename: input.filename,
caption: input.caption,
+ quotedMessageId: input.quotedMessageId,
}),
}),
defineTool({
diff --git a/src/modules/message/message.service.spec.ts b/src/modules/message/message.service.spec.ts
index e6fb81b2e..e3823af0c 100644
--- a/src/modules/message/message.service.spec.ts
+++ b/src/modules/message/message.service.spec.ts
@@ -1159,7 +1159,7 @@ describe('MessageService', () => {
chatId: '[email protected]',
url: 'https://example.com/a.png',
quotedMessageId: 'wa-quoted-9',
- } as never);
+ });
expect(mockEngine.sendImageMessage).toHaveBeenCalledWith(
@@ -1173,7 +1173,7 @@ describe('MessageService', () => {
latitude: 1,
longitude: 2,
quotedMessageId: 'wa-quoted-9',
- } as never);
+ });
expect(mockEngine.sendLocationMessage).toHaveBeenCalledWith(
@@ -1187,7 +1187,7 @@ describe('MessageService', () => {
contactName: 'Alice',
contactNumber: '628999',
quotedMessageId: 'wa-quoted-9',
- } as never);
+ });
expect(mockEngine.sendContactMessage).toHaveBeenCalledWith(
@@ -1201,7 +1201,7 @@ describe('MessageService', () => {
name: 'Q',
options: ['a', 'b'],
quotedMessageId: 'wa-quoted-9',
- } as never);
+ });
expect(mockEngine.sendPollMessage).toHaveBeenCalledWith(
@@ -1214,7 +1214,7 @@ describe('MessageService', () => {
chatId: '[email protected]',
text: 'hi',
quotedMessageId: 'wa-quoted-9',
- } as never);
+ });
expect(mockEngine.sendTextMessage).toHaveBeenCalledWith(
@@ -1228,7 +1228,7 @@ describe('MessageService', () => {
// implementation that always passed an options object would satisfy the assertion above while
// rewriting every existing send.
it('leaves an unquoted text send on its existing two-argument call shape', async () => {
- await service.sendText('sess-1', { chatId: '[email protected]', text: 'hi' } as never);
+ await service.sendText('sess-1', { chatId: '[email protected]', text: 'hi' });
expect(mockEngine.sendTextMessage).toHaveBeenCalledWith('[email protected]', 'hi');
});