Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): reject non-http(s) bulk media URLs and respect the caption limit

Cares T.993e507c87ea
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index 96c0860f3..75d99448f 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -718,7 +718,9 @@
"bulkDelayHint": "1000–60000 مللي ثانية (الافتراضي 3000)",
"bulkMediaKind": "إرسال كـ",
"bulkMediaHint": "عند إرفاق ملف تصبح الرسالة تعليقًا عليه. يُرسل الملف المختار داخل الطلب نفسه، لذا تحتاج الملفات الكبيرة لعدد كبير من المستلمين إلى رابط وسائط عام بدلًا منه.",
- "bulkMediaTooLarge": "هذا الملف كبير جدًا لإرساله مضمَّنًا إلى {{count}} مستلمين. استخدم رابط وسائط عامًا بدلًا منه، أو أرسل إلى عدد أقل من المستلمين.",
+ "bulkMediaTooLarge": "هذا الملف كبير جدًا لإرساله مضمَّنًا إلى {{count}} مستلمين: بهذا العدد يمكن أن يصل حجم الملف إلى {{size}} كحد أقصى. استخدم رابط وسائط عامًا بدلًا منه، أو أرسل إلى عدد أقل من المستلمين.",
+ "bulkMediaUrlInvalid": "استخدم عنوانًا كاملًا يبدأ بـ http:// أو https://، مثل https://example.com/file.pdf.",
+ "bulkCaptionTooLong": "عند إرفاق ملف تُرسل الرسالة كتعليق عليه، والحد الأقصى للتعليق {{max}} حرفًا (الآن {{count}}).",
"send": "إرسال الرسالة",
"sending": "جارٍ الإرسال...",
"viewOnly": "للعرض فقط",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index e9567d0d5..e697b9468 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -703,7 +703,9 @@
"bulkDelayHint": "1000–60000 ms (Standard: 3000)",
"bulkMediaKind": "Senden als",
"bulkMediaHint": "Mit Anhang wird die Nachricht zu dessen Bildunterschrift. Eine ausgewählte Datei wird direkt in der Anfrage mitgesendet, daher brauchen große Dateien für viele Empfänger stattdessen eine öffentliche Medien-URL.",
- "bulkMediaTooLarge": "Diese Datei ist zu groß, um sie direkt an {{count}} Empfänger zu senden. Verwende stattdessen eine öffentliche Medien-URL oder sende an weniger Empfänger.",
+ "bulkMediaTooLarge": "Diese Datei ist zu groß, um sie direkt an {{count}} Empfänger zu senden: Bei dieser Anzahl darf eine Datei höchstens {{size}} groß sein. Verwende stattdessen eine öffentliche Medien-URL oder sende an weniger Empfänger.",
+ "bulkMediaUrlInvalid": "Gib eine vollständige http://- oder https://-Adresse ein, z. B. https://example.com/file.pdf.",
+ "bulkCaptionTooLong": "Mit Anhang wird die Nachricht als dessen Bildunterschrift gesendet, die auf {{max}} Zeichen begrenzt ist (aktuell {{count}}).",
"send": "Nachricht senden",
"sending": "Wird gesendet...",
"viewOnly": "Nur ansehen",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index dddf1ad12..7b2f4a08d 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -703,7 +703,9 @@
"bulkDelayHint": "1000–60000 ms (default 3000)",
"bulkMediaKind": "Send as",
"bulkMediaHint": "With an attachment, the message becomes its caption. A picked file travels inside the request, so large files for many recipients need a public media URL instead.",
- "bulkMediaTooLarge": "This file is too large to send inline to {{count}} recipients. Use a public media URL instead, or send to fewer recipients.",
+ "bulkMediaTooLarge": "This file is too large to send inline to {{count}} recipients: at that count each file can be at most {{size}}. Use a public media URL instead, or send to fewer recipients.",
+ "bulkMediaUrlInvalid": "Use a full http:// or https:// address, like https://example.com/file.pdf.",
+ "bulkCaptionTooLong": "With an attachment the message goes out as its caption, which is limited to {{max}} characters ({{count}} now).",
"send": "Send Message",
"sending": "Sending...",
"viewOnly": "View Only",
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index 50ca7a070..dffc558dd 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -654,7 +654,9 @@
"bulkDelayHint": "1000–60000 ms (predeterminado: 3000)",
"bulkMediaKind": "Enviar como",
"bulkMediaHint": "Con un adjunto, el mensaje pasa a ser su pie de foto. Un archivo seleccionado viaja dentro de la solicitud, así que los archivos grandes para muchos destinatarios necesitan una URL de medios pública.",
- "bulkMediaTooLarge": "Este archivo es demasiado grande para enviarlo directamente a {{count}} destinatarios. Usa una URL de medios pública o envía a menos destinatarios.",
+ "bulkMediaTooLarge": "Este archivo es demasiado grande para enviarlo directamente a {{count}} destinatarios: con esa cantidad, cada archivo puede ocupar como máximo {{size}}. Usa una URL de medios pública o envía a menos destinatarios.",
+ "bulkMediaUrlInvalid": "Usa una dirección completa con http:// o https://, por ejemplo https://example.com/file.pdf.",
+ "bulkCaptionTooLong": "Con un adjunto, el mensaje se envía como su pie de foto, que está limitado a {{max}} caracteres (ahora {{count}}).",
"send": "Enviar mensaje",
"sending": "Enviando...",
"viewOnly": "Solo lectura",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index afa4a96a9..e6375d286 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -703,7 +703,9 @@
"bulkDelayHint": "1000–60000 ms (par défaut : 3000)",
"bulkMediaKind": "Envoyer en tant que",
"bulkMediaHint": "Avec une pièce jointe, le message devient sa légende. Un fichier sélectionné est envoyé dans la requête elle-même : pour un gros fichier et de nombreux destinataires, utilisez plutôt une URL de média publique.",
- "bulkMediaTooLarge": "Ce fichier est trop volumineux pour être envoyé directement à {{count}} destinataires. Utilisez plutôt une URL de média publique ou envoyez à moins de destinataires.",
+ "bulkMediaTooLarge": "Ce fichier est trop volumineux pour être envoyé directement à {{count}} destinataires : à ce nombre, chaque fichier peut faire au maximum {{size}}. Utilisez plutôt une URL de média publique ou envoyez à moins de destinataires.",
+ "bulkMediaUrlInvalid": "Saisissez une adresse complète en http:// ou https://, par exemple https://example.com/file.pdf.",
+ "bulkCaptionTooLong": "Avec une pièce jointe, le message est envoyé comme sa légende, limitée à {{max}} caractères ({{count}} actuellement).",
"send": "Envoyer le message",
"sending": "Envoi...",
"viewOnly": "Lecture seule",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index e44d8378b..0917b230b 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -712,7 +712,9 @@
"bulkDelayHint": "1000–60000 אלפיות שנייה (ברירת מחדל 3000)",
"bulkMediaKind": "שליחה בתור",
"bulkMediaHint": "כשמצורף קובץ, ההודעה הופכת לכיתוב שלו. קובץ שנבחר נשלח בתוך הבקשה עצמה, ולכן קבצים גדולים לנמענים רבים דורשים כתובת URL ציבורית למדיה במקום זאת.",
- "bulkMediaTooLarge": "הקובץ גדול מדי לשליחה ישירה אל {{count}} נמענים. יש להשתמש בכתובת URL ציבורית למדיה במקום זאת, או לשלוח לפחות נמענים.",
+ "bulkMediaTooLarge": "הקובץ גדול מדי לשליחה ישירה אל {{count}} נמענים: בכמות כזו כל קובץ יכול להיות בגודל של {{size}} לכל היותר. יש להשתמש בכתובת URL ציבורית למדיה במקום זאת, או לשלוח לפחות נמענים.",
+ "bulkMediaUrlInvalid": "יש להזין כתובת מלאה שמתחילה ב-http:// או ב-https://, למשל https://example.com/file.pdf.",
+ "bulkCaptionTooLong": "כשמצורף קובץ, ההודעה נשלחת ככיתוב שלו, שמוגבל ל-{{max}} תווים (כרגע {{count}}).",
"send": "שליחת הודעה",
"sending": "שולח...",
"viewOnly": "צפייה בלבד",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index f604b3358..6ab262844 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -703,7 +703,9 @@
"bulkDelayHint": "1000–60000 ms (predefinito: 3000)",
"bulkMediaKind": "Invia come",
"bulkMediaHint": "Con un allegato, il messaggio diventa la sua didascalia. Un file selezionato viaggia dentro la richiesta, quindi i file grandi per molti destinatari richiedono invece un URL multimediale pubblico.",
- "bulkMediaTooLarge": "Questo file è troppo grande per inviarlo direttamente a {{count}} destinatari. Usa invece un URL multimediale pubblico o invia a meno destinatari.",
+ "bulkMediaTooLarge": "Questo file è troppo grande per inviarlo direttamente a {{count}} destinatari: con questo numero ogni file può essere al massimo di {{size}}. Usa invece un URL multimediale pubblico o invia a meno destinatari.",
+ "bulkMediaUrlInvalid": "Usa un indirizzo completo con http:// o https://, per esempio https://example.com/file.pdf.",
+ "bulkCaptionTooLong": "Con un allegato il messaggio viene inviato come sua didascalia, limitata a {{max}} caratteri (ora {{count}}).",
"send": "Invia Messaggio",
"sending": "Invio in corso...",
"viewOnly": "Sola Visualizzazione",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index 9e64af7cd..d7495de4c 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -703,7 +703,9 @@
"bulkDelayHint": "1000–60000ms (기본값 3000)",
"bulkMediaKind": "전송 형식",
"bulkMediaHint": "첨부 파일이 있으면 메시지가 캡션이 됩니다. 선택한 파일은 요청 안에 담겨 전송되므로, 큰 파일을 많은 수신자에게 보내려면 공개 미디어 URL을 사용해야 합니다.",
- "bulkMediaTooLarge": "이 파일은 {{count}}명의 수신자에게 직접 보내기에는 너무 큽니다. 대신 공개 미디어 URL을 사용하거나 수신자 수를 줄이세요.",
+ "bulkMediaTooLarge": "이 파일은 {{count}}명의 수신자에게 직접 보내기에는 너무 큽니다. 이 인원수에서는 파일당 최대 {{size}}까지 가능합니다. 대신 공개 미디어 URL을 사용하거나 수신자 수를 줄이세요.",
+ "bulkMediaUrlInvalid": "http:// 또는 https://로 시작하는 전체 주소를 입력하세요. 예: https://example.com/file.pdf",
+ "bulkCaptionTooLong": "첨부 파일이 있으면 메시지가 캡션으로 전송되며, 캡션은 최대 {{max}}자입니다(현재 {{count}}자).",
"send": "메시지 보내기",
"sending": "보내는 중...",
"viewOnly": "읽기 전용",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 6291793b5..0a3267631 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -654,7 +654,9 @@
"bulkDelayHint": "1000–60000 ms (padrão: 3000)",
"bulkMediaKind": "Enviar como",
"bulkMediaHint": "Com um anexo, a mensagem vira a legenda dele. Um arquivo selecionado vai dentro da própria requisição, então arquivos grandes para muitos destinatários precisam de uma URL de mídia pública.",
- "bulkMediaTooLarge": "Este arquivo é grande demais para enviar diretamente a {{count}} destinatários. Use uma URL de mídia pública ou envie para menos destinatários.",
+ "bulkMediaTooLarge": "Este arquivo é grande demais para enviar diretamente a {{count}} destinatários: com essa quantidade, cada arquivo pode ter no máximo {{size}}. Use uma URL de mídia pública ou envie para menos destinatários.",
+ "bulkMediaUrlInvalid": "Use um endereço completo com http:// ou https://, por exemplo https://example.com/file.pdf.",
+ "bulkCaptionTooLong": "Com um anexo, a mensagem é enviada como a legenda dele, que tem limite de {{max}} caracteres (agora {{count}}).",
"send": "Enviar mensagem",
"sending": "Enviando...",
"viewOnly": "Somente leitura",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index e5c645995..dda34d595 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -703,7 +703,9 @@
"bulkDelayHint": "1000–60000 ms (డిఫాల్ట్ 3000)",
"bulkMediaKind": "ఇలా పంపండి",
"bulkMediaHint": "అటాచ్‌మెంట్ ఉన్నప్పుడు సందేశం దాని క్యాప్షన్‌గా మారుతుంది. ఎంచుకున్న ఫైల్ అభ్యర్థనలోనే పంపబడుతుంది, కాబట్టి పెద్ద ఫైల్‌లను చాలా మంది గ్రహీతలకు పంపడానికి పబ్లిక్ మీడియా URL అవసరం.",
- "bulkMediaTooLarge": "ఈ ఫైల్‌ను {{count}} గ్రహీతలకు నేరుగా పంపడానికి ఇది చాలా పెద్దది. దానికి బదులుగా పబ్లిక్ మీడియా URLని ఉపయోగించండి లేదా తక్కువ మంది గ్రహీతలకు పంపండి.",
+ "bulkMediaTooLarge": "ఈ ఫైల్‌ను {{count}} గ్రహీతలకు నేరుగా పంపడానికి ఇది చాలా పెద్దది: ఈ సంఖ్యలో ఒక్కో ఫైల్ గరిష్ఠంగా {{size}} ఉండవచ్చు. దానికి బదులుగా పబ్లిక్ మీడియా URLని ఉపయోగించండి లేదా తక్కువ మంది గ్రహీతలకు పంపండి.",
+ "bulkMediaUrlInvalid": "http:// లేదా https://తో మొదలయ్యే పూర్తి చిరునామాను ఉపయోగించండి, ఉదా: https://example.com/file.pdf.",
+ "bulkCaptionTooLong": "అటాచ్‌మెంట్ ఉన్నప్పుడు సందేశం దాని క్యాప్షన్‌గా పంపబడుతుంది, దాని పరిమితి {{max}} అక్షరాలు (ప్రస్తుతం {{count}}).",
"send": "సందేశం పంపు",
"sending": "పంపుతోంది...",
"viewOnly": "చూడటానికి మాత్రమే",
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index 30929b1b6..95b5a0ba5 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -703,7 +703,9 @@
"bulkDelayHint": "1000–60000 ms (varsayılan 3000)",
"bulkMediaKind": "Gönderme biçimi",
"bulkMediaHint": "Dosya eklendiğinde mesaj, dosyanın açıklaması olur. Seçilen dosya isteğin içinde gönderilir; bu yüzden çok sayıda alıcıya büyük dosya göndermek için herkese açık bir medya URL'si kullanın.",
- "bulkMediaTooLarge": "Bu dosya {{count}} alıcıya doğrudan gönderilemeyecek kadar büyük. Bunun yerine herkese açık bir medya URL'si kullanın veya daha az alıcıya gönderin.",
+ "bulkMediaTooLarge": "Bu dosya {{count}} alıcıya doğrudan gönderilemeyecek kadar büyük: bu alıcı sayısında dosya en fazla {{size}} olabilir. Bunun yerine herkese açık bir medya URL'si kullanın veya daha az alıcıya gönderin.",
+ "bulkMediaUrlInvalid": "http:// veya https:// ile başlayan tam bir adres girin, örneğin https://example.com/file.pdf.",
+ "bulkCaptionTooLong": "Dosya eklendiğinde mesaj, dosyanın açıklaması olarak gönderilir ve açıklama en fazla {{max}} karakter olabilir (şu an {{count}}).",
"send": "Mesajı Gönder",
"sending": "Gönderiliyor...",
"viewOnly": "Yalnızca Görüntüle",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index fb40d1512..15b1c6d75 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -703,7 +703,9 @@
"bulkDelayHint": "1000–60000 毫秒(默认 3000)",
"bulkMediaKind": "发送为",
"bulkMediaHint": "添加附件后,消息将作为附件的说明文字。所选文件会随请求一起发送,因此向大量接收者发送大文件时,请改用公开的媒体 URL。",
- "bulkMediaTooLarge": "此文件太大,无法直接发送给 {{count}} 位接收者。请改用公开的媒体 URL,或减少接收者数量。",
+ "bulkMediaTooLarge": "此文件太大,无法直接发送给 {{count}} 位接收者:在这个人数下,每个文件最大只能为 {{size}}。请改用公开的媒体 URL,或减少接收者数量。",
+ "bulkMediaUrlInvalid": "请输入以 http:// 或 https:// 开头的完整地址,例如 https://example.com/file.pdf。",
+ "bulkCaptionTooLong": "添加附件后,消息将作为附件的说明文字发送,说明文字最多 {{max}} 个字符(当前 {{count}} 个)。",
"send": "发送消息",
"sending": "正在发送...",
"viewOnly": "仅查看",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index 97edfb021..4cbb45a79 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -703,7 +703,9 @@
"bulkDelayHint": "1000–60000 毫秒(預設 3000)",
"bulkMediaKind": "傳送為",
"bulkMediaHint": "加入附件後,訊息會成為附件的說明文字。所選檔案會隨請求一併傳送,因此向大量收件人傳送大型檔案時,請改用公開的媒體 URL。",
- "bulkMediaTooLarge": "此檔案太大,無法直接傳送給 {{count}} 位收件人。請改用公開的媒體 URL,或減少收件人數目。",
+ "bulkMediaTooLarge": "此檔案太大,無法直接傳送給 {{count}} 位收件人:以這個人數計,每個檔案最大只能為 {{size}}。請改用公開的媒體 URL,或減少收件人數目。",
+ "bulkMediaUrlInvalid": "請輸入以 http:// 或 https:// 開頭的完整地址,例如 https://example.com/file.pdf。",
+ "bulkCaptionTooLong": "加入附件後,訊息會作為附件的說明文字傳送,說明文字最多 {{max}} 個字元(目前 {{count}} 個)。",
"send": "傳送訊息",
"sending": "正在傳送...",
"viewOnly": "僅檢視",
diff --git a/dashboard/src/pages/MessageTester.css b/dashboard/src/pages/MessageTester.css
index 454437367..73eccd72e 100644
--- a/dashboard/src/pages/MessageTester.css
+++ b/dashboard/src/pages/MessageTester.css
@@ -300,6 +300,10 @@
color: var(--error-text);
}
+.message-tester .form-group .hint:empty {
+ margin-top: 0;
+}
+
/* Side-by-side pair (location latitude/longitude). */
.message-tester .form-row {
display: grid;
diff --git a/dashboard/src/pages/MessageTester.tsx b/dashboard/src/pages/MessageTester.tsx
index 29cac24c3..7faf92b27 100644
--- a/dashboard/src/pages/MessageTester.tsx
+++ b/dashboard/src/pages/MessageTester.tsx
@@ -14,8 +14,13 @@ import { useRole } from '../hooks/useRole';
import { useSessionsQuery, useSessionGroupsQuery } from '../hooks/queries';
import { parseBulkRecipients, BULK_MAX_RECIPIENTS, BULK_RECIPIENTS_FILE_MAX_BYTES } from '../utils/bulkRecipients';
import {
+ BULK_CAPTION_MAX_LENGTH,
+ BULK_INLINE_MEDIA_MAX_BYTES,
BULK_MEDIA_KINDS,
buildBulkMessages,
+ formatFileSize,
+ inlineMediaBudgetBytes,
+ isHttpMediaUrl,
mediaKindFromMime,
mediaKindFromUrl,
toBulkAttachment,
@@ -91,8 +96,6 @@ const fallbackMime: Record<(typeof messageTypes)[number], string> = {
// backend's MEDIA_DOWNLOAD_MAX_BYTES (default 50 MiB) stays authoritative for URL sends (fetched server-side).
const MEDIA_UPLOAD_MAX_BYTES = 18 * 1024 * 1024;
-const BULK_INLINE_MEDIA_MAX_BYTES = 24 * 1024 * 1024;
-
// Batch statuses that stop the progress polling (mirrors the backend BatchStatus enum).
const TERMINAL_BATCH_STATUSES: readonly BatchStatus[] = ['completed', 'cancelled', 'failed'];
@@ -144,6 +147,7 @@ export function MessageTester() {
const [bulkRecipients, setBulkRecipients] = useState('');
const [bulkDelay, setBulkDelay] = useState('');
const [bulkMediaKind, setBulkMediaKind] = useState<BulkMediaKind>('document');
+ const [bulkMediaKindChosen, setBulkMediaKindChosen] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [response, setResponse] = useState<ApiResponse | null>(null);
// Live bulk-batch progress, polled every ~2s while the batch runs (see startBatchPolling).
@@ -268,7 +272,10 @@ export function MessageTester() {
setMediaFile({ base64, mimetype, filename: file.name });
setMediaUrl('');
if (messageType === 'document') setContent(file.name);
- if (messageType === 'bulk') setBulkMediaKind(mediaKindFromMime(mimetype));
+ if (messageType === 'bulk') {
+ setBulkMediaKind(mediaKindFromMime(mimetype));
+ setBulkMediaKindChosen(false);
+ }
};
reader.onerror = () => {
if (mediaReadSeq.current !== myRead) return;
@@ -288,6 +295,9 @@ export function MessageTester() {
messageType === 'bulk' &&
!!mediaFile &&
mediaFile.base64.length * bulkRecipientList.length > BULK_INLINE_MEDIA_MAX_BYTES;
+ const bulkMediaUrlInvalid =
+ messageType === 'bulk' && !mediaFile && mediaUrl.trim() !== '' && !isHttpMediaUrl(mediaUrl);
+ const bulkCaptionTooLong = bulkAttachment !== null && content.length > BULK_CAPTION_MAX_LENGTH;
// Per-type required-field validation for the newer types; text/media keep their original behavior
// (the backend stays the authoritative validator either way).
@@ -306,6 +316,8 @@ export function MessageTester() {
formValid =
(content.trim().length > 0 || bulkAttachment !== null) &&
!bulkMediaTooLarge &&
+ !bulkMediaUrlInvalid &&
+ !bulkCaptionTooLong &&
bulkRecipientList.length > 0 &&
bulkRecipientList.length <= BULK_MAX_RECIPIENTS &&
(delayMs === undefined || (!Number.isNaN(delayMs) && delayMs >= 1000 && delayMs <= 60000));
@@ -486,11 +498,19 @@ export function MessageTester() {
// in flight (its late onload would otherwise re-clear this URL).
mediaReadSeq.current += 1;
if (mediaFile) setMediaFile(null);
- if (messageType === 'bulk') setBulkMediaKind(mediaKindFromUrl(e.target.value));
+ if (messageType === 'bulk') {
+ if (!e.target.value.trim()) setBulkMediaKindChosen(false);
+ else if (!bulkMediaKindChosen) setBulkMediaKind(mediaKindFromUrl(e.target.value));
+ }
}}
placeholder="https://example.com/file.jpg"
disabled={!!mediaFile}
/>
+ {messageType === 'bulk' && (
+ <span className="hint error" role="status">
+ {bulkMediaUrlInvalid ? t('messageTester.bulkMediaUrlInvalid') : ''}
+ </span>
+ )}
</div>
<div className="form-group">
<label>
@@ -519,9 +539,12 @@ export function MessageTester() {
onChange={handleFileChange}
/>
{messageType === 'bulk' && (
- <span className={bulkMediaTooLarge ? 'hint error' : 'hint'} role={bulkMediaTooLarge ? 'alert' : undefined}>
+ <span className={bulkMediaTooLarge ? 'hint error' : 'hint'} role="status">
{bulkMediaTooLarge
- ? t('messageTester.bulkMediaTooLarge', { count: bulkRecipientList.length })
+ ? t('messageTester.bulkMediaTooLarge', {
+ count: bulkRecipientList.length,
+ size: formatFileSize(inlineMediaBudgetBytes(bulkRecipientList.length)),
+ })
: t('messageTester.bulkMediaHint')}
</span>
)}
@@ -644,7 +667,10 @@ export function MessageTester() {
// category would route stale bytes to the wrong send-${type} endpoint — clear it.
if (type !== messageType) {
clearMediaFile();
- if (type === 'bulk' || messageType === 'bulk') setMediaUrl('');
+ if (type === 'bulk' || messageType === 'bulk') {
+ setMediaUrl('');
+ setBulkMediaKindChosen(false);
+ }
}
setMessageType(type);
}}
@@ -915,6 +941,11 @@ export function MessageTester() {
placeholder={t('messageTester.messagePlaceholder')}
rows={4}
/>
+ <span className="hint error" role="status">
+ {bulkCaptionTooLong
+ ? t('messageTester.bulkCaptionTooLong', { max: BULK_CAPTION_MAX_LENGTH, count: content.length })
+ : ''}
+ </span>
</div>
{mediaSourceFields}
{bulkAttachment && (
@@ -933,7 +964,10 @@ export function MessageTester() {
type="button"
aria-pressed={bulkMediaKind === kind}
className={bulkMediaKind === kind ? 'active' : ''}
- onClick={() => setBulkMediaKind(kind)}
+ onClick={() => {
+ setBulkMediaKind(kind);
+ setBulkMediaKindChosen(true);
+ }}
>
{t(`messageTester.types.${kind}`)}
</button>
diff --git a/dashboard/src/utils/bulkMedia.test.ts b/dashboard/src/utils/bulkMedia.test.ts
index 808556dd4..9012a9b9a 100644
--- a/dashboard/src/utils/bulkMedia.test.ts
+++ b/dashboard/src/utils/bulkMedia.test.ts
@@ -3,6 +3,9 @@ import assert from 'node:assert/strict';
import {
buildBulkMessages,
filenameFromUrl,
+ formatFileSize,
+ inlineMediaBudgetBytes,
+ isHttpMediaUrl,
mediaKindFromMime,
mediaKindFromUrl,
toBulkAttachment,
@@ -39,6 +42,33 @@ test('no file and a blank URL means no attachment', () => {
assert.equal(toBulkAttachment('image', null, ' '), null);
});
+test('only http and https URLs count as media URLs', () => {
+ assert.equal(isHttpMediaUrl('https://cdn.example.com/a.pdf'), true);
+ assert.equal(isHttpMediaUrl(' HTTP://cdn.example.com/a.pdf '), true);
+ assert.equal(isHttpMediaUrl('cdn.example.com/pricelist.pdf'), false);
+ assert.equal(isHttpMediaUrl('file:///etc/passwd'), false);
+ assert.equal(isHttpMediaUrl('data:application/pdf;base64,QUJD'), false);
+ assert.equal(isHttpMediaUrl('ftp://cdn.example.com/a.pdf'), false);
+});
+
+test('a URL that is not http(s) gives no attachment', () => {
+ assert.equal(toBulkAttachment('document', null, 'cdn.example.com/pricelist.pdf'), null);
+ assert.equal(toBulkAttachment('document', null, 'data:application/pdf;base64,QUJD'), null);
+});
+
+test('the per-file budget shrinks with the recipient count', () => {
+ assert.equal(inlineMediaBudgetBytes(1), 18 * 1024 * 1024);
+ assert.equal(formatFileSize(inlineMediaBudgetBytes(1)), '18 MB');
+ assert.equal(formatFileSize(inlineMediaBudgetBytes(50)), '368 KB');
+ assert.equal(formatFileSize(inlineMediaBudgetBytes(100)), '184 KB');
+ assert.equal(inlineMediaBudgetBytes(0), inlineMediaBudgetBytes(1));
+});
+
+test('formats sizes in KB below a megabyte and MB above', () => {
+ assert.equal(formatFileSize(512), '1 KB');
+ assert.equal(formatFileSize(1536 * 1024), '1.5 MB');
+});
+
test('a picked file is sent inline and wins over a URL', () => {
assert.deepEqual(toBulkAttachment('image', { ...file, mimetype: 'image/png' }, 'https://x.test/a.png'), {
kind: 'image',
diff --git a/dashboard/src/utils/bulkMedia.ts b/dashboard/src/utils/bulkMedia.ts
index 3914f05dd..4bfeb4402 100644
--- a/dashboard/src/utils/bulkMedia.ts
+++ b/dashboard/src/utils/bulkMedia.ts
@@ -4,6 +4,12 @@ export type BulkMediaKind = 'image' | 'video' | 'audio' | 'document';
export const BULK_MEDIA_KINDS: readonly BulkMediaKind[] = ['image', 'video', 'audio', 'document'];
+// Total base64 across all items: the default 25 MB BODY_SIZE_LIMIT minus room for the JSON envelope.
+// A gateway running with a lower BODY_SIZE_LIMIT rejects smaller requests, which the dashboard can't know.
+export const BULK_INLINE_MEDIA_MAX_BYTES = 24 * 1024 * 1024;
+
+export const BULK_CAPTION_MAX_LENGTH = 1024;
+
export interface BulkAttachment {
kind: BulkMediaKind;
media: BulkMediaPayload;
@@ -28,6 +34,24 @@ const KIND_BY_EXTENSION: Record<string, BulkMediaKind> = {
wav: 'audio',
};
+export function isHttpMediaUrl(url: string): boolean {
+ try {
+ const { protocol } = new URL(url.trim());
+ return protocol === 'http:' || protocol === 'https:';
+ } catch {
+ return false;
+ }
+}
+
+export function inlineMediaBudgetBytes(recipientCount: number): number {
+ return Math.floor((BULK_INLINE_MEDIA_MAX_BYTES / Math.max(recipientCount, 1)) * 0.75);
+}
+
+export function formatFileSize(bytes: number): string {
+ if (bytes >= 1024 * 1024) return `${Number((bytes / (1024 * 1024)).toFixed(1))} MB`;
+ return `${Math.max(1, Math.floor(bytes / 1024))} KB`;
+}
+
export function mediaKindFromMime(mimetype: string): BulkMediaKind {
const category = mimetype.split('/')[0]?.toLowerCase();
return category === 'image' || category === 'video' || category === 'audio' ? category : 'document';
@@ -60,7 +84,7 @@ export function toBulkAttachment(
url: string,
): BulkAttachment | null {
const trimmedUrl = url.trim();
- if (!file && !trimmedUrl) return null;
+ if (!file && !isHttpMediaUrl(trimmedUrl)) return null;
const media: BulkMediaPayload = file ? { base64: file.base64, mimetype: file.mimetype } : { url: trimmedUrl };
if (kind === 'document') {
const filename = file ? file.filename : filenameFromUrl(trimmedUrl);