Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): name status fonts after the protocol
Yudhi Armyndharis500540d2366b
diff --git a/dashboard/src/components/chats/StatusComposeModal.test.ts b/dashboard/src/components/chats/StatusComposeModal.test.tsindex 35142b5e9..dc49c93fb 100644--- a/dashboard/src/components/chats/StatusComposeModal.test.ts+++ b/dashboard/src/components/chats/StatusComposeModal.test.ts@@ -26,6 +26,9 @@ class CountingFileReader {const posted: unknown[] = [];// Contact-list reads, each answered with a 429.let contactReads = 0;+// While set, a contact read is answered with an empty list, so a test that only looks at the form leaves no retry+// or request timer behind.+let emptyContacts = false;before(async () => {const { installJsdomGlobals } = await import('../../test-helpers/jsdom.ts');@@ -34,6 +37,8 @@ before(async () => {globalThis.fetch = ((input: RequestInfo | URL, init?: RequestInit) => {if (String(input).includes('/contacts')) {contactReads += 1;+ if (emptyContacts)+ return Promise.resolve(new Response('[]', { headers: { 'Content-Type': 'application/json' } }));return Promise.resolve(new Response(JSON.stringify({ statusCode: 429, message: 'Too Many Requests' }), {status: 429,@@ -90,6 +95,7 @@ afterEach(() => {holdReads = false;posted.length = 0;contactReads = 0;+ emptyContacts = false;queryClient.clear();});@@ -227,3 +233,43 @@ test('a number typed in native digits finds a recipient by its number', async ()globalThis.fetch = stubbed;}});++// The ids are the protocol's FontType enum; the picker names them as the protocol does instead of showing bare numbers.+const fontOptions = () =>+ [...(document.getElementById('scm-3') as HTMLSelectElement).options].map(o => [o.value, o.textContent]);++test('the font picker names every id after the protocol, on Baileys', async () => {+ emptyContacts = true;+ render('baileys');+ // Let the contact read land first: an answer arriving after the next test's cache clear leaves a timer behind.+ await rtl.screen.findByText('No contacts found');+ assert.deepEqual(fontOptions(), [+ ['', 'Default'],+ ['0', 'System'],+ ['1', 'System text'],+ ['2', 'Script'],+ ['6', 'Bold'],+ ['7', 'Morning Breeze'],+ ['8', 'Calistoga'],+ ['9', 'Exo 2'],+ ['10', 'Courier Prime'],+ ]);+});++test('whatsapp-web.js is not offered the ids it posts in the default font', () => {+ render('whatsapp-web.js');+ assert.deepEqual(+ fontOptions().map(([value]) => value),+ ['', '0', '1', '2', '6', '7'],+ );+});++test('a picked font is posted under its own id', async () => {+ const { screen, fireEvent, waitFor } = rtl;+ render();+ fireEvent.change(document.getElementById('scm-1') as HTMLTextAreaElement, { target: { value: 'hello' } });+ fireEvent.change(document.getElementById('scm-3') as HTMLSelectElement, { target: { value: '2' } });+ fireEvent.click(screen.getByRole('button', { name: 'Post' }));+ await waitFor(() => assert.equal(posted.length, 1));+ assert.equal((posted[0] as { font?: number }).font, 2);+});diff --git a/dashboard/src/components/chats/StatusComposeModal.tsx b/dashboard/src/components/chats/StatusComposeModal.tsxindex 8844a1737..3c61c4f81 100644--- a/dashboard/src/components/chats/StatusComposeModal.tsx+++ b/dashboard/src/components/chats/StatusComposeModal.tsx@@ -9,6 +9,7 @@ import { Modal } from '../Modal';import { MEDIA_UPLOAD_MAX_BYTES } from '../../utils/mediaUpload';import { captionLength } from '../../utils/bulkMedia';import { matches } from '../../utils/chatFilters';+import { statusFontsFor } from '../../utils/statusFonts';// Mirrors @ArrayMaxSize(256) on the send-status DTOs — the picker caps selection client-side so the// user can't build a list the backend is guaranteed to reject.@@ -237,11 +238,10 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {<label htmlFor="scm-3">{t('chats.status.font')}</label><select id="scm-3" value={composeFont} onChange={e => setComposeFont(e.target.value)}><option value="">{t('chats.status.fontDefault')}</option>- {/* The WhatsApp status font enum: 6 is the bold system face; 3–5 don't exist on- the wire and the backend rejects them. */}- {[0, 1, 2, 6, 7, 8, 9, 10].map(f => (- <option key={f} value={f}>- {f}+ {/* The WhatsApp status font enum; 3 to 5 don't exist on the wire and the backend rejects them. */}+ {statusFontsFor(engineType).map(f => (+ <option key={f.id} value={f.id}>+ {t(f.labelKey)}</option>))}</select>diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.jsonindex a2aa70420..c304a2198 100644--- a/dashboard/src/i18n/locales/ar.json+++ b/dashboard/src/i18n/locales/ar.json@@ -188,6 +188,16 @@"backgroundColor": "لون الخلفية","font": "الخط","fontDefault": "افتراضي",+ "fonts": {+ "system": "النظام",+ "systemText": "نص النظام",+ "script": "خط يدوي",+ "bold": "غامق",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "أو","post": "نشر","posted": "تم نشر الحالة",diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.jsonindex 22368987a..224f4f314 100644--- a/dashboard/src/i18n/locales/de.json+++ b/dashboard/src/i18n/locales/de.json@@ -171,6 +171,16 @@"backgroundColor": "Hintergrundfarbe","font": "Schriftart","fontDefault": "Standard",+ "fonts": {+ "system": "System",+ "systemText": "Systemtext",+ "script": "Schreibschrift",+ "bold": "Fett",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "oder","post": "Posten","posted": "Status gepostet",diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.jsonindex 3e62e28ac..f39405508 100644--- a/dashboard/src/i18n/locales/en.json+++ b/dashboard/src/i18n/locales/en.json@@ -171,6 +171,16 @@"backgroundColor": "Background color","font": "Font","fontDefault": "Default",+ "fonts": {+ "system": "System",+ "systemText": "System text",+ "script": "Script",+ "bold": "Bold",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "or","post": "Post","posted": "Status posted",diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.jsonindex 4aefee4b7..3092c2fec 100644--- a/dashboard/src/i18n/locales/es.json+++ b/dashboard/src/i18n/locales/es.json@@ -175,6 +175,16 @@"backgroundColor": "Color de fondo","font": "Fuente","fontDefault": "Predeterminada",+ "fonts": {+ "system": "Sistema",+ "systemText": "Texto del sistema",+ "script": "Manuscrita",+ "bold": "Negrita",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "o","post": "Publicar","posted": "Estado publicado",diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.jsonindex 391d63013..f30229a07 100644--- a/dashboard/src/i18n/locales/fr.json+++ b/dashboard/src/i18n/locales/fr.json@@ -175,6 +175,16 @@"backgroundColor": "Couleur de fond","font": "Police","fontDefault": "Par défaut",+ "fonts": {+ "system": "Système",+ "systemText": "Texte système",+ "script": "Manuscrite",+ "bold": "Gras",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "ou","post": "Publier","posted": "Statut publié",diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.jsonindex 74ed3553f..58fa65c16 100644--- a/dashboard/src/i18n/locales/he.json+++ b/dashboard/src/i18n/locales/he.json@@ -180,6 +180,16 @@"backgroundColor": "צבע רקע","font": "גופן","fontDefault": "ברירת מחדל",+ "fonts": {+ "system": "מערכת",+ "systemText": "טקסט מערכת",+ "script": "כתב יד",+ "bold": "מודגש",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "או","post": "פרסם","posted": "הסטטוס פורסם",diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.jsonindex 17e42c4ae..013c717f6 100644--- a/dashboard/src/i18n/locales/hi.json+++ b/dashboard/src/i18n/locales/hi.json@@ -171,6 +171,16 @@"backgroundColor": "पृष्ठभूमि का रंग","font": "फ़ॉन्ट","fontDefault": "डिफ़ॉल्ट",+ "fonts": {+ "system": "सिस्टम",+ "systemText": "सिस्टम टेक्स्ट",+ "script": "स्क्रिप्ट",+ "bold": "बोल्ड",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "या","post": "पोस्ट करें","posted": "स्टेटस पोस्ट किया गया",diff --git a/dashboard/src/i18n/locales/id.json b/dashboard/src/i18n/locales/id.jsonindex 3597426f4..b3b801625 100644--- a/dashboard/src/i18n/locales/id.json+++ b/dashboard/src/i18n/locales/id.json@@ -171,6 +171,16 @@"backgroundColor": "Warna latar","font": "Font","fontDefault": "Default",+ "fonts": {+ "system": "Sistem",+ "systemText": "Teks sistem",+ "script": "Tulisan tangan",+ "bold": "Tebal",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "atau","post": "Posting","posted": "Status diposting",diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.jsonindex 381a7f671..5cb54d570 100644--- a/dashboard/src/i18n/locales/it.json+++ b/dashboard/src/i18n/locales/it.json@@ -175,6 +175,16 @@"backgroundColor": "Colore di sfondo","font": "Carattere","fontDefault": "Predefinito",+ "fonts": {+ "system": "Sistema",+ "systemText": "Testo di sistema",+ "script": "Corsivo",+ "bold": "Grassetto",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "o","post": "Pubblica","posted": "Stato pubblicato",diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.jsonindex 740f75135..96b2d60a1 100644--- a/dashboard/src/i18n/locales/ko.json+++ b/dashboard/src/i18n/locales/ko.json@@ -171,6 +171,16 @@"backgroundColor": "배경색","font": "글꼴","fontDefault": "기본값",+ "fonts": {+ "system": "시스템",+ "systemText": "시스템 텍스트",+ "script": "필기체",+ "bold": "굵게",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "또는","post": "게시","posted": "상태가 게시되었습니다",diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.jsonindex a72ebed00..290b686e7 100644--- a/dashboard/src/i18n/locales/pt-BR.json+++ b/dashboard/src/i18n/locales/pt-BR.json@@ -175,6 +175,16 @@"backgroundColor": "Cor de fundo","font": "Fonte","fontDefault": "Padrão",+ "fonts": {+ "system": "Sistema",+ "systemText": "Texto do sistema",+ "script": "Manuscrita",+ "bold": "Negrito",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "ou","post": "Publicar","posted": "Status publicado",diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.jsonindex dd941d6c4..d0b44fff9 100644--- a/dashboard/src/i18n/locales/te.json+++ b/dashboard/src/i18n/locales/te.json@@ -171,6 +171,16 @@"backgroundColor": "నేపథ్య రంగు","font": "ఫాంట్","fontDefault": "డిఫాల్ట్",+ "fonts": {+ "system": "సిస్టమ్",+ "systemText": "సిస్టమ్ టెక్స్ట్",+ "script": "స్క్రిప్ట్",+ "bold": "బోల్డ్",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "లేదా","post": "పోస్ట్ చేయండి","posted": "స్టేటస్ పోస్ట్ చేయబడింది",diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.jsonindex 345047115..0a5bfe3a4 100644--- a/dashboard/src/i18n/locales/tr.json+++ b/dashboard/src/i18n/locales/tr.json@@ -171,6 +171,16 @@"backgroundColor": "Arka plan rengi","font": "Yazı Tipi","fontDefault": "Varsayılan",+ "fonts": {+ "system": "Sistem",+ "systemText": "Sistem metni",+ "script": "El yazısı",+ "bold": "Kalın",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "veya","post": "Paylaş","posted": "Durum paylaşıldı",diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.jsonindex 54258af3d..b7affff74 100644--- a/dashboard/src/i18n/locales/zh-CN.json+++ b/dashboard/src/i18n/locales/zh-CN.json@@ -171,6 +171,16 @@"backgroundColor": "背景颜色","font": "字体","fontDefault": "默认",+ "fonts": {+ "system": "系统",+ "systemText": "系统文本",+ "script": "手写体",+ "bold": "粗体",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "或","post": "发布","posted": "状态已发布",diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.jsonindex 581120472..149606f80 100644--- a/dashboard/src/i18n/locales/zh-HK.json+++ b/dashboard/src/i18n/locales/zh-HK.json@@ -171,6 +171,16 @@"backgroundColor": "背景顏色","font": "字型","fontDefault": "預設",+ "fonts": {+ "system": "系統",+ "systemText": "系統文字",+ "script": "手寫體",+ "bold": "粗體",+ "morningBreeze": "Morning Breeze",+ "calistoga": "Calistoga",+ "exo2": "Exo 2",+ "courierPrime": "Courier Prime"+ },"orLabel": "或","post": "發佈","posted": "狀態已發佈",diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsxindex 032c05670..960d9a4cf 100644--- a/dashboard/src/pages/Chats.tsx+++ b/dashboard/src/pages/Chats.tsx@@ -75,6 +75,7 @@ import { useChatScrollPosition } from '../hooks/useChatScrollPosition';import { createTrailingCoalescer } from '../utils/trailingCoalescer';import { createReloadCoalescer, type ReloadCoalescer } from '../utils/reloadCoalescer';import { copyToClipboard } from '../utils/clipboard';+import { statusFontStyle } from '../utils/statusFonts';import MessageBody from '../components/chats/MessageBody';import MediaLightbox, { type LightboxItem } from '../components/chats/MediaLightbox';import KindIcon from '../components/chats/KindIcon';@@ -140,34 +141,6 @@ interface IncomingWsMessage {author?: string;}-// WhatsApp's text-status font slots — the current wire enum is {0,1,2,6,7,8,9,10} (6 is the bold-// system face); 3–5 are legacy slots older clients still emit. Approximated with generic-// families/weights since the actual faces are proprietary; slot 0 and unknown slots keep the UI-// default.-const STATUS_FONT: Record<number, { family?: string; weight?: number }> = {- 1: { family: 'serif' },- 2: { family: 'cursive' },- 3: { family: 'fantasy' }, // legacy- 4: { family: 'serif' }, // legacy- 5: { family: 'ui-rounded, system-ui, sans-serif' }, // legacy- 6: { weight: 700 },- 7: { family: 'cursive' },- 8: { family: 'serif' },- 9: { family: 'sans-serif', weight: 800 },- 10: { family: 'monospace', weight: 700 },-};--/** Inline style for a status item's font slot; {} when unstyled/unknown. */-const statusFontStyle = (font?: number): { fontFamily?: string; fontWeight?: number } => {- if (font === undefined) return {};- const slot = STATUS_FONT[font];- if (!slot) return {};- return {- ...(slot.family ? { fontFamily: slot.family } : {}),- ...(slot.weight ? { fontWeight: slot.weight } : {}),- };-};-// The confirmation dialog's copy for each destructive chat row action; its confirm button repeats the title.const CONFIRM_TEXT = {leave: {diff --git a/dashboard/src/utils/statusFonts.test.ts b/dashboard/src/utils/statusFonts.test.tsnew file mode 100644index 000000000..dc3d1473e--- /dev/null+++ b/dashboard/src/utils/statusFonts.test.ts@@ -0,0 +1,45 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { STATUS_FONTS, statusFontStyle, statusFontsFor } from './statusFonts.ts';++test('the offered ids are the protocol enum, so 3 to 5 are never offered', () => {+ assert.deepEqual(+ STATUS_FONTS.map(f => f.id),+ [0, 1, 2, 6, 7, 8, 9, 10],+ );+});++test('whatsapp-web.js is offered only the ids it honors, every other engine the whole enum', () => {+ assert.deepEqual(+ statusFontsFor('whatsapp-web.js').map(f => f.id),+ [0, 1, 2, 6, 7],+ );+ for (const engine of ['baileys', null]) {+ assert.deepEqual(+ statusFontsFor(engine).map(f => f.id),+ [0, 1, 2, 6, 7, 8, 9, 10],+ );+ }+});++test('id 1 is the system text face, not a serif one', () => {+ assert.deepEqual(statusFontStyle(1), { fontFamily: 'system-ui, sans-serif' });+});++test('every other id keeps the face its protocol name suggests', () => {+ assert.deepEqual(statusFontStyle(2), { fontFamily: 'cursive' });+ assert.deepEqual(statusFontStyle(6), { fontWeight: 700 });+ assert.deepEqual(statusFontStyle(7), { fontFamily: 'cursive' });+ assert.deepEqual(statusFontStyle(8), { fontFamily: 'serif' });+ assert.deepEqual(statusFontStyle(9), { fontFamily: 'sans-serif', fontWeight: 800 });+ assert.deepEqual(statusFontStyle(10), { fontFamily: 'monospace', fontWeight: 700 });+});++test('the default face, an absent id and an unknown id are left unstyled; the legacy ids still draw', () => {+ assert.deepEqual(statusFontStyle(0), {});+ assert.deepEqual(statusFontStyle(undefined), {});+ assert.deepEqual(statusFontStyle(11), {});+ assert.deepEqual(statusFontStyle(3), { fontFamily: 'fantasy' });+ assert.deepEqual(statusFontStyle(4), { fontFamily: 'serif' });+ assert.deepEqual(statusFontStyle(5), { fontFamily: 'ui-rounded, system-ui, sans-serif' });+});diff --git a/dashboard/src/utils/statusFonts.ts b/dashboard/src/utils/statusFonts.tsnew file mode 100644index 000000000..1700a4914--- /dev/null+++ b/dashboard/src/utils/statusFonts.ts@@ -0,0 +1,51 @@+// WhatsApp's text-status font ids as the protocol names them (ExtendedTextMessage.FontType): 0 SYSTEM, 1 SYSTEM_TEXT,+// 2 FB_SCRIPT, 6 SYSTEM_BOLD, 7 MORNINGBREEZE_REGULAR, 8 CALISTOGA_REGULAR, 9 EXO2_EXTRABOLD, 10 COURIERPRIME_BOLD.+// 3 to 5 are not part of the enum and the gateway rejects them; older clients still emit them on a received status,+// so the preview below keeps a face for them. The faces are approximations with generic families and weights, since+// the real ones are proprietary.+interface Face {+ family?: string;+ weight?: number;+}++interface StatusFont extends Face {+ id: number;+ // The picker label in plain language; the product names stay as the protocol has them.+ labelKey: string;+}++export const STATUS_FONTS: readonly StatusFont[] = [+ { id: 0, labelKey: 'chats.status.fonts.system' },+ { id: 1, labelKey: 'chats.status.fonts.systemText', family: 'system-ui, sans-serif' },+ { id: 2, labelKey: 'chats.status.fonts.script', family: 'cursive' },+ { id: 6, labelKey: 'chats.status.fonts.bold', weight: 700 },+ { id: 7, labelKey: 'chats.status.fonts.morningBreeze', family: 'cursive' },+ { id: 8, labelKey: 'chats.status.fonts.calistoga', family: 'serif' },+ { id: 9, labelKey: 'chats.status.fonts.exo2', family: 'sans-serif', weight: 800 },+ { id: 10, labelKey: 'chats.status.fonts.courierPrime', family: 'monospace', weight: 700 },+];++// Legacy ids 3 to 5 of an older client's status: shown, never offered.+const LEGACY_FONT_FACES: Record<number, Face> = {+ 3: { family: 'fantasy' },+ 4: { family: 'serif' },+ 5: { family: 'ui-rounded, system-ui, sans-serif' },+};++// whatsapp-web.js posts an id above this one in the default font (Utils.js clamps fontStyle to 0 to 7).+export const WWEBJS_STATUS_FONT_MAX = 7;++/** The fonts the composer offers for an engine: whatsapp-web.js ignores 8 to 10, so it is not offered them. */+export const statusFontsFor = (engineType: string | null): readonly StatusFont[] =>+ engineType === 'whatsapp-web.js' ? STATUS_FONTS.filter(f => f.id <= WWEBJS_STATUS_FONT_MAX) : STATUS_FONTS;++/** Inline style for a status item's font id; {} when unstyled/unknown. */+export const statusFontStyle = (font?: number): { fontFamily?: string; fontWeight?: number } => {+ if (font === undefined) return {};+ const slot: Face | undefined = STATUS_FONTS.find(f => f.id === font) ?? LEGACY_FONT_FACES[font];+ if (!slot) return {};+ return {+ ...(slot.family ? { fontFamily: slot.family } : {}),+ ...(slot.weight ? { fontWeight: slot.weight } : {}),+ };+};