Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): send an untyped file from Chats as a document
Yudhi Armyndharisda9f3bff2276
diff --git a/dashboard/src/components/chats/ChatComposer.tsx b/dashboard/src/components/chats/ChatComposer.tsxindex da7782028..e8a8795e2 100644--- a/dashboard/src/components/chats/ChatComposer.tsx+++ b/dashboard/src/components/chats/ChatComposer.tsx@@ -171,7 +171,14 @@ function ChatComposer({if (attachmentReadSeq.current !== myRead) return;const dataUrl = event.target?.result as string;const base64Data = dataUrl.split(',')[1];- setAttachment({ file, base64: base64Data, mimetype: file.type, filename: file.name });+ // A file the browser has no MIME mapping for has type '', which the gateway refuses for base64;+ // the generic type sends it as a document, the gateway's own default.+ setAttachment({+ file,+ base64: base64Data,+ mimetype: file.type || 'application/octet-stream',+ filename: file.name,+ });};reader.readAsDataURL(file);};diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.tsindex 5cc7f7c1d..d5b0050c5 100644--- a/dashboard/src/pages/Chats.test.ts+++ b/dashboard/src/pages/Chats.test.ts@@ -856,6 +856,25 @@ test('a caption sent with a document shows in its bubble', async () => {assert.ok(within(thread).queryByText('please sign'), 'the caption that was sent is missing from the bubble');});+test('a file the browser cannot type goes out as a document with a generic MIME type', async () => {+ const { screen, fireEvent, within, waitFor } = rtl;+ resetFetchCalls();+ const { container } = renderChats();++ await screen.findByText('Main (15551234567)');+ fireEvent.click(await screen.findByText('Alice'));+ await within(container.querySelector('.room-messages') as HTMLElement).findByText('hello from alice');+ // File.type is '' for an extension the browser has no mapping for, and the gateway refuses base64+ // without a MIME type.+ await stageAttachment(container, 'settings.env', '');+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));+ await waitFor(() => {+ const call = findFetchCall('POST', `/api/sessions/${SESSION.id}/messages/send-document`);+ assert.ok(call, 'expected a POST to the send-document endpoint');+ assert.equal((call.body as { mimetype?: string }).mimetype, 'application/octet-stream');+ });+});+test('the reply banner and the sent snippet name a media type in words, not as a raw token', async () => {const { screen, fireEvent, within, waitFor } = rtl;resetFetchCalls();