Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): refuse an empty group send and stop it on 409

Yudhi Armyndharis22f0572398d1
diff --git a/dashboard/src/pages/MessageTester.test.ts b/dashboard/src/pages/MessageTester.test.ts
index b8d29ab71..cdfde9fbb 100644
--- a/dashboard/src/pages/MessageTester.test.ts
+++ b/dashboard/src/pages/MessageTester.test.ts
@@ -237,6 +237,40 @@ test('a 429 from the gateway stops the run instead of trying the rest', async ()
assert.ok(rtl.screen.getByText('Failed'));
});
+test('a 409 (engine not ready) stops the run, since every group would fail alike', async () => {
+ const gateway = stubGroupGateway(
+ [
+ { id: '[email protected]', name: 'Family' },
+ { id: '[email protected]', name: 'Work' },
+ ],
+ 409,
+ );
+ await renderGroupsAsWriter();
+ await sendTextToAllGroups();
+
+ await rtl.screen.findByText('1, stopped after HTTP 409');
+ assert.deepEqual(gateway.textSends, ['[email protected]']);
+});
+
+test('an empty message or a media type with no file or URL keeps Send disabled', async () => {
+ stubGroupGateway([
+ { id: '[email protected]', name: 'Family' },
+ { id: '[email protected]', name: 'Work' },
+ ]);
+ await renderGroupsAsWriter();
+ await rtl.screen.findByRole('checkbox', { name: 'Work' });
+ rtl.fireEvent.click(rtl.screen.getByRole('button', { name: 'Select all' }));
+
+ const message = rtl.screen.getByPlaceholderText('Enter your message here...');
+ rtl.fireEvent.change(message, { target: { value: ' ' } });
+ assert.equal(sendMessageButton().disabled, true);
+ rtl.fireEvent.change(message, { target: { value: 'hi' } });
+ await rtl.waitFor(() => assert.equal(sendMessageButton().disabled, false));
+
+ rtl.fireEvent.click(rtl.screen.getByRole('button', { name: 'Image' }));
+ assert.equal(sendMessageButton().disabled, true);
+});
+
test('a recipients file over the cap is refused without being read', async () => {
const { container } = await pickRecipientsFile(maxBytes + 1);
diff --git a/dashboard/src/pages/MessageTester.tsx b/dashboard/src/pages/MessageTester.tsx
index 03efd800a..de4d28fe5 100644
--- a/dashboard/src/pages/MessageTester.tsx
+++ b/dashboard/src/pages/MessageTester.tsx
@@ -311,15 +311,17 @@ export function MessageTester() {
const bulkCaptionTooLong =
bulkAttachment !== null && bulkAttachment.kind !== 'audio' && captionLength(content) > 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).
+ // 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 === 'location') {
+ if (messageType === 'text') {
+ formValid = content.trim().length > 0;
+ } else if (isMediaMessageType) {
+ formValid = !!mediaFile || mediaUrl.trim().length > 0;
+ } else if (messageType === 'location') {
formValid = !Number.isNaN(lat) && !Number.isNaN(lng) && lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180;
} else if (messageType === 'contact') {
formValid = contactName.trim().length > 0 && contactNumber.trim().length > 0;
- } else if (messageType === 'sticker') {
- formValid = !!mediaFile || mediaUrl.trim().length > 0;
} else if (messageType === 'poll') {
formValid = pollQuestion.trim().length > 0 && pollOptionsFilled.length >= 2;
} else if (messageType === 'forward') {
diff --git a/dashboard/src/utils/groupSelection.test.ts b/dashboard/src/utils/groupSelection.test.ts
index 75b52c9d5..f6ebfc214 100644
--- a/dashboard/src/utils/groupSelection.test.ts
+++ b/dashboard/src/utils/groupSelection.test.ts
@@ -78,8 +78,9 @@ test('forward uses the first group as its source chat instead of looping', () =>
assert.deepEqual(planGroupSend(['[email protected]', '[email protected]'], 'forward'), { mode: 'single', chatId: '[email protected]' });
});
-test('429 and 503 are refusals that stop a run, other failures are not', () => {
+test('409, 429 and 503 are refusals that stop a run, other failures are not', () => {
const withStatus = (status: number) => Object.assign(new Error('refused'), { status });
+ assert.equal(isGatewayRefusal(withStatus(409)), true);
assert.equal(isGatewayRefusal(withStatus(429)), true);
assert.equal(isGatewayRefusal(withStatus(503)), true);
assert.equal(isGatewayRefusal(withStatus(404)), false);
diff --git a/dashboard/src/utils/groupSelection.ts b/dashboard/src/utils/groupSelection.ts
index 48e416bfc..c872a5d36 100644
--- a/dashboard/src/utils/groupSelection.ts
+++ b/dashboard/src/utils/groupSelection.ts
@@ -10,7 +10,8 @@ export interface GroupPickerRow {
export type GroupSendPlan = { mode: 'single'; chatId: string } | { mode: 'sequential'; chatIds: string[] };
-const GATEWAY_REFUSAL_STATUSES: readonly number[] = [429, 503];
+// 409 on a send route means the session's engine is not ready, which fails every group alike.
+const GATEWAY_REFUSAL_STATUSES: readonly number[] = [409, 429, 503];
export function groupLabel(group: SelectableGroup): string {
return group.name?.trim() || group.id;