Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(message): let the fetched type win for an undeclared bulk media URL
Yudhi Armyndharis965391f4b6a6
diff --git a/src/modules/message/bulk-message.service.spec.ts b/src/modules/message/bulk-message.service.spec.tsindex 204b35fdd..23720ae53 100644--- a/src/modules/message/bulk-message.service.spec.ts+++ b/src/modules/message/bulk-message.service.spec.ts@@ -626,6 +626,27 @@ describe('BulkMessageService.processBatch', () => {);});+ it('lets a URL item with no declared mimetype take the fetched type, as a single send does', async () => {+ const batch = makeBatch(2);+ batch.messages = [+ { chatId: '[email protected]', type: 'image', content: { image: { url: 'https://x/y.png' } } },+ { chatId: '[email protected]', type: 'audio', content: { audio: { url: 'https://x/v.ogg' } } },+ ];+ repo.findOne.mockResolvedValue(batch);++ await runProcessBatch();++ // The placeholder both engines read as "unknown", so the fetched Content-Type wins.+ expect(engine.sendImageMessage).toHaveBeenCalledWith(+ '[email protected]',+ expect.objectContaining({ mimetype: 'application/octet-stream', data: 'https://x/y.png' }),+ );+ expect(engine.sendAudioMessage).toHaveBeenCalledWith(+ '[email protected]',+ expect.objectContaining({ mimetype: 'application/octet-stream', data: 'https://x/v.ogg' }),+ );+ });+it('runs the message:sending gate for each bulk message (bulk no longer bypasses moderation)', async () => {repo.findOne.mockResolvedValue(makeBatch(1));diff --git a/src/modules/message/bulk-message.service.ts b/src/modules/message/bulk-message.service.tsindex 1b535457e..b931eb41e 100644--- a/src/modules/message/bulk-message.service.ts+++ b/src/modules/message/bulk-message.service.ts@@ -800,14 +800,18 @@ export class BulkMessageService implements OnApplicationBootstrap {/*** The mimetype a media item is sent with, and so the one its row must record: a stored row with no- * mimetype cannot be served back from the media endpoint.+ * mimetype cannot be served back from the media endpoint. An undeclared URL item gets the+ * 'application/octet-stream' placeholder buildMediaInput uses, which both engines read as "unknown",+ * so the fetched Content-Type wins. A voice note keeps ogg/opus either way, as on the single send.*/private mediaMimetype(type: string, content: BulkMessageContent): string {- const declared = content[type as 'image' | 'video' | 'audio' | 'document']?.mimetype;- if (declared) return declared;+ const media = content[type as 'image' | 'video' | 'audio' | 'document'];+ if (media?.mimetype) return media.mimetype;+ if (type === 'audio' && content.audio?.ptt) return 'audio/ogg; codecs=opus';+ if (!stripBase64DataUri(media?.base64)) return 'application/octet-stream';if (type === 'image') return 'image/jpeg';if (type === 'video') return 'video/mp4';- if (type === 'audio') return content.audio?.ptt ? 'audio/ogg; codecs=opus' : 'audio/mpeg';+ if (type === 'audio') return 'audio/mpeg';return 'application/octet-stream';}