Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(engine): close two Baileys gaps against the whatsapp-web.js path

Yudhi Armyndharisd764eb337794
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 55e714fed..fb55e3417 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- 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.
+- 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.
- Three routes declare the `409` they can answer: a duplicate template name on create or rename, and an integration instance id that already exists. Clients generated from the contract modelled those calls as unable to conflict.
diff --git a/src/engine/adapters/baileys-messaging.ts b/src/engine/adapters/baileys-messaging.ts
index 624740285..6cb7cfd79 100644
--- a/src/engine/adapters/baileys-messaging.ts
+++ b/src/engine/adapters/baileys-messaging.ts
@@ -327,7 +327,11 @@ export class BaileysMessaging {
const { data, mimetype } = await resolveMediaBuffer(media);
return this.sendContent(
chatId,
- { audio: data, mimetype, ptt: media.ptt ?? false },
+ // Audio carries no caption, so a mention here tags the recipient through contextInfo without
+ // visible @text. It is still forwarded: the route accepts `mentions` (SendAudioMessageDto
+ // extends SendMediaMessageDto) and whatsapp-web.js sends it, so dropping it here made the same
+ // request notify participants on one engine and silently not on the other.
+ { audio: data, mimetype, ptt: media.ptt ?? false, ...this.withMentions(media.mentions) },
await this.quoteOption(media.quotedMessageId),
);
}
@@ -433,6 +437,10 @@ export class BaileysMessaging {
async forwardMessage(fromChatId: string, toChatId: string, messageId: string): Promise<MessageResult> {
this.host.ensureReady();
const forward = await this.requireStored(messageId);
+ // fromChatId was accepted and then ignored, so a message id from ANY chat forwarded successfully
+ // while whatsapp-web.js answered 404 for the same request (it fetches from the named chat and
+ // fails when the id is not in it). Same check the star and react paths already apply.
+ this.assertStoredInChat(forward, fromChatId, messageId);
return this.sendContent(toChatId, { forward });
}
diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.ts
index d5fef48aa..8dd9640fc 100644
--- a/src/engine/adapters/baileys.adapter.spec.ts
+++ b/src/engine/adapters/baileys.adapter.spec.ts
@@ -2481,6 +2481,25 @@ describe('BaileysAdapter media sends', () => {
});
});
+ /**
+ * Audio has no caption, so this tags through contextInfo with no visible @text. It is forwarded
+ * anyway because the route accepts it (SendAudioMessageDto extends SendMediaMessageDto) and
+ * whatsapp-web.js sends it: dropping it here made the same request notify group participants on
+ * one engine and silently not on the other.
+ */
+ it('sendAudioMessage de-normalizes media.mentions into the content', async () => {
+ const adapter = await ready();
+ await adapter.sendAudioMessage('[email protected]', {
+ mimetype: 'audio/mp4',
+ data: Buffer.from([1]),
+ mentions: ['[email protected]'],
+ });
+ expect(fakeSock.sendMessage).toHaveBeenCalledWith(
+ expect.objectContaining({ mentions: ['[email protected]'] }),
+ );
+ });
+
it('sendAudioMessage with ptt sends a voice note (ptt:true)', async () => {
const adapter = await ready();
await adapter.sendAudioMessage('[email protected]', {
@@ -2581,6 +2600,20 @@ describe('BaileysAdapter store-backed ops', () => {
expect(fakeSock.sendMessage).toHaveBeenCalledWith('[email protected]', { forward: stored });
});
+ // fromChatId was accepted and ignored: any stored id forwarded from any claimed source, while
+ // whatsapp-web.js answered 404 for the same request because it fetches from the named chat.
+ it('forwardMessage throws MessageNotFoundError when the stored key belongs to another chat', async () => {
+ fakeStore.getMessage.mockResolvedValue({
+ ...stored,
+ key: { ...stored.key, remoteJid: '[email protected]' },
+ });
+ const adapter = await ready();
+ await expect(
+ adapter.forwardMessage('[email protected]', '[email protected]', 'TARGET'),
+ ).rejects.toBeInstanceOf(MessageNotFoundError);
+ expect(fakeSock.sendMessage).not.toHaveBeenCalled();
+ });
+
it('reactToMessage sends the stored key', async () => {
fakeStore.getMessage.mockResolvedValue(stored);
const adapter = await ready();