Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): match numbers only for queries that read as one

Yudhi Armyndharis1dd28ecd0a16
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 73a7641ac..86404c770 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Key Baileys chat writes and read receipts to the gateway's newest stored message when the session holds none in memory (#1891). Thanks @rjsebening.
- Group dashboard phone numbers in threes and fours, so `+49 157 333 4 4455` now reads `+49 157 3334 4455`; 10-digit numbers keep their shape (#1940).
- Make the deleted-message and omitted-media labels in outgoing dashboard chat bubbles readable in dark mode.
+- Match the dashboard New chat search against contact numbers only when the query reads as a phone number, so a name with a digit no longer lists every contact whose number holds that digit.
## [0.26.0] - 2026-10-28
diff --git a/dashboard/src/components/chats/NewChatPanel.tsx b/dashboard/src/components/chats/NewChatPanel.tsx
index c355ad56c..40be1e130 100644
--- a/dashboard/src/components/chats/NewChatPanel.tsx
+++ b/dashboard/src/components/chats/NewChatPanel.tsx
@@ -7,7 +7,7 @@ import { formatPhoneForDisplay, isolateNumber } from '../../utils/formatPhone';
import { useRole } from '../../hooks/useRole';
import { useToast } from '../../hooks/useToast';
import ChatAvatar from './ChatAvatar';
-import { normalizePhoneText } from '../../utils/phone';
+import { normalizePhoneText, phoneQueryDigits } from '../../utils/phone';
type Mode = 'chat' | 'group';
@@ -118,7 +118,7 @@ function NewChatPanel({ sessionId, onOpenChat, findListedChat, onClose }: NewCha
}, [contactsQuery.data]);
const normalizedQuery = query.trim().toLowerCase();
- const queryDigits = normalizePhoneText(query).replace(/\D/g, '');
+ const queryDigits = phoneQueryDigits(query);
const visibleContacts = normalizedQuery
? contacts.filter(
c =>
diff --git a/dashboard/src/components/chats/SessionPicker.tsx b/dashboard/src/components/chats/SessionPicker.tsx
index cc36380a0..dfac2142f 100644
--- a/dashboard/src/components/chats/SessionPicker.tsx
+++ b/dashboard/src/components/chats/SessionPicker.tsx
@@ -6,6 +6,7 @@ import type { Session } from '../../services/api';
import { useProfilePicture } from '../../hooks/useProfilePicture';
import { formatPhoneForDisplay } from '../../utils/formatPhone';
import { flagOfRegion, regionOfPhone } from '../../utils/phoneCountry';
+import { phoneQueryDigits } from '../../utils/phone';
interface SessionPickerProps {
/** Every session the gateway lists; only a ready one can be picked. */
@@ -110,7 +111,7 @@ function SessionPicker({ sessions, selectedSessionId, onSelectSession, canAddSes
const selected = sessions.find(s => s.id === selectedSessionId);
const needle = query.trim().toLowerCase();
- const digits = query.replace(/\D/g, '');
+ const digits = phoneQueryDigits(query);
const shown = needle
? sessions.filter(
s =>
diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.ts
index 809776730..4a36c955c 100644
--- a/dashboard/src/pages/Chats.features.test.ts
+++ b/dashboard/src/pages/Chats.features.test.ts
@@ -608,6 +608,23 @@ test('a contact the engine lists twice under one id is offered once, and found b
assert.equal(screen.getAllByRole('button', { name: /Bob/ }).length, 1, 'Bob was not found by his phone number');
});
+test('the New chat search matches a number only for a query that reads as one', async () => {
+ const { screen, fireEvent } = rtl;
+ renderPage();
+ await screen.findByText('Alice');
+ fireEvent.click(screen.getByRole('button', { name: 'New chat' }));
+ await screen.findByRole('button', { name: /Bob/ });
+ const search = screen.getByLabelText('Search name or number with country code');
+
+ // Bob's number holds a 2, which is no part of the name searched for.
+ fireEvent.change(search, { target: { value: 'Alice 2' } });
+ assert.equal(screen.queryAllByRole('button', { name: /Bob/ }).length, 0, 'a digit in a name matched a number');
+ assert.ok(screen.getByText('No contacts found'));
+ fireEvent.change(search, { target: { value: '+1 555-000.2222' } });
+ assert.equal(screen.getAllByRole('button', { name: /Bob/ }).length, 1, 'Bob was not found by his number');
+ assert.ok(screen.getByRole('button', { name: /^Start chat with/ }), 'the typed number is not offered');
+});
+
for (const reactStrictMode of [false, true]) {
test(`a typed number is checked with the gateway and opens a chat under the id it resolves to${reactStrictMode ? ' (StrictMode)' : ''}`, async () => {
const { screen, fireEvent, waitFor, within } = rtl;
@@ -979,6 +996,25 @@ test('the session switcher lists every session with its state, and only a connec
assert.equal(screen.getAllByRole('option').length, 1, 'the search did not narrow the list');
});
+test('the session switcher matches a number only for a query that reads as one, and a name with a digit by name', async () => {
+ const { screen, fireEvent, waitFor } = rtl;
+ listSecond = true;
+ listOffline = true;
+ listCreated = { ...CREATED_SESSION, name: 'Support 2' };
+ const { container } = renderPage();
+ await screen.findByText('Alice');
+ fireEvent.click(container.querySelector('.session-switcher-btn') as HTMLElement);
+ const search = screen.getByLabelText('Search sessions...');
+ const shown = () => screen.queryAllByRole('option').map(option => option.querySelector('.session-name')?.textContent);
+ await waitFor(() => assert.equal(shown().length, 4));
+
+ // Main and Marie Haas have a 2 in their number, which is no part of the name searched for.
+ fireEvent.change(search, { target: { value: 'Support 2' } });
+ assert.deepEqual(shown(), ['Support 2']);
+ fireEvent.change(search, { target: { value: '+1 (555) 987-65' } });
+ assert.deepEqual(shown(), [SECOND_SESSION.name]);
+});
+
test('the session switcher follows live session status: a session that connects can be picked, one that drops cannot', async () => {
const { screen, fireEvent, act } = rtl;
listOffline = true;
diff --git a/dashboard/src/utils/phone.test.ts b/dashboard/src/utils/phone.test.ts
index f700c7de8..60f67de64 100644
--- a/dashboard/src/utils/phone.test.ts
+++ b/dashboard/src/utils/phone.test.ts
@@ -1,6 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { normalizePhoneText } from './phone.ts';
+import { normalizePhoneText, phoneQueryDigits } from './phone.ts';
const char = (code: number) => String.fromCharCode(code);
const digitsOf = (zero: number) => [...'0123456789'].map(d => char(zero + Number(d))).join('');
@@ -56,3 +56,9 @@ test('the Mathematical digit sets read as ASCII digits', () => {
assert.equal(normalizePhoneText(digits), '0123456789');
}
});
+
+test('a query gives digits to match numbers with only when it reads as a phone number', () => {
+ assert.equal(phoneQueryDigits(' +62 (812) 345-67.89 '), '628123456789');
+ assert.equal(phoneQueryDigits(`${char(0xff0b)}${digitsOf(0x0660).slice(1, 4)}`), '123');
+ for (const query of ['Shop 2', 'Team-2', '2nd floor', 'a+1', '']) assert.equal(phoneQueryDigits(query), '', query);
+});
diff --git a/dashboard/src/utils/phone.ts b/dashboard/src/utils/phone.ts
index 403fc01fb..ca7b05ba3 100644
--- a/dashboard/src/utils/phone.ts
+++ b/dashboard/src/utils/phone.ts
@@ -19,3 +19,11 @@ export function normalizePhoneText(text: string): string {
.replace(/\p{Cf}/gu, '')
.replace(/(?![0-9])\p{Nd}/gu, asciiDigit);
}
+
+// The digits of a search query that reads as a phone number: digits, with the spaces, plus sign, parentheses, hyphens
+// and dots a number is written with. Any other query gives none, so it matches names only: "Shop 2" names something,
+// and its 2 is no reason to list every number that holds one.
+export function phoneQueryDigits(query: string): string {
+ const text = normalizePhoneText(query).trim();
+ return /^[\d\s+().-]+$/.test(text) ? text.replace(/\D/g, '') : '';
+}