Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): show a document's caption in its sent bubble
Yudhi Armyndharis14292cf2ec36
diff --git a/dashboard/src/components/chats/ChatComposer.tsx b/dashboard/src/components/chats/ChatComposer.tsxindex 3ea0fae21..4bdbbd41b 100644--- a/dashboard/src/components/chats/ChatComposer.tsx+++ b/dashboard/src/components/chats/ChatComposer.tsx@@ -205,16 +205,20 @@ function ChatComposer({setSending(true);const tempId = `temp_${Date.now()}`;+ // The body the gateway stores for each type: image and video keep only the caption, a document its+ // caption or else its filename, and audio its filename (the thread hides a body equal to it).const tempMessage: ChatMessageView = {id: tempId,chatId: activeChat.id,from: 'me',to: activeChat.id,- body: attachment- ? attachment.mimetype.startsWith('image/') || attachment.mimetype.startsWith('video/')+ body: !attachment+ ? textToSend+ : attachment.mimetype.startsWith('image/') || attachment.mimetype.startsWith('video/')? textToSend- : attachment.filename- : textToSend,+ : attachment.mimetype.startsWith('audio/')+ ? attachment.filename+ : textToSend || attachment.filename,type: attachment ? messageTypeFromMime(attachment.mimetype) : 'text',direction: 'outgoing',status: 'pending',diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.tsindex 597a1c817..be410eec5 100644--- a/dashboard/src/pages/Chats.test.ts+++ b/dashboard/src/pages/Chats.test.ts@@ -802,6 +802,31 @@ test('text typed with an audio attachment stays in the input instead of showingassert.equal(within(thread).queryByText('not a caption'), null, 'the audio bubble shows text that was never sent');});+test('a caption sent with a document shows in its bubble', async () => {+ const { screen, fireEvent, within, waitFor } = rtl;+ resetFetchCalls();+ const { container } = renderChats();++ await screen.findByText('Main (15551234567)');+ fireEvent.click(await screen.findByText('Alice'));+ const thread = container.querySelector('.room-messages') as HTMLElement;+ await within(thread).findByText('hello from alice');+ await stageAttachment(container, 'contract.pdf');++ const input = screen.getByPlaceholderText('Add a caption...') as HTMLInputElement;+ fireEvent.change(input, { target: { value: 'please sign' } });+ 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 { caption?: string }).caption, 'please sign');+ });+ await flush();++ assert.equal(input.value, '');+ assert.ok(within(thread).queryByText('please sign'), 'the caption that was sent is missing from the bubble');+});+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();