Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(message): prefer base64 over url when both are provided (#670) (#671)
Yudhi Armyndharisb777924437e2
diff --git a/src/modules/message/message.service.spec.ts b/src/modules/message/message.service.spec.tsindex 380ae1c32..6ae405f36 100644--- a/src/modules/message/message.service.spec.ts+++ b/src/modules/message/message.service.spec.ts@@ -855,6 +855,27 @@ describe('MessageService', () => {}),).rejects.toThrow('mimetype is required when using base64 data');});++ it('prefers base64 over url when both are provided (#670)', async () => {+ // When both are sent, base64 is the explicit local payload and must win over `url` — otherwise+ // a stale `url` is fetched and silently shadows the image. This aligns the send selection with+ // the base64-first persisted metadata and the `@ValidateIf((o) => !o.base64)` intent on `url`.+ await service.sendImage('sess-1', {+ chatId: '[email protected]',+ url: 'https://example.com/img.jpg',+ base64: 'iVBORw0KGgoAAAAN...',+ mimetype: 'image/png',+ });++ expect(mockEngine.sendImageMessage).toHaveBeenCalledWith(+ '[email protected]',+ expect.objectContaining({ data: 'iVBORw0KGgoAAAAN...' }),+ );+ expect(mockEngine.sendImageMessage).not.toHaveBeenCalledWith(+ '[email protected]',+ expect.objectContaining({ data: 'https://example.com/img.jpg' }),+ );+ });});// ── reactToMessage / deleteMessage ────────────────────────────────diff --git a/src/modules/message/message.service.ts b/src/modules/message/message.service.tsindex 55b9b22b0..fdfa623a7 100644--- a/src/modules/message/message.service.ts+++ b/src/modules/message/message.service.ts@@ -677,7 +677,11 @@ export class MessageService {return {mimetype: dto.mimetype || 'application/octet-stream',- data: dto.url || dto.base64!,+ // base64 wins over url when both are present: it is the explicit local payload, and a stale+ // `url` (e.g. a Swagger/example default left in the body) must not be fetched in its place.+ // Aligns the send selection with the base64-first persisted metadata and the url field's+ // `@ValidateIf((o) => !o.base64)` (which skips @IsUrl when base64 is present) — #670.+ data: dto.base64 || dto.url!,filename: dto.filename,caption: dto.caption,mentions: dto.mentions,