Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): drop non-chat-id @ fields from bulk recipients
Yudhi Armyndharisd63878b9bba3
diff --git a/dashboard/src/utils/bulkRecipients.test.ts b/dashboard/src/utils/bulkRecipients.test.tsindex aa82be0b7..457141c41 100644--- a/dashboard/src/utils/bulkRecipients.test.ts+++ b/dashboard/src/utils/bulkRecipients.test.ts@@ -64,3 +64,14 @@ test('a number too short to be a phone is dropped rather than sent', () => {assert.deepEqual(parseBulkRecipients('12345'), []);assert.deepEqual(parseBulkRecipients('123456'), ['[email protected]']);});++// A contact export carries an email column next to the phone. Passing every '@' field through sent+// each address as a recipient that could only fail, and doubled the count held against the batch cap.+test('an @ field without a WhatsApp chat id shape is dropped, so an email column is not a recipient', () => {+ const csv = 'name,email,phone\nJohn,[email protected],628123456789\nAmy,[email protected],628987654321';+ assert.deepEqual(parseBulkRecipients(csv), ['[email protected]', '[email protected]']);+ assert.deepEqual(+ parseBulkRecipients('[email protected]\n120363123456789@newsletter\n628123456789:12@lid'),+ ['[email protected]', '120363123456789@newsletter', '628123456789:12@lid'],+ );+});diff --git a/dashboard/src/utils/bulkRecipients.ts b/dashboard/src/utils/bulkRecipients.tsindex 436e7ec93..562a809f6 100644--- a/dashboard/src/utils/bulkRecipients.ts+++ b/dashboard/src/utils/bulkRecipients.ts@@ -9,9 +9,10 @@ export const BULK_RECIPIENTS_FILE_MAX_BYTES = 2 * 1024 * 1024;/*** Parse the bulk-recipients textarea into chat IDs: trims whitespace, drops blanks, de-dupes, and- * normalizes bare phone numbers to `<digits>@c.us`. An entry containing '@' is treated as a full- * chat ID and passes through untouched; anything else must carry at least MIN_PHONE_DIGITS digits- * or it is dropped rather than sent as a meaningless or truncated id.+ * normalizes bare phone numbers to `<digits>@c.us`. An entry with a WhatsApp chat id shape passes+ * through untouched; any other entry containing '@', such as an email column, is dropped. Anything+ * else must carry at least MIN_PHONE_DIGITS digits or it is dropped rather than sent as a+ * meaningless or truncated id.** Entries are separated by line endings AND by the comma/semicolon/tab a spreadsheet export writes,* because the file picker offers `.csv`. Phone-number formatting (spaces, parentheses, hyphens,@@ -37,6 +38,13 @@ const FIELD_SEPARATORS = /[,;\t]/;*/const MIN_PHONE_DIGITS = 6;+/**+ * A full chat id: a numeric user part (a device suffix or group hyphen allowed) on a WhatsApp+ * server. The server list is what keeps an email out; a numeric local part alone would still let+ * `[email protected]` through.+ */+const CHAT_ID = /^[0-9][0-9:-]*@(c\.us|g\.us|s\.whatsapp\.net|lid|newsletter|broadcast)$/i;+export function parseBulkRecipients(text: string): string[] {const seen = new Set<string>();for (const rawLine of text.split(/\r\n?|\n/)) {@@ -48,7 +56,7 @@ export function parseBulkRecipients(text: string): string[] {const field = rawField.trim();if (!field) continue;if (field.includes('@')) {- seen.add(field);+ if (CHAT_ID.test(field)) seen.add(field);continue;}const digits = field.replace(/[^0-9]/g, '');