Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep text typed next to an audio attachment

Yudhi Armyndharis77368d6e53c0
diff --git a/dashboard/src/components/chats/ChatComposer.tsx b/dashboard/src/components/chats/ChatComposer.tsx
index c0c9e5707..406166dbe 100644
--- a/dashboard/src/components/chats/ChatComposer.tsx
+++ b/dashboard/src/components/chats/ChatComposer.tsx
@@ -73,6 +73,8 @@ function ChatComposer({
const queryClient = useQueryClient();
const [sending, setSending] = useState<boolean>(false);
+ // Audio carries no caption on either engine, so text typed next to it is never sent with it.
+ const attachmentIsAudio = attachment?.mimetype.startsWith('audio/') ?? false;
const [showEmojiPicker, setShowEmojiPicker] = useState<boolean>(false);
// Monotonic token invalidating an in-flight attachment FileReader: picking a second file (or
@@ -194,7 +196,8 @@ function ChatComposer({
const textToSend = messageInput.trim();
if (!textToSend && !attachment) return;
- setMessageInput('');
+ // Text that cannot travel with an audio file stays in the input to be sent as its own message.
+ if (!attachmentIsAudio) setMessageInput('');
setSending(true);
const tempId = `temp_${Date.now()}`;
@@ -204,9 +207,7 @@ function ChatComposer({
from: 'me',
to: activeChat.id,
body: attachment
- ? attachment.mimetype.startsWith('image/') ||
- attachment.mimetype.startsWith('video/') ||
- attachment.mimetype.startsWith('audio/')
+ ? attachment.mimetype.startsWith('image/') || attachment.mimetype.startsWith('video/')
? textToSend
: attachment.filename
: textToSend,
@@ -365,7 +366,7 @@ function ChatComposer({
type="text"
placeholder={
canWrite
- ? attachment
+ ? attachment && !attachmentIsAudio
? t('chats.captionPlaceholder')
: t('chats.messagePlaceholder')
: t('chats.noPermission')
diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.ts
index 219f0fd9c..d3368ca41 100644
--- a/dashboard/src/pages/Chats.test.ts
+++ b/dashboard/src/pages/Chats.test.ts
@@ -320,6 +320,9 @@ function installFetchStub(): void {
const send = () => jsonResponse({ messageId: 'wamid.out.1', timestamp: 1_700_000_100 });
return sendGate ? sendGate.then(send) : Promise.resolve(send());
}
+ if (method === 'POST' && path === `/api/sessions/${SESSION.id}/messages/send-audio`) {
+ return Promise.resolve(jsonResponse({ messageId: 'wamid.out.audio', timestamp: 1_700_000_100 }));
+ }
if (method === 'GET' && path.startsWith('/api/search?')) {
return Promise.resolve(jsonResponse({ hits: [], total: 0 }));
}
@@ -708,10 +711,10 @@ test('a read-only key opening a chat sends no mark-as-read', async () => {
// copies window properties that Node does not already define, so `Blob`/`File` stay Node's while
// `FileReader` is JSDOM's — and JSDOM's readAsDataURL brand-checks its argument against JSDOM's
// own Blob ("parameter 1 is not of type 'Blob'").
-async function stageAttachment(container: HTMLElement, filename: string): Promise<void> {
+async function stageAttachment(container: HTMLElement, filename: string, type = 'application/pdf'): Promise<void> {
const { fireEvent, waitFor } = rtl;
const fileInput = container.querySelector('input[type="file"]') as HTMLInputElement;
- const file = new window.File(['%PDF-1.4 stub'], filename, { type: 'application/pdf' });
+ const file = new window.File(['%PDF-1.4 stub'], filename, { type });
fireEvent.change(fileInput, { target: { files: [file] } });
// The bytes arrive through FileReader.onload, so the banner is asynchronous.
await waitFor(() => {
@@ -739,6 +742,32 @@ test('a staged attachment survives closing and reopening the same room', async (
assert.equal(container.querySelector('.preview-filename')?.textContent, 'contract.pdf');
});
+test('text typed with an audio attachment stays in the input instead of showing as sent', 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, 'note.ogg', 'audio/ogg');
+
+ // Audio carries no caption on either engine, so the input does not offer one and keeps the text.
+ const input = screen.getByPlaceholderText('Type a message...') as HTMLInputElement;
+ fireEvent.change(input, { target: { value: 'not a caption' } });
+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));
+ await waitFor(() => {
+ const call = findFetchCall('POST', `/api/sessions/${SESSION.id}/messages/send-audio`);
+ assert.ok(call, 'expected a POST to the send-audio endpoint');
+ assert.equal((call.body as { caption?: string }).caption, undefined);
+ });
+ await flush();
+
+ assert.equal(input.value, 'not a caption', 'the text that was not sent was cleared');
+ assert.equal(within(thread).queryByText('not a caption'), null, 'the audio bubble shows text that was never sent');
+});
+
test('a staged attachment is dropped when a different chat is opened', async () => {
const { screen, fireEvent, within } = rtl;
resetFetchCalls();