Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): use one stop rule for bulk lookups and group sends
Yudhi Armyndharisb968e3fb56b0
diff --git a/dashboard/src/pages/NumberChecker.test.ts b/dashboard/src/pages/NumberChecker.test.tsindex d76f6a128..618483cc9 100644--- a/dashboard/src/pages/NumberChecker.test.ts+++ b/dashboard/src/pages/NumberChecker.test.ts@@ -947,6 +947,22 @@ test('NumberChecker: a lookup that gets no answer at all stops the batch beforeassert.equal(rtl.screen.queryByText(/Completed checking/), null);});+// Only a fetch that gets no answer ends the run. A 200 whose body cannot be read is that lookup's failure.+test('NumberChecker: an answer that is not JSON fails that number and the run goes on', async () => {+ const lookups = stubLookups(number =>+ number === '911111111111' ? new Response('<html>sign in</html>', { status: 200 }) : registered(number),+ );+ const { container } = renderComponent();+ const textarea = await openBulkTab();+ rtl.fireEvent.change(textarea, { target: { value: '911111111111\n912222222222' } });+ startBatch();++ await rtl.screen.findByText('Completed checking 2 numbers.', {}, { timeout: 3000 });+ assert.deepEqual(lookups, ['911111111111', '912222222222']);+ assert.equal(statValue('Failed'), '1');+ assert.equal(container.querySelector('.nc-batch-stopped'), null);+});+test('NumberChecker: a refusal on the last number says so instead of counting numbers left unsent', async () => {const lookups = stubLookups(number =>number === '912222222222' ? jsonResponse({ message: 'Rate limit exceeded (HTTP 429)' }, 429) : registered(number),diff --git a/dashboard/src/pages/NumberChecker.tsx b/dashboard/src/pages/NumberChecker.tsxindex 0325b4ad9..24f59f80f 100644--- a/dashboard/src/pages/NumberChecker.tsx+++ b/dashboard/src/pages/NumberChecker.tsx@@ -51,14 +51,6 @@ const STOP_REASON_KEYS: Record<number, string> = {503: 'numberChecker.stopped.reason503',};-// The status of a lookup that fails every number after it alike, or undefined when only that number failed.-// A rejected fetch carries no status: the gateway never answered.-function lookupStopStatus(err: unknown): number | undefined {- const status = (err as { status?: unknown } | null)?.status;- if (typeof status !== 'number') return 0;- return status === 400 || isGatewayRefusal(err) ? status : undefined;-}-// `attempted` counts the lookup that stopped the run, which is the last one sent; only the rest were never sent.function batchStopMessage(t: TFunction, { status, attempted, total }: BatchStop): string {if (status === 0) return t('numberChecker.stopped.noAnswer', { attempted, total });@@ -332,9 +324,9 @@ export function NumberChecker() {// The gateway keeps refusing this route for the rest of its window, a stopped session or an unreachable// gateway fails every later number too, so each would only become a false "Failed" row (and spend more// of the limit).- const stopStatus = lookupStopStatus(err);- if (stopStatus !== undefined) {- refusedWith = stopStatus;+ if (isGatewayRefusal(err)) {+ // A rejected fetch carries no status: the gateway never answered.+ refusedWith = (err as { status?: number }).status ?? 0;setBatchProgress({ current: i + 1, total: numbers.length });break;}