Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): name a message type in words in the chat composer

Yudhi Armyndhariscc06ff50d7e7
diff --git a/dashboard/src/components/chats/ChatComposer.tsx b/dashboard/src/components/chats/ChatComposer.tsx
index 406166dbe..93c132a5e 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);
+ // "[Image]" for a non-text message; an unexpected type still reads as itself rather than a raw key.
+ const typeLabel = (type: string) => `[${t(`chats.messageType.${type}`, { defaultValue: type })}]`;
// 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;
@@ -270,7 +272,8 @@ function ChatComposer({
upsertCachedMessage(queryClient, sendKey, reconciled, { dropId: tempId });
// Update sidebar chat list (move active chat to the top with the new snippet)
- const snippet = currentAttachment ? `[${currentAttachment.mimetype.split('/')[0]}]` : textToSend;
+ // Named by the type the bubble uses, not the MIME major type: a PDF is a document, not "application".
+ const snippet = currentAttachment ? typeLabel(messageTypeFromMime(currentAttachment.mimetype)) : textToSend;
const sentAt = Math.floor(Date.now() / 1000);
setChats(prevChats => promoteChatWithSnippet(prevChats, activeChat.id, snippet, sentAt));
} catch (err) {
@@ -328,7 +331,7 @@ function ChatComposer({
})}
</div>
<div className="replying-to-body">
- {replyingTo.type !== 'text' ? `[${replyingTo.type}]` : replyingTo.body}
+ {replyingTo.type !== 'text' ? typeLabel(replyingTo.type) : replyingTo.body}
</div>
</div>
<button className="btn-close-reply" onClick={() => setReplyingTo(null)}>
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index ce2f8ae61..da0d5df08 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -103,6 +103,24 @@
"delete": "حذف الرسالة"
},
"replyingTo": "الرد على {{name}}",
+ "messageType": {
+ "text": "نص",
+ "image": "صورة",
+ "video": "فيديو",
+ "audio": "صوت",
+ "voice": "رسالة صوتية",
+ "document": "مستند",
+ "sticker": "ملصق",
+ "location": "موقع",
+ "contact": "جهة اتصال",
+ "poll": "استطلاع",
+ "call": "مكالمة",
+ "revoked": "رسالة محذوفة",
+ "order": "طلب",
+ "product": "منتج",
+ "masked": "رسالة مخفية",
+ "unknown": "رسالة"
+ },
"you": "أنت",
"youPrefix": "أنت: ",
"yesterday": "أمس",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index 03c094194..466b09f97 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -99,6 +99,24 @@
"delete": "Nachricht löschen"
},
"replyingTo": "Antwort an {{name}}",
+ "messageType": {
+ "text": "Text",
+ "image": "Bild",
+ "video": "Video",
+ "audio": "Audio",
+ "voice": "Sprachnachricht",
+ "document": "Dokument",
+ "sticker": "Sticker",
+ "location": "Standort",
+ "contact": "Kontakt",
+ "poll": "Umfrage",
+ "call": "Anruf",
+ "revoked": "Gelöschte Nachricht",
+ "order": "Bestellung",
+ "product": "Produkt",
+ "masked": "Ausgeblendete Nachricht",
+ "unknown": "Nachricht"
+ },
"you": "Du",
"youPrefix": "Du: ",
"yesterday": "Gestern",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index ff180a203..12ae54194 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -99,6 +99,24 @@
"delete": "Delete message"
},
"replyingTo": "Replying to {{name}}",
+ "messageType": {
+ "text": "Text",
+ "image": "Image",
+ "video": "Video",
+ "audio": "Audio",
+ "voice": "Voice message",
+ "document": "Document",
+ "sticker": "Sticker",
+ "location": "Location",
+ "contact": "Contact",
+ "poll": "Poll",
+ "call": "Call",
+ "revoked": "Deleted message",
+ "order": "Order",
+ "product": "Product",
+ "masked": "Hidden message",
+ "unknown": "Message"
+ },
"you": "You",
"youPrefix": "You: ",
"yesterday": "Yesterday",
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index f610e1369..ba09f4e03 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -100,6 +100,24 @@
"delete": "Eliminar mensaje"
},
"replyingTo": "Respondiendo a {{name}}",
+ "messageType": {
+ "text": "Texto",
+ "image": "Imagen",
+ "video": "Vídeo",
+ "audio": "Audio",
+ "voice": "Mensaje de voz",
+ "document": "Documento",
+ "sticker": "Sticker",
+ "location": "Ubicación",
+ "contact": "Contacto",
+ "poll": "Encuesta",
+ "call": "Llamada",
+ "revoked": "Mensaje eliminado",
+ "order": "Pedido",
+ "product": "Producto",
+ "masked": "Mensaje oculto",
+ "unknown": "Mensaje"
+ },
"you": "Tú",
"youPrefix": "Tú: ",
"yesterday": "Ayer",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index ed9f3fe15..55274030c 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -100,6 +100,24 @@
"delete": "Supprimer le message"
},
"replyingTo": "Réponse à {{name}}",
+ "messageType": {
+ "text": "Texte",
+ "image": "Image",
+ "video": "Vidéo",
+ "audio": "Audio",
+ "voice": "Message vocal",
+ "document": "Document",
+ "sticker": "Sticker",
+ "location": "Localisation",
+ "contact": "Contact",
+ "poll": "Sondage",
+ "call": "Appel",
+ "revoked": "Message supprimé",
+ "order": "Commande",
+ "product": "Produit",
+ "masked": "Message masqué",
+ "unknown": "Message"
+ },
"you": "Vous",
"youPrefix": "Vous : ",
"yesterday": "Hier",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index dfb2307da..67bba3a09 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -101,6 +101,24 @@
"delete": "מחק הודעה"
},
"replyingTo": "משיב ל-{{name}}",
+ "messageType": {
+ "text": "טקסט",
+ "image": "תמונה",
+ "video": "וידאו",
+ "audio": "אודיו",
+ "voice": "הודעה קולית",
+ "document": "מסמך",
+ "sticker": "מדבקה",
+ "location": "מיקום",
+ "contact": "איש קשר",
+ "poll": "סקר",
+ "call": "שיחה",
+ "revoked": "הודעה שנמחקה",
+ "order": "הזמנה",
+ "product": "מוצר",
+ "masked": "הודעה מוסתרת",
+ "unknown": "הודעה"
+ },
"you": "אתה",
"youPrefix": "אתה: ",
"yesterday": "אתמול",
diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.json
index 74cebbd1b..44f05ef0b 100644
--- a/dashboard/src/i18n/locales/hi.json
+++ b/dashboard/src/i18n/locales/hi.json
@@ -99,6 +99,24 @@
"delete": "संदेश हटाएं"
},
"replyingTo": "{{name}} को उत्तर दे रहे हैं",
+ "messageType": {
+ "text": "टेक्स्ट",
+ "image": "छवि",
+ "video": "वीडियो",
+ "audio": "ऑडियो",
+ "voice": "वॉइस संदेश",
+ "document": "दस्तावेज़",
+ "sticker": "स्टिकर",
+ "location": "स्थान",
+ "contact": "संपर्क",
+ "poll": "पोल",
+ "call": "कॉल",
+ "revoked": "हटाया गया संदेश",
+ "order": "ऑर्डर",
+ "product": "उत्पाद",
+ "masked": "छिपा हुआ संदेश",
+ "unknown": "संदेश"
+ },
"you": "आप",
"youPrefix": "आप: ",
"yesterday": "कल",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index 7e29a88c5..4e8711653 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -100,6 +100,24 @@
"delete": "Elimina messaggio"
},
"replyingTo": "Risposta a {{name}}",
+ "messageType": {
+ "text": "Testo",
+ "image": "Immagine",
+ "video": "Video",
+ "audio": "Audio",
+ "voice": "Messaggio vocale",
+ "document": "Documento",
+ "sticker": "Sticker",
+ "location": "Posizione",
+ "contact": "Contatto",
+ "poll": "Sondaggio",
+ "call": "Chiamata",
+ "revoked": "Messaggio eliminato",
+ "order": "Ordine",
+ "product": "Prodotto",
+ "masked": "Messaggio nascosto",
+ "unknown": "Messaggio"
+ },
"you": "Tu",
"youPrefix": "Tu: ",
"yesterday": "Ieri",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index c57987f50..5751e6b25 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -99,6 +99,24 @@
"delete": "메시지 삭제"
},
"replyingTo": "{{name}}님에게 답장",
+ "messageType": {
+ "text": "텍스트",
+ "image": "이미지",
+ "video": "동영상",
+ "audio": "오디오",
+ "voice": "음성 메시지",
+ "document": "문서",
+ "sticker": "스티커",
+ "location": "위치",
+ "contact": "연락처",
+ "poll": "투표",
+ "call": "통화",
+ "revoked": "삭제된 메시지",
+ "order": "주문",
+ "product": "상품",
+ "masked": "가려진 메시지",
+ "unknown": "메시지"
+ },
"you": "나",
"youPrefix": "나: ",
"yesterday": "어제",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 49a0474ea..7bf9a8fca 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -100,6 +100,24 @@
"delete": "Excluir mensagem"
},
"replyingTo": "Respondendo a {{name}}",
+ "messageType": {
+ "text": "Texto",
+ "image": "Imagem",
+ "video": "Vídeo",
+ "audio": "Áudio",
+ "voice": "Mensagem de voz",
+ "document": "Documento",
+ "sticker": "Figurinha",
+ "location": "Localização",
+ "contact": "Contato",
+ "poll": "Enquete",
+ "call": "Chamada",
+ "revoked": "Mensagem excluída",
+ "order": "Pedido",
+ "product": "Produto",
+ "masked": "Mensagem oculta",
+ "unknown": "Mensagem"
+ },
"you": "Você",
"youPrefix": "Você: ",
"yesterday": "Ontem",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index a5fed08c2..6cb27c0f5 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -99,6 +99,24 @@
"delete": "సందేశాన్ని తొలగించు"
},
"replyingTo": "{{name}} కు ప్రత్యుత్తరం ఇస్తోంది",
+ "messageType": {
+ "text": "టెక్స్ట్",
+ "image": "చిత్రం",
+ "video": "వీడియో",
+ "audio": "ఆడియో",
+ "voice": "వాయిస్ సందేశం",
+ "document": "డాక్యుమెంట్",
+ "sticker": "స్టిక్కర్",
+ "location": "స్థానం",
+ "contact": "పరిచయం",
+ "poll": "పోల్",
+ "call": "కాల్",
+ "revoked": "తొలగించిన సందేశం",
+ "order": "ఆర్డర్",
+ "product": "ఉత్పత్తి",
+ "masked": "దాచిన సందేశం",
+ "unknown": "సందేశం"
+ },
"you": "మీరు",
"youPrefix": "మీరు: ",
"yesterday": "నిన్న",
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index b70c87664..95d6e09f7 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -99,6 +99,24 @@
"delete": "Mesajı sil"
},
"replyingTo": "{{name}} kişisine yanıt veriliyor",
+ "messageType": {
+ "text": "Metin",
+ "image": "Görsel",
+ "video": "Video",
+ "audio": "Ses",
+ "voice": "Sesli mesaj",
+ "document": "Belge",
+ "sticker": "Çıkartma",
+ "location": "Konum",
+ "contact": "Kişi",
+ "poll": "Anket",
+ "call": "Arama",
+ "revoked": "Silinen mesaj",
+ "order": "Sipariş",
+ "product": "Ürün",
+ "masked": "Gizlenen mesaj",
+ "unknown": "Mesaj"
+ },
"you": "Siz",
"youPrefix": "Siz: ",
"yesterday": "Dün",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index c88015663..a76d96295 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -99,6 +99,24 @@
"delete": "删除消息"
},
"replyingTo": "正在回复 {{name}}",
+ "messageType": {
+ "text": "文本",
+ "image": "图片",
+ "video": "视频",
+ "audio": "音频",
+ "voice": "语音消息",
+ "document": "文档",
+ "sticker": "贴纸",
+ "location": "位置",
+ "contact": "联系人",
+ "poll": "投票",
+ "call": "通话",
+ "revoked": "已删除的消息",
+ "order": "订单",
+ "product": "商品",
+ "masked": "已隐藏的消息",
+ "unknown": "消息"
+ },
"you": "你",
"youPrefix": "你:",
"yesterday": "昨天",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index 9a0914ca5..3f3fdaebf 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -99,6 +99,24 @@
"delete": "刪除訊息"
},
"replyingTo": "正在回覆 {{name}}",
+ "messageType": {
+ "text": "文字",
+ "image": "圖片",
+ "video": "影片",
+ "audio": "音訊",
+ "voice": "語音訊息",
+ "document": "文件",
+ "sticker": "貼圖",
+ "location": "位置",
+ "contact": "聯絡人",
+ "poll": "投票",
+ "call": "通話",
+ "revoked": "已刪除的訊息",
+ "order": "訂單",
+ "product": "商品",
+ "masked": "已隱藏的訊息",
+ "unknown": "訊息"
+ },
"you": "你",
"youPrefix": "你:",
"yesterday": "昨天",
diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.ts
index 95f267288..45401726a 100644
--- a/dashboard/src/pages/Chats.test.ts
+++ b/dashboard/src/pages/Chats.test.ts
@@ -323,6 +323,9 @@ function installFetchStub(): void {
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 === 'POST' && path === `/api/sessions/${SESSION.id}/messages/send-document`) {
+ return Promise.resolve(jsonResponse({ messageId: 'wamid.out.document', timestamp: 1_700_000_100 }));
+ }
if (method === 'GET' && path.startsWith('/api/search?')) {
return Promise.resolve(jsonResponse({ hits: [], total: 0 }));
}
@@ -799,6 +802,33 @@ test('text typed with an audio attachment stays in the input instead of showing
assert.equal(within(thread).queryByText('not a caption'), null, 'the audio bubble shows text that was never sent');
});
+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();
+ const { container } = renderChats();
+
+ await screen.findByText('Main (15551234567)');
+ const row = (await screen.findByText('Alice')).closest('.chat-item-card') as HTMLElement;
+ fireEvent.click(row);
+ const thread = container.querySelector('.room-messages') as HTMLElement;
+ await within(thread).findByText('hello from alice');
+
+ // Reply to the image row: the banner reads its localized type, not "[image]".
+ const image = thread.querySelector(`[data-wa-message-id="${OMITTED_MEDIA_MESSAGE.waMessageId}"]`) as HTMLElement;
+ fireEvent.click(image.querySelector('button[title="Reply"]') as HTMLElement);
+ await waitFor(() =>
+ assert.equal(container.querySelector('.replying-to-body')?.textContent ?? null, '[Image]', 'reply banner'),
+ );
+ fireEvent.click(container.querySelector('.btn-close-reply') as HTMLElement);
+
+ // A PDF goes out as a document, and the sidebar says so rather than "[application]".
+ await stageAttachment(container, 'contract.pdf');
+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));
+ await waitFor(() =>
+ assert.equal(row.querySelector('.chat-item-snippet')?.textContent ?? null, '[Document]', 'sidebar snippet'),
+ );
+});
+
test('a staged attachment is dropped when a different chat is opened', async () => {
const { screen, fireEvent, within } = rtl;
resetFetchCalls();