Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): stop the group send when every group would fail alike

Yudhi Armyndharisfc01980df8c5
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index b479677b8..4e812a1c9 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -996,6 +996,7 @@
"groupsSentSummary": "تم إرسال {{sent}}/{{total}}",
"groupSendCancelled": "{{count}}، أُلغيت",
"groupSendStopped": "{{count}}، توقف بعد HTTP {{status}}",
+ "groupSendStoppedNoAnswer": "{{count}}، توقف: لم تردّ البوابة",
"response": {
"timestamp": "الوقت",
"messageId": "معرّف الرسالة",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index 746c88b2b..27a74c210 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -971,6 +971,7 @@
"groupsSentSummary": "{{sent}}/{{total}} gesendet",
"groupSendCancelled": "{{count}}, abgebrochen",
"groupSendStopped": "{{count}}, gestoppt nach HTTP {{status}}",
+ "groupSendStoppedNoAnswer": "{{count}}, gestoppt: das Gateway hat nicht geantwortet",
"response": {
"timestamp": "Zeitstempel",
"messageId": "Nachrichten-ID",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index 5e2493d66..a955b8ed6 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -971,6 +971,7 @@
"groupsSentSummary": "{{sent}}/{{total}} sent",
"groupSendCancelled": "{{count}}, cancelled",
"groupSendStopped": "{{count}}, stopped after HTTP {{status}}",
+ "groupSendStoppedNoAnswer": "{{count}}, stopped: the gateway did not answer",
"response": {
"timestamp": "Timestamp",
"messageId": "Message ID",
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index d8effea14..ad6d106ea 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -927,6 +927,7 @@
"groupsSentSummary": "{{sent}}/{{total}} enviados",
"groupSendCancelled": "{{count}}, cancelados",
"groupSendStopped": "{{count}}, detenido tras HTTP {{status}}",
+ "groupSendStoppedNoAnswer": "{{count}}, detenido: la puerta de enlace no respondió",
"response": {
"timestamp": "Fecha/Hora",
"messageId": "ID de mensaje",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index 8ce8f5191..a1d454410 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -977,6 +977,7 @@
"groupsSentSummary": "{{sent}}/{{total}} envoyés",
"groupSendCancelled": "{{count}}, annulés",
"groupSendStopped": "{{count}}, arrêté après HTTP {{status}}",
+ "groupSendStoppedNoAnswer": "{{count}}, arrêté : la passerelle n'a pas répondu",
"response": {
"timestamp": "Horodatage",
"messageId": "ID du message",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 19c45df19..cae3b2c9b 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -984,6 +984,7 @@
"groupsSentSummary": "נשלחו {{sent}}/{{total}}",
"groupSendCancelled": "{{count}}, בוטלו",
"groupSendStopped": "{{count}}, נעצר אחרי HTTP {{status}}",
+ "groupSendStoppedNoAnswer": "{{count}}, נעצר: השער לא השיב",
"response": {
"timestamp": "חותמת זמן",
"messageId": "מזהה הודעה",
diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.json
index 62094a926..4f10559de 100644
--- a/dashboard/src/i18n/locales/hi.json
+++ b/dashboard/src/i18n/locales/hi.json
@@ -971,6 +971,7 @@
"groupsSentSummary": "{{sent}}/{{total}} भेजे गए",
"groupSendCancelled": "{{count}}, रद्द किए गए",
"groupSendStopped": "{{count}}, HTTP {{status}} के बाद रोक दिए गए",
+ "groupSendStoppedNoAnswer": "{{count}}, रोक दिए गए: गेटवे ने जवाब नहीं दिया",
"response": {
"timestamp": "समय",
"messageId": "संदेश ID",
diff --git a/dashboard/src/i18n/locales/id.json b/dashboard/src/i18n/locales/id.json
index 890ebca23..8e03bf133 100644
--- a/dashboard/src/i18n/locales/id.json
+++ b/dashboard/src/i18n/locales/id.json
@@ -971,6 +971,7 @@
"groupsSentSummary": "{{sent}}/{{total}} terkirim",
"groupSendCancelled": "{{count}}, dibatalkan",
"groupSendStopped": "{{count}}, dihentikan setelah HTTP {{status}}",
+ "groupSendStoppedNoAnswer": "{{count}}, dihentikan: gateway tidak merespons",
"response": {
"timestamp": "Waktu",
"messageId": "ID Pesan",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index 7f2607857..c74a0ec95 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -977,6 +977,7 @@
"groupsSentSummary": "{{sent}}/{{total}} inviati",
"groupSendCancelled": "{{count}}, annullati",
"groupSendStopped": "{{count}}, interrotto dopo HTTP {{status}}",
+ "groupSendStoppedNoAnswer": "{{count}}, interrotto: il gateway non ha risposto",
"response": {
"timestamp": "Timestamp",
"messageId": "ID Messaggio",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index 10f6b6a3d..ab3bd872f 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -971,6 +971,7 @@
"groupsSentSummary": "{{sent}}/{{total}}개 전송됨",
"groupSendCancelled": "{{count}}개, 취소됨",
"groupSendStopped": "{{count}}개, HTTP {{status}} 후 중지됨",
+ "groupSendStoppedNoAnswer": "{{count}}개, 중지됨: 게이트웨이가 응답하지 않았습니다",
"response": {
"timestamp": "타임스탬프",
"messageId": "메시지 ID",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 5ca93e78f..b0bb2966a 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -927,6 +927,7 @@
"groupsSentSummary": "{{sent}}/{{total}} enviados",
"groupSendCancelled": "{{count}}, cancelados",
"groupSendStopped": "{{count}}, interrompido após HTTP {{status}}",
+ "groupSendStoppedNoAnswer": "{{count}}, interrompido: o gateway não respondeu",
"response": {
"timestamp": "Data/Hora",
"messageId": "ID da mensagem",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index b0efacec6..215daabd8 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -971,6 +971,7 @@
"groupsSentSummary": "{{sent}}/{{total}} పంపబడ్డాయి",
"groupSendCancelled": "{{count}}, రద్దు చేయబడ్డాయి",
"groupSendStopped": "{{count}}, HTTP {{status}} తర్వాత ఆపబడింది",
+ "groupSendStoppedNoAnswer": "{{count}}, ఆపబడింది: గేట్‌వే స్పందించలేదు",
"response": {
"timestamp": "సమయము",
"messageId": "సందేశం ID",
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index 8a81778e4..c20d1b775 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -971,6 +971,7 @@
"groupsSentSummary": "{{sent}}/{{total}} gönderildi",
"groupSendCancelled": "{{count}}, iptal edildi",
"groupSendStopped": "{{count}}, HTTP {{status}} sonrası durduruldu",
+ "groupSendStoppedNoAnswer": "{{count}}, durduruldu: ağ geçidi yanıt vermedi",
"response": {
"timestamp": "Zaman Damgası",
"messageId": "Mesaj ID'si",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index 6b20a5a56..cb7121ceb 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -971,6 +971,7 @@
"groupsSentSummary": "已发送 {{sent}}/{{total}}",
"groupSendCancelled": "{{count}} 个,已取消",
"groupSendStopped": "{{count}} 个,在 HTTP {{status}} 后停止",
+ "groupSendStoppedNoAnswer": "{{count}} 个,已停止:网关未响应",
"response": {
"timestamp": "时间戳",
"messageId": "消息 ID",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index 6cea72c7b..6e6960e86 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -971,6 +971,7 @@
"groupsSentSummary": "已傳送 {{sent}}/{{total}}",
"groupSendCancelled": "{{count}} 個,已取消",
"groupSendStopped": "{{count}} 個,在 HTTP {{status}} 後停止",
+ "groupSendStoppedNoAnswer": "{{count}} 個,已停止:閘道沒有回應",
"response": {
"timestamp": "時間戳記",
"messageId": "訊息 ID",
diff --git a/dashboard/src/pages/MessageTester.test.ts b/dashboard/src/pages/MessageTester.test.ts
index e90fdc264..b5ee86e46 100644
--- a/dashboard/src/pages/MessageTester.test.ts
+++ b/dashboard/src/pages/MessageTester.test.ts
@@ -144,9 +144,12 @@ function groupJsonResponse(data: unknown, status = 200): Response {
return new Response(JSON.stringify(data), { status, headers: { 'Content-Type': 'application/json' } });
}
+// How the first text send fails: an HTTP status, a fetch that never gets an answer, or a 201 with no message id.
+type FirstSendFailure = number | 'unreachable' | 'unconfirmed';
+
function stubGroupGateway(
groups: { id: string; name?: string }[],
- refuseFirstWith?: number,
+ refuseFirstWith?: FirstSendFailure,
): { textSends: string[]; imageBodies: { chatId: string; url?: string; caption?: string }[] } {
const previousFetch = globalThis.fetch;
restoreFetch = () => {
@@ -168,7 +171,11 @@ function stubGroupGateway(
const { chatId } = JSON.parse(String(init?.body)) as { chatId: string };
textSends.push(chatId);
if (refuseFirstWith && textSends.length === 1) {
- return Promise.resolve(groupJsonResponse({ message: 'Too many requests' }, refuseFirstWith));
+ if (refuseFirstWith === 'unreachable') return Promise.reject(new TypeError('Failed to fetch'));
+ if (refuseFirstWith === 'unconfirmed') return Promise.resolve(groupJsonResponse({ timestamp: 1 }, 201));
+ const message =
+ refuseFirstWith === 400 ? "Session 's1' is not active. Start the session first." : 'Too many requests';
+ return Promise.resolve(groupJsonResponse({ message }, refuseFirstWith));
}
return Promise.resolve(groupJsonResponse({ messageId: `m${textSends.length}`, timestamp: 1 }, 201));
}
@@ -260,6 +267,56 @@ test('a 409 (engine not ready) stops the run, since every group would fail alike
assert.deepEqual(gateway.textSends, ['[email protected]']);
});
+test('a 400 (the session is not active) stops the run, since every group would fail alike', async () => {
+ const gateway = stubGroupGateway(
+ [
+ { id: '[email protected]', name: 'Family' },
+ { id: '[email protected]', name: 'Work' },
+ ],
+ 400,
+ );
+ await renderGroupsAsWriter();
+ await sendTextToAllGroups();
+
+ await rtl.screen.findByText('1, stopped after HTTP 400');
+ assert.ok(rtl.screen.getByText(/is not active/, { selector: 'li' }));
+ assert.deepEqual(gateway.textSends, ['[email protected]']);
+});
+
+test('a gateway that does not answer stops the run, and the notice says so', async () => {
+ const gateway = stubGroupGateway(
+ [
+ { id: '[email protected]', name: 'Family' },
+ { id: '[email protected]', name: 'Work' },
+ ],
+ 'unreachable',
+ );
+ await renderGroupsAsWriter();
+ await sendTextToAllGroups();
+
+ await rtl.screen.findByText('1, stopped: the gateway did not answer');
+ assert.deepEqual(gateway.textSends, ['[email protected]']);
+});
+
+// The page's own "no message id" failure has no HTTP status either, but the gateway did answer.
+test('a send answered without a message id fails that group and the run goes on', async () => {
+ const gateway = stubGroupGateway(
+ [
+ { id: '[email protected]', name: 'Family' },
+ { id: '[email protected]', name: 'Work' },
+ ],
+ 'unconfirmed',
+ );
+ await renderGroupsAsWriter();
+ await sendTextToAllGroups();
+
+ // The run waits 3 seconds between groups, so the second send comes after that.
+ await rtl.screen.findByText('1/2 sent', {}, { timeout: 8000 });
+ assert.deepEqual(gateway.textSends, ['[email protected]', '[email protected]']);
+ assert.ok(rtl.screen.getByText(/Failed to send message/, { selector: 'li' }));
+ assert.equal(rtl.screen.queryByText(/stopped/) === null, true);
+});
+
test('an empty message or a media type with no file or URL keeps Send disabled', async () => {
stubGroupGateway([
{ id: '[email protected]', name: 'Family' },
diff --git a/dashboard/src/pages/MessageTester.tsx b/dashboard/src/pages/MessageTester.tsx
index f7b2b025f..d421946bd 100644
--- a/dashboard/src/pages/MessageTester.tsx
+++ b/dashboard/src/pages/MessageTester.tsx
@@ -52,6 +52,7 @@ interface ApiResponse {
failures: { id: string; name: string; error: string }[];
notSent: number;
stoppedBy?: 'abort' | 'refusal';
+ // The status that stopped the run; absent when a fetch got no answer at all.
refusedWith?: number;
};
}
@@ -1284,10 +1285,12 @@ export function MessageTester() {
<span className="detail-label">{t('messageTester.response.notSent')}</span>
<span className="detail-value">
{response.groups.stoppedBy === 'refusal'
- ? t('messageTester.groupSendStopped', {
- count: response.groups.notSent,
- status: response.groups.refusedWith,
- })
+ ? response.groups.refusedWith === undefined
+ ? t('messageTester.groupSendStoppedNoAnswer', { count: response.groups.notSent })
+ : t('messageTester.groupSendStopped', {
+ count: response.groups.notSent,
+ status: response.groups.refusedWith,
+ })
: t('messageTester.groupSendCancelled', { count: response.groups.notSent })}
</span>
</div>
diff --git a/dashboard/src/utils/groupSelection.test.ts b/dashboard/src/utils/groupSelection.test.ts
index f6ebfc214..a19bf590f 100644
--- a/dashboard/src/utils/groupSelection.test.ts
+++ b/dashboard/src/utils/groupSelection.test.ts
@@ -78,12 +78,17 @@ 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('409, 429 and 503 are refusals that stop a run, other failures are not', () => {
+test('a stopped session, a refusal and a fetch with no answer end a run, other failures do not', () => {
const withStatus = (status: number) => Object.assign(new Error('refused'), { status });
+ assert.equal(isGatewayRefusal(withStatus(400)), true);
assert.equal(isGatewayRefusal(withStatus(409)), true);
assert.equal(isGatewayRefusal(withStatus(429)), true);
assert.equal(isGatewayRefusal(withStatus(503)), true);
+ assert.equal(isGatewayRefusal(new TypeError('Failed to fetch')), true);
assert.equal(isGatewayRefusal(withStatus(404)), false);
+ assert.equal(isGatewayRefusal(withStatus(500)), false);
+ // An error the page raised itself, or an unreadable answer, is not a fetch that got no answer.
assert.equal(isGatewayRefusal(new Error('offline')), false);
+ assert.equal(isGatewayRefusal(new SyntaxError('Unexpected token')), false);
assert.equal(isGatewayRefusal(null), false);
});
diff --git a/dashboard/src/utils/groupSelection.ts b/dashboard/src/utils/groupSelection.ts
index c872a5d36..96ab8aa6f 100644
--- a/dashboard/src/utils/groupSelection.ts
+++ b/dashboard/src/utils/groupSelection.ts
@@ -10,8 +10,9 @@ export interface GroupPickerRow {
export type GroupSendPlan = { mode: 'single'; chatId: string } | { mode: 'sequential'; chatIds: string[] };
-// 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];
+// Answers the next call of the same run gets too: 400 a session with no engine (the send and lookup routes answer it),
+// 409 an engine that is not ready, which fails every group alike, 429 the rate limit, 503 WhatsApp not answering.
+const GATEWAY_REFUSAL_STATUSES: readonly number[] = [400, 409, 429, 503];
export function groupLabel(group: SelectableGroup): string {
return group.name?.trim() || group.id;
@@ -52,7 +53,11 @@ export function planGroupSend(selectedIds: readonly string[], messageType: strin
return { mode: 'sequential', chatIds: [...selectedIds] };
}
+// A failure the rest of a run would meet too, so the run stops instead of recording one failure per remaining target:
+// one of the statuses above, or a fetch that got no answer at all (it rejects with a TypeError). An error the page
+// raised itself, or an answer it could not read, fails that call only.
export function isGatewayRefusal(err: unknown): boolean {
+ if (err instanceof TypeError) return true;
const status = (err as { status?: unknown } | null)?.status;
return typeof status === 'number' && GATEWAY_REFUSAL_STATUSES.includes(status);
}