Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): say why an over-limit field holds Send
Yudhi Armyndharis929653ba88e3
diff --git a/dashboard/src/components/chats/StatusComposeModal.test.ts b/dashboard/src/components/chats/StatusComposeModal.test.tsindex 903bd377a..1bdb3484a 100644--- a/dashboard/src/components/chats/StatusComposeModal.test.ts+++ b/dashboard/src/components/chats/StatusComposeModal.test.ts@@ -180,8 +180,10 @@ test('status text and caption are bounded by Post, not truncated by UTF-16 unitsassert.equal(text.hasAttribute('maxlength'), false);fireEvent.change(text, { target: { value: '\u{1F600}'.repeat(4096) } });assert.equal(post.disabled, false, 'text the gateway accepts is held');+ assert.equal(screen.queryByText('Limited to 4096 characters (4096 now).'), null);fireEvent.change(text, { target: { value: '\u{1F600}'.repeat(4097) } });assert.equal(post.disabled, true, 'text over 4096 characters can be posted');+ screen.getByText('Limited to 4096 characters (4097 now).');fireEvent.click(screen.getByRole('button', { name: 'Image' }));fireEvent.change(screen.getByLabelText('Status image'), {@@ -194,4 +196,5 @@ test('status text and caption are bounded by Post, not truncated by UTF-16 unitsassert.equal(post.disabled, false, 'a caption the gateway accepts is held');fireEvent.change(caption, { target: { value: '\u{1F600}'.repeat(1025) } });assert.equal(post.disabled, true, 'a caption over 1024 characters can be posted');+ screen.getByText('Limited to 1024 characters (1025 now).');});diff --git a/dashboard/src/components/chats/StatusComposeModal.tsx b/dashboard/src/components/chats/StatusComposeModal.tsxindex bee61133e..bf4830221 100644--- a/dashboard/src/components/chats/StatusComposeModal.tsx+++ b/dashboard/src/components/chats/StatusComposeModal.tsx@@ -132,6 +132,8 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {reader.readAsDataURL(file);};+ const composeTextLength = captionLength(composeText.trim());+ const composeCaptionLength = captionLength(composeCaption.trim());const composeCanSubmit =Boolean(sessionId) &&!composePosting &&@@ -141,9 +143,7 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {(composeType === 'text' ? composeText.trim().length > 0 : Boolean(composeImageBase64 || composeImageUrl.trim())) &&// Bounded here rather than by a native maxLength, which counts UTF-16 units and would cut pasted// emoji the gateway accepts: it counts an astral character as one.- (composeType === 'text'- ? captionLength(composeText.trim()) <= 4096- : captionLength(composeCaption.trim()) <= 1024) &&+ (composeType === 'text' ? composeTextLength <= 4096 : composeCaptionLength <= 1024) &&(!isBaileysEngine || composeRecipients.length > 0);const handleComposeSubmit = async () => {@@ -218,6 +218,11 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {onChange={e => setComposeText(e.target.value)}placeholder={t('chats.status.composeText')}/>+ {composeTextLength > 4096 && (+ <p className="input-hint" role="status">+ {t('common.fieldTooLong', { max: 4096, count: composeTextLength })}+ </p>+ )}</div><div className="compose-row"><div className="compose-field">@@ -275,6 +280,11 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {value={composeCaption}onChange={e => setComposeCaption(e.target.value)}/>+ {composeCaptionLength > 1024 && (+ <p className="input-hint" role="status">+ {t('common.fieldTooLong', { max: 1024, count: composeCaptionLength })}+ </p>+ )}</div></>)}diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.jsonindex bd4bc8886..e8dd14770 100644--- a/dashboard/src/i18n/locales/ar.json+++ b/dashboard/src/i18n/locales/ar.json@@ -44,6 +44,7 @@"hoursAgo_many": "منذ {{count}} ساعة","hoursAgo_zero": "منذ {{count}} ساعة","optional": "اختياري",+ "fieldTooLong": "الحد الأقصى {{max}} حرفًا (الآن {{count}}).","language": "اللغة","back": "رجوع","next": "التالي",diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.jsonindex c7a1b19b7..dbc30a16f 100644--- a/dashboard/src/i18n/locales/de.json+++ b/dashboard/src/i18n/locales/de.json@@ -36,6 +36,7 @@"hoursAgo": "vor {{count}} Std.","hoursAgo_other": "vor {{count}} Std.","optional": "optional",+ "fieldTooLong": "Auf {{max}} Zeichen begrenzt (aktuell {{count}}).","language": "Sprache","back": "Zurück","next": "Weiter",diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.jsonindex a0147b07e..511921d0e 100644--- a/dashboard/src/i18n/locales/en.json+++ b/dashboard/src/i18n/locales/en.json@@ -36,6 +36,7 @@"hoursAgo": "{{count}} hour ago","hoursAgo_other": "{{count}} hours ago","optional": "optional",+ "fieldTooLong": "Limited to {{max}} characters ({{count}} now).","language": "Language","back": "Back","next": "Next",diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.jsonindex 236f458d6..efcb31733 100644--- a/dashboard/src/i18n/locales/es.json+++ b/dashboard/src/i18n/locales/es.json@@ -36,6 +36,7 @@"hoursAgo_other": "Hace {{count}} horas","hoursAgo_many": "Hace {{count}} horas","optional": "opcional",+ "fieldTooLong": "Limitado a {{max}} caracteres (ahora {{count}}).","language": "Idioma","back": "Atrás","next": "Siguiente",diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.jsonindex c19356d86..4ee7d12e1 100644--- a/dashboard/src/i18n/locales/fr.json+++ b/dashboard/src/i18n/locales/fr.json@@ -38,6 +38,7 @@"hoursAgo_other": "Il y a {{count}} heures","hoursAgo_many": "Il y a {{count}} heures","optional": "optionnel",+ "fieldTooLong": "Limité à {{max}} caractères ({{count}} actuellement).","language": "Langue","back": "Retour","next": "Suivant",diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.jsonindex 52c5a11a7..eecb53b79 100644--- a/dashboard/src/i18n/locales/he.json+++ b/dashboard/src/i18n/locales/he.json@@ -40,6 +40,7 @@"hoursAgo_other": "לפני {{count}} שעות","hoursAgo_two": "לפני שעתיים","optional": "אופציונלי",+ "fieldTooLong": "מוגבל ל-{{max}} תווים (כרגע {{count}}).","language": "שפה","back": "חזרה","next": "הבא",diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.jsonindex 1dd746fde..575869917 100644--- a/dashboard/src/i18n/locales/hi.json+++ b/dashboard/src/i18n/locales/hi.json@@ -36,6 +36,7 @@"hoursAgo": "{{count}} घंटे पहले","hoursAgo_other": "{{count}} घंटे पहले","optional": "वैकल्पिक",+ "fieldTooLong": "{{max}} वर्णों तक सीमित (अभी {{count}})।","language": "भाषा","back": "पीछे","next": "अगला",diff --git a/dashboard/src/i18n/locales/id.json b/dashboard/src/i18n/locales/id.jsonindex a21d94c9e..cced742f9 100644--- a/dashboard/src/i18n/locales/id.json+++ b/dashboard/src/i18n/locales/id.json@@ -36,6 +36,7 @@"hoursAgo": "{{count}} jam lalu","hoursAgo_other": "{{count}} jam lalu","optional": "opsional",+ "fieldTooLong": "Dibatasi {{max}} karakter (saat ini {{count}}).","language": "Bahasa","back": "Kembali","next": "Selanjutnya",diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.jsonindex 40669b21a..679173aac 100644--- a/dashboard/src/i18n/locales/it.json+++ b/dashboard/src/i18n/locales/it.json@@ -38,6 +38,7 @@"hoursAgo_other": "{{count}} ore fa","hoursAgo_many": "{{count}} ore fa","optional": "opzionale",+ "fieldTooLong": "Limitato a {{max}} caratteri (ora {{count}}).","language": "Lingua","back": "Indietro","next": "Avanti",diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.jsonindex 598ff0afc..479961fb1 100644--- a/dashboard/src/i18n/locales/ko.json+++ b/dashboard/src/i18n/locales/ko.json@@ -36,6 +36,7 @@"hoursAgo": "{{count}}시간 전","hoursAgo_other": "{{count}}시간 전","optional": "선택 사항",+ "fieldTooLong": "최대 {{max}}자입니다(현재 {{count}}자).","language": "언어","back": "뒤로","next": "다음",diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.jsonindex 879c62fa7..155a70407 100644--- a/dashboard/src/i18n/locales/pt-BR.json+++ b/dashboard/src/i18n/locales/pt-BR.json@@ -36,6 +36,7 @@"hoursAgo_other": "Há {{count}} horas","hoursAgo_many": "Há {{count}} horas","optional": "opcional",+ "fieldTooLong": "Limite de {{max}} caracteres (agora {{count}}).","language": "Idioma","back": "Voltar","next": "Próximo",diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.jsonindex 1324a83ef..34823975f 100644--- a/dashboard/src/i18n/locales/te.json+++ b/dashboard/src/i18n/locales/te.json@@ -36,6 +36,7 @@"hoursAgo": "{{count}} గంట క్రితం","hoursAgo_other": "{{count}} గంటల క్రితం","optional": "ఐచ్ఛికం",+ "fieldTooLong": "పరిమితి {{max}} అక్షరాలు (ప్రస్తుతం {{count}}).","language": "భాష","back": "వెనుకకు","next": "తరువాత",diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.jsonindex 4284aba89..1f8043cd1 100644--- a/dashboard/src/i18n/locales/tr.json+++ b/dashboard/src/i18n/locales/tr.json@@ -36,6 +36,7 @@"hoursAgo": "{{count}} saat önce","hoursAgo_other": "{{count}} saat önce","optional": "isteğe bağlı",+ "fieldTooLong": "En fazla {{max}} karakter olabilir (şu an {{count}}).","language": "Dil","back": "Geri","next": "İleri",diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.jsonindex 6ed9f2133..4cd71ee55 100644--- a/dashboard/src/i18n/locales/zh-CN.json+++ b/dashboard/src/i18n/locales/zh-CN.json@@ -36,6 +36,7 @@"hoursAgo": "{{count}} 小时前","hoursAgo_other": "{{count}} 小时前","optional": "可选",+ "fieldTooLong": "最多 {{max}} 个字符(当前 {{count}} 个)。","language": "语言","back": "返回","next": "下一步",diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.jsonindex 2125e68c0..96e3412a9 100644--- a/dashboard/src/i18n/locales/zh-HK.json+++ b/dashboard/src/i18n/locales/zh-HK.json@@ -36,6 +36,7 @@"hoursAgo": "{{count}} 小時前","hoursAgo_other": "{{count}} 小時前","optional": "選填",+ "fieldTooLong": "最多 {{max}} 個字元(目前 {{count}} 個)。","language": "語言","back": "返回","next": "下一步",diff --git a/dashboard/src/pages/ApiKeys.test.ts b/dashboard/src/pages/ApiKeys.test.tsindex 6bdd035ae..98ff8432b 100644--- a/dashboard/src/pages/ApiKeys.test.ts+++ b/dashboard/src/pages/ApiKeys.test.ts@@ -226,6 +226,7 @@ test('a key name over the 100 characters the gateway takes keeps Create disabledassert.equal(create.disabled, false, 'Create is disabled for a 100-character name');fireEvent.change(name, { target: { value: '\u{1F511}'.repeat(101) } });assert.equal(create.disabled, true, 'Create is enabled for a 101-character name');+ screen.getByText('Limited to 100 characters (101 now).');});test('an IP or chat line the gateway would refuse keeps Create disabled and names the line', async () => {diff --git a/dashboard/src/pages/ApiKeys.tsx b/dashboard/src/pages/ApiKeys.tsxindex 795d208c7..e9208cb47 100644--- a/dashboard/src/pages/ApiKeys.tsx+++ b/dashboard/src/pages/ApiKeys.tsx@@ -316,7 +316,8 @@ export function ApiKeys() {// The gateway takes a name of 3 to 100 characters, counted the way its validators count them (an// emoji is one); Create is held outside that range.const nameTooShort = captionLength(newKey.name.trim()) < 3;- const nameTooLong = [...newKey.name].length > 100;+ const nameLength = [...newKey.name].length;+ const nameTooLong = nameLength > 100;const canCreate =!createMutation.isPending && !nameTooShort && !nameTooLong && newErrors.ip === null && newErrors.chat === null;const canSave = !updateMutation.isPending && editErrors?.ip === null && editErrors.chat === null;@@ -578,6 +579,9 @@ export function ApiKeys() {{newKey.name.length > 0 && nameTooShort && (<span className="key-field-hint">{t('apiKeys.nameTooShort')}</span>)}+ {nameTooLong && (+ <span className="key-field-hint">{t('common.fieldTooLong', { max: 100, count: nameLength })}</span>+ )}<label htmlFor="ak-2">{t('common.role')}</label><selectid="ak-2"diff --git a/dashboard/src/pages/MessageTester.test.ts b/dashboard/src/pages/MessageTester.test.tsindex 8f01d7307..37113fbdc 100644--- a/dashboard/src/pages/MessageTester.test.ts+++ b/dashboard/src/pages/MessageTester.test.ts@@ -321,12 +321,15 @@ function setValue(element: HTMLElement, value: string): void {rtl.fireEvent.change(element, { target: { value } });}-/** Exactly `max` characters in `element` lets Send through; one more holds it. */+/** Exactly `max` characters in `element` lets Send through; one more holds it and says why. */async function assertLengthBound(element: HTMLElement, max: number, char = 'x'): Promise<void> {+ const reason = `Limited to ${max} characters (${max + 1} now).`;setValue(element, char.repeat(max));await rtl.waitFor(() => assert.equal(sendMessageButton().disabled, false));+ assert.equal(rtl.screen.queryByText(reason), null);setValue(element, char.repeat(max + 1));assert.equal(sendMessageButton().disabled, true);+ rtl.screen.getByText(reason);setValue(element, char.repeat(max));}diff --git a/dashboard/src/pages/MessageTester.tsx b/dashboard/src/pages/MessageTester.tsxindex 41fd5de99..ac27893fe 100644--- a/dashboard/src/pages/MessageTester.tsx+++ b/dashboard/src/pages/MessageTester.tsx@@ -1,4 +1,4 @@-import { useState, useEffect, useRef, type ChangeEvent } from 'react';+import { Fragment, useState, useEffect, useRef, type ChangeEvent } from 'react';import { useTranslation } from 'react-i18next';import { Send, CheckCircle, XCircle, Loader2, Upload, X, Plus, AlertCircle } from 'lucide-react';import {@@ -350,20 +350,21 @@ export function MessageTester() {const bulkCaptionTooLong =bulkAttachment !== null && bulkAttachment.kind !== 'audio' && captionLength(content) > BULK_CAPTION_MAX_LENGTH;+ // The text field goes out as the caption on image and video and as the filename on a document.+ const mediaContentMax =+ messageType === 'document'+ ? MEDIA_FILENAME_MAX_LENGTH+ : messageType === 'image' || messageType === 'video'+ ? BULK_CAPTION_MAX_LENGTH+ : Infinity;+// Per-type required-field validation (the backend stays the authoritative validator). A multi-group// send repeats the request per group, so a body the backend would refuse must not start the run.let formValid = true;if (messageType === 'text') {formValid = content.trim().length > 0 && captionLength(content) <= MESSAGE_TEXT_MAX_LENGTH;} else if (isMediaMessageType) {- // The text field goes out as the caption on image and video and as the filename on a document.- const contentMax =- messageType === 'document'- ? MEDIA_FILENAME_MAX_LENGTH- : messageType === 'image' || messageType === 'video'- ? BULK_CAPTION_MAX_LENGTH- : Infinity;- formValid = (!!mediaFile || isHttpMediaUrl(mediaUrl)) && captionLength(content) <= contentMax;+ formValid = (!!mediaFile || isHttpMediaUrl(mediaUrl)) && captionLength(content) <= mediaContentMax;} else if (messageType === 'location') {formValid =!Number.isNaN(lat) &&@@ -410,6 +411,16 @@ export function MessageTester() {!formValid ||(messageType !== 'bulk' && (recipientType === 'group' ? selectedGroups.length === 0 : !recipient));+ // Says why Send is held when a field runs past its bound, counted the way `formValid` counts it.+ const tooLongHint = (value: string, max: number) => {+ const count = captionLength(value);+ return (+ <span className="hint error" role="status">+ {count > max ? t('common.fieldTooLong', { max, count }) : ''}+ </span>+ );+ };+const isGroupSending = groupSendProgress !== null;const sendToGroups = async (chatIds: string[], sendTo: (chatId: string) => Promise<MessageResponse>) => {@@ -828,6 +839,7 @@ export function MessageTester() {placeholder={t('messageTester.messagePlaceholder')}rows={5}/>+ {tooLongHint(content, MESSAGE_TEXT_MAX_LENGTH)}</div>)}@@ -851,6 +863,7 @@ export function MessageTester() {: t('messageTester.captionPlaceholder')}/>+ {tooLongHint(content, mediaContentMax)}</div>)}</>@@ -896,6 +909,7 @@ export function MessageTester() {value={locationDescription}onChange={e => setLocationDescription(e.target.value)}/>+ {tooLongHint(locationDescription.trim(), LOCATION_TEXT_MAX_LENGTH)}</div><div className="form-group"><label htmlFor="mt-16">@@ -907,6 +921,7 @@ export function MessageTester() {value={locationAddress}onChange={e => setLocationAddress(e.target.value)}/>+ {tooLongHint(locationAddress.trim(), LOCATION_TEXT_MAX_LENGTH)}</div></>)}@@ -922,6 +937,7 @@ export function MessageTester() {onChange={e => setContactName(e.target.value)}placeholder={t('messageTester.contactNamePlaceholder')}/>+ {tooLongHint(contactName.trim(), CONTACT_NAME_MAX_LENGTH)}</div><div className="form-group"><label htmlFor="mt-7">{t('messageTester.contactNumber')}</label>@@ -932,6 +948,7 @@ export function MessageTester() {onChange={e => setContactNumber(e.target.value)}placeholder="+62812345678"/>+ {tooLongHint(contactNumber.trim(), CONTACT_NUMBER_MAX_LENGTH)}</div></>)}@@ -947,27 +964,31 @@ export function MessageTester() {onChange={e => setPollQuestion(e.target.value)}placeholder={t('messageTester.pollQuestionPlaceholder')}/>+ {tooLongHint(pollQuestion.trim(), POLL_NAME_MAX_LENGTH)}</div><div className="form-group"><label>{t('messageTester.pollOptions')}</label>{pollOptions.map((option, index) => (- <div className="poll-option-row" key={index}>- <input- type="text"- value={option}- onChange={e => setPollOptions(prev => prev.map((o, i) => (i === index ? e.target.value : o)))}- placeholder={t('messageTester.pollOptionPlaceholder', { index: index + 1 })}- />- <button- type="button"- className="remove-option-btn"- onClick={() => setPollOptions(prev => prev.filter((_, i) => i !== index))}- disabled={pollOptions.length <= 2}- aria-label={t('messageTester.removeOption')}- >- <X size={14} />- </button>- </div>+ <Fragment key={index}>+ <div className="poll-option-row">+ <input+ type="text"+ value={option}+ onChange={e => setPollOptions(prev => prev.map((o, i) => (i === index ? e.target.value : o)))}+ placeholder={t('messageTester.pollOptionPlaceholder', { index: index + 1 })}+ />+ <button+ type="button"+ className="remove-option-btn"+ onClick={() => setPollOptions(prev => prev.filter((_, i) => i !== index))}+ disabled={pollOptions.length <= 2}+ aria-label={t('messageTester.removeOption')}+ >+ <X size={14} />+ </button>+ </div>+ {tooLongHint(option.trim(), POLL_OPTION_MAX_LENGTH)}+ </Fragment>))}<buttontype="button"