Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): scope a Baileys reply to the chat it is sent into
Yudhi Armyndharisf2464df3d13a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 97fd8da7b..1d5e2ebab 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- The filter builder's three selects, the status image picker and the templates session picker expose accessible names, so a screen reader no longer announces unnamed comboboxes on those surfaces.- The plugin session picker exposes an accessible name, and a required array field's asterisk renders in the error colour. The caption lives outside `.form-group`, so the rule that colours the mark never matched it.- Baileys forwards `mentions` on an audio send. The route accepts the field and whatsapp-web.js sent it, so the same request tagged group participants on one engine and silently did not on the other.+- Replying with a quoted id that does not belong to the target chat is refused on Baileys with the same `404` whatsapp-web.js already answered. It was the last stored-message path with no chat check, so a reply could quote another conversation.- Forwarding a message whose id is not in `fromChatId` is refused on Baileys with the same `404` whatsapp-web.js already answered. The parameter was accepted and then ignored, so any stored id forwarded from any claimed source.- The Baileys engine resolves its WhatsApp Web version through a fallback chain instead of one call: an operator pin (`BAILEYS_WA_VERSION`), the two library endpoints, a disk cache of the last known-good version, then a built-in default. Each remote tier is bounded and rides the session proxy, and a stale answer is neither cached nor used. Thanks @giovanni-orciuolo.- The Go and Java SDKs can @mention on an audio send. `SendAudioRequest` was flattened off the shared media type and lost the field, so the typed path could not set it while every other client could.diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 3e7709514..05bcb152c 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -1592,8 +1592,9 @@ One upstream gap remains on whatsapp-web.js and cannot be switched off from heremessage resolves but the page decides it is not replyable, the message is sent without the quote andthe call still succeeds.-Quoting a message from a **different chat** is not validated on either engine; the id is passed-through as given.+Quoting a message from a **different chat** is not validated on these `send-*` routes on either+engine; the id is passed through as given. `POST /messages/reply` is stricter: both engines refuse a+quoted id that does not belong to the target chat, with `404`.#### POST /api/sessions/:sessionId/messages/send-templatediff --git a/src/engine/adapters/baileys-messaging.ts b/src/engine/adapters/baileys-messaging.tsindex 6cb7cfd79..a491698f2 100644--- a/src/engine/adapters/baileys-messaging.ts+++ b/src/engine/adapters/baileys-messaging.ts@@ -431,6 +431,13 @@ export class BaileysMessaging {async replyToMessage(chatId: string, quotedMsgId: string, text: string): Promise<MessageResult> {this.host.ensureReady();const quoted = await this.requireStored(quotedMsgId);+ // The one requireStored path that had no chat check. whatsapp-web.js resolves the quote by+ // fetching from the named chat and 404s when the id is not in it, so the same request replied+ // across conversations here and was refused there. The library encodes the foreign chat into+ // contextInfo rather than rejecting it (Utils/messages.js), so the adapter is the only guard.+ // NOT applied to quoteOption: cross-chat quoting on the send-* routes is deliberate and+ // published in docs/06.+ this.assertStoredInChat(quoted, chatId, quotedMsgId);return this.sendContent(chatId, { text }, { quoted });}diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.tsindex 8dd9640fc..68afec8c0 100644--- a/src/engine/adapters/baileys.adapter.spec.ts+++ b/src/engine/adapters/baileys.adapter.spec.ts@@ -2593,6 +2593,20 @@ describe('BaileysAdapter store-backed ops', () => {);});+ // The one requireStored path that had no chat check, while whatsapp-web.js resolves the quote by+ // fetching from the named chat and 404s when the id is not in it.+ it('replyToMessage throws MessageNotFoundError when the quoted key belongs to another chat', async () => {+ fakeStore.getMessage.mockResolvedValue({+ ...stored,+ key: { ...stored.key, remoteJid: '[email protected]' },+ });+ const adapter = await ready();+ await expect(adapter.replyToMessage('[email protected]', 'TARGET', 'my reply')).rejects.toBeInstanceOf(+ MessageNotFoundError,+ );+ expect(fakeSock.sendMessage).not.toHaveBeenCalled();+ });+it('forwardMessage forwards the stored message', async () => {fakeStore.getMessage.mockResolvedValue(stored);const adapter = await ready();