Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): name the unknown message type as an unknown type

Yudhi Armyndharis2ba28849268c
diff --git a/dashboard/src/components/DashboardCharts.test.ts b/dashboard/src/components/DashboardCharts.test.ts
index 159577544..9932c2519 100644
--- a/dashboard/src/components/DashboardCharts.test.ts
+++ b/dashboard/src/components/DashboardCharts.test.ts
@@ -51,6 +51,6 @@ test('the by-type pie legend names message types in words', async () => {
const card = (await rtl.screen.findByText('Messages by type')).closest('.chart-card') as HTMLElement;
await rtl.waitFor(() => {
const legend = Array.from(card.querySelectorAll('.recharts-legend-item-text')).map(n => n.textContent);
- assert.deepEqual(legend.sort(), ['Hidden message', 'Unknown', 'Voice message']);
+ assert.deepEqual(legend.sort(), ['Hidden message', 'Unknown type', 'Voice message']);
});
});
diff --git a/dashboard/src/components/DashboardCharts.tsx b/dashboard/src/components/DashboardCharts.tsx
index 52ba4442b..4c8a186eb 100644
--- a/dashboard/src/components/DashboardCharts.tsx
+++ b/dashboard/src/components/DashboardCharts.tsx
@@ -19,6 +19,7 @@ import { BarChart3 } from 'lucide-react';
import { useStatsMessagesQuery } from '../hooks/queries';
import type { StatsPeriod } from '../services/api';
import { formatTick } from '../utils/chartTicks';
+import { messageTypeLabelKey } from '../utils/enumLabels';
import './DashboardCharts.css';
const PERIODS: StatsPeriod[] = ['24h', '7d', '30d'];
@@ -68,12 +69,9 @@ export function DashboardCharts() {
if (isError && forbidden) return null;
const timeSeries = (data?.timeSeries ?? []).map(p => ({ ...p, label: formatTick(p.timestamp, period) }));
- // `name` keys the slice color; `label` is what the legend and tooltip show. The `unknown` bucket
- // reads "Unknown", not the chat bubble's generic "Message" placeholder.
- const typeLabel = (name: string) =>
- t(name === 'unknown' ? 'chats.kind.unknown' : `chats.messageType.${name}`, { defaultValue: name });
+ // `name` keys the slice color; `label` is what the legend and tooltip show.
const byType = Object.entries(data?.byType ?? {})
- .map(([name, value]) => ({ name, label: typeLabel(name), value }))
+ .map(([name, value]) => ({ name, label: t(messageTypeLabelKey(name), { defaultValue: name }), value }))
.sort((a, b) => b.value - a.value);
const topChats = (data?.topChats ?? [])
.slice(0, 8)
diff --git a/dashboard/src/components/FilterBuilder.test.ts b/dashboard/src/components/FilterBuilder.test.ts
index 58575e24b..b73015f5c 100644
--- a/dashboard/src/components/FilterBuilder.test.ts
+++ b/dashboard/src/components/FilterBuilder.test.ts
@@ -38,8 +38,8 @@ test('enum tags name message types and chat kinds in words', () => {
);
assert.ok(types.includes('Voice message'), `message type tags: ${types.join(', ')}`);
assert.ok(types.includes('Hidden message'), `message type tags: ${types.join(', ')}`);
- // The unclassified bucket is not "any message"; it reads like the unknown chat kind.
- assert.ok(types.includes('Unknown'), `message type tags: ${types.join(', ')}`);
+ // The unclassified bucket is not "any message" (the reply banner's wording for it).
+ assert.ok(types.includes('Unknown type'), `message type tags: ${types.join(', ')}`);
assert.ok(!types.includes('Message'), `message type tags: ${types.join(', ')}`);
assert.deepEqual(kinds, ['Individual', 'Group', 'Channel', 'Status', 'Broadcast', 'Unknown']);
});
diff --git a/dashboard/src/components/FilterBuilder.tsx b/dashboard/src/components/FilterBuilder.tsx
index 24b1886fd..548452ea1 100644
--- a/dashboard/src/components/FilterBuilder.tsx
+++ b/dashboard/src/components/FilterBuilder.tsx
@@ -9,6 +9,7 @@ import {
type WebhookFilterCondition,
type WebhookFilterOperator,
} from '../services/api';
+import { messageTypeLabelKey } from '../utils/enumLabels';
import './FilterBuilder.css';
type FieldKind = 'id' | 'idArray' | 'text' | 'enum' | 'boolean';
@@ -18,8 +19,8 @@ interface FieldDescriptor {
kind: FieldKind;
operators: WebhookFilterOperator[];
enumValues?: readonly string[];
- /** i18n namespace that names each enum value; the value itself is what the filter sends. */
- enumLabels?: string;
+ /** i18n key that names an enum value; the value itself is what the filter sends. */
+ enumLabel?: (value: string) => string;
}
// Mirrors the backend message-family field registry (src/modules/webhook/filters/filter-types.ts).
@@ -33,10 +34,16 @@ const MESSAGE_FIELDS: FieldDescriptor[] = [
kind: 'enum',
operators: ['is', 'isNot'],
enumValues: MESSAGE_TYPES,
- enumLabels: 'chats.messageType',
+ enumLabel: messageTypeLabelKey,
},
{ field: 'isGroup', kind: 'boolean', operators: ['is'] },
- { field: 'kind', kind: 'enum', operators: ['is', 'isNot'], enumValues: CHAT_KINDS, enumLabels: 'chats.kind' },
+ {
+ field: 'kind',
+ kind: 'enum',
+ operators: ['is', 'isNot'],
+ enumValues: CHAT_KINDS,
+ enumLabel: kind => `chats.kind.${kind}`,
+ },
{ field: 'fromMe', kind: 'boolean', operators: ['is'] },
{ field: 'hasMedia', kind: 'boolean', operators: ['is'] },
{ field: 'mentions', kind: 'idArray', operators: ['is', 'isNot'] },
@@ -239,11 +246,7 @@ export function FilterBuilder({ filters, onChange, chats }: FilterBuilderProps)
});
}}
>
- {/* An `unknown` type reads "Unknown" like the unknown chat kind, not the chat
- bubble's generic "Message" placeholder. */}
- {t(option === 'unknown' ? 'chats.kind.unknown' : `${def.enumLabels}.${option}`, {
- defaultValue: option,
- })}
+ {def.enumLabel ? t(def.enumLabel(option), { defaultValue: option }) : option}
</button>
);
})}
diff --git a/dashboard/src/components/chats/ChatComposer.tsx b/dashboard/src/components/chats/ChatComposer.tsx
index 4aa4236fc..3ea0fae21 100644
--- a/dashboard/src/components/chats/ChatComposer.tsx
+++ b/dashboard/src/components/chats/ChatComposer.tsx
@@ -74,6 +74,8 @@ function ChatComposer({
const [sending, setSending] = useState<boolean>(false);
// "[Image]" for a non-text message; an unexpected type still reads as itself rather than a raw key.
+ // An `unknown` one quotes as "[Message]" on purpose: here it is a message, not a type category
+ // (the chart and the webhook filter name it through messageTypeLabelKey instead).
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;
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index 9788757f6..d57bebb7f 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -119,7 +119,8 @@
"order": "طلب",
"product": "منتج",
"masked": "رسالة مخفية",
- "unknown": "رسالة"
+ "unknown": "رسالة",
+ "unknownType": "نوع غير معروف"
},
"you": "أنت",
"youPrefix": "أنت: ",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index 747fd98f9..cc3d9d224 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -115,7 +115,8 @@
"order": "Bestellung",
"product": "Produkt",
"masked": "Ausgeblendete Nachricht",
- "unknown": "Nachricht"
+ "unknown": "Nachricht",
+ "unknownType": "Unbekannter Typ"
},
"you": "Du",
"youPrefix": "Du: ",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index 8dd582aad..14127fb55 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -115,7 +115,8 @@
"order": "Order",
"product": "Product",
"masked": "Hidden message",
- "unknown": "Message"
+ "unknown": "Message",
+ "unknownType": "Unknown type"
},
"you": "You",
"youPrefix": "You: ",
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index 0f66c2a7a..36dcf57b6 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -116,7 +116,8 @@
"order": "Pedido",
"product": "Producto",
"masked": "Mensaje oculto",
- "unknown": "Mensaje"
+ "unknown": "Mensaje",
+ "unknownType": "Tipo desconocido"
},
"you": "Tú",
"youPrefix": "Tú: ",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index 96fce5f71..9e712c5af 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -116,7 +116,8 @@
"order": "Commande",
"product": "Produit",
"masked": "Message masqué",
- "unknown": "Message"
+ "unknown": "Message",
+ "unknownType": "Type inconnu"
},
"you": "Vous",
"youPrefix": "Vous : ",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 0cd68a048..c279905d6 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -117,7 +117,8 @@
"order": "הזמנה",
"product": "מוצר",
"masked": "הודעה מוסתרת",
- "unknown": "הודעה"
+ "unknown": "הודעה",
+ "unknownType": "סוג לא ידוע"
},
"you": "אתה",
"youPrefix": "אתה: ",
diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.json
index c7cfa3a1b..c88e49f6b 100644
--- a/dashboard/src/i18n/locales/hi.json
+++ b/dashboard/src/i18n/locales/hi.json
@@ -115,7 +115,8 @@
"order": "ऑर्डर",
"product": "उत्पाद",
"masked": "छिपा हुआ संदेश",
- "unknown": "संदेश"
+ "unknown": "संदेश",
+ "unknownType": "अज्ञात प्रकार"
},
"you": "आप",
"youPrefix": "आप: ",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index a976a4fbe..022e6e1aa 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -116,7 +116,8 @@
"order": "Ordine",
"product": "Prodotto",
"masked": "Messaggio nascosto",
- "unknown": "Messaggio"
+ "unknown": "Messaggio",
+ "unknownType": "Tipo sconosciuto"
},
"you": "Tu",
"youPrefix": "Tu: ",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index e90cc0347..b3f9ba6b0 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -115,7 +115,8 @@
"order": "주문",
"product": "상품",
"masked": "가려진 메시지",
- "unknown": "메시지"
+ "unknown": "메시지",
+ "unknownType": "알 수 없는 유형"
},
"you": "나",
"youPrefix": "나: ",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 488b21d03..13c99593e 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -116,7 +116,8 @@
"order": "Pedido",
"product": "Produto",
"masked": "Mensagem oculta",
- "unknown": "Mensagem"
+ "unknown": "Mensagem",
+ "unknownType": "Tipo desconhecido"
},
"you": "Você",
"youPrefix": "Você: ",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index 4f68e7bfa..8fade1333 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -115,7 +115,8 @@
"order": "ఆర్డర్",
"product": "ఉత్పత్తి",
"masked": "దాచిన సందేశం",
- "unknown": "సందేశం"
+ "unknown": "సందేశం",
+ "unknownType": "తెలియని రకం"
},
"you": "మీరు",
"youPrefix": "మీరు: ",
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index 2f4869f50..ce928c5ee 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -115,7 +115,8 @@
"order": "Sipariş",
"product": "Ürün",
"masked": "Gizlenen mesaj",
- "unknown": "Mesaj"
+ "unknown": "Mesaj",
+ "unknownType": "Bilinmeyen tür"
},
"you": "Siz",
"youPrefix": "Siz: ",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index 20ac0674b..6d3680828 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -115,7 +115,8 @@
"order": "订单",
"product": "商品",
"masked": "已隐藏的消息",
- "unknown": "消息"
+ "unknown": "消息",
+ "unknownType": "未知类型"
},
"you": "你",
"youPrefix": "你:",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index b6b005999..6d227b03d 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -115,7 +115,8 @@
"order": "訂單",
"product": "商品",
"masked": "已隱藏的訊息",
- "unknown": "訊息"
+ "unknown": "訊息",
+ "unknownType": "未知類型"
},
"you": "你",
"youPrefix": "你:",
diff --git a/dashboard/src/utils/enumLabels.ts b/dashboard/src/utils/enumLabels.ts
new file mode 100644
index 000000000..9fd58efc5
--- /dev/null
+++ b/dashboard/src/utils/enumLabels.ts
@@ -0,0 +1,9 @@
+// i18n keys for enum values the API sends as raw keys.
+
+/**
+ * The key naming a message type where the type is a category: a chart slice, a webhook filter
+ * value. `unknown` there is an unclassified type, so it cannot use chats.messageType.unknown, the
+ * reply banner's generic "Message", which would read as "any message".
+ */
+export const messageTypeLabelKey = (type: string): string =>
+ type === 'unknown' ? 'chats.messageType.unknownType' : `chats.messageType.${type}`;