Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): block webhook saves with no events or URL

Yudhi Armyndharis47d1e0ed563d
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index cac365433..0f24c9de3 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -467,6 +467,7 @@
"selectSession": "اختر جلسة...",
"session": "الجلسة",
"events": "الأحداث",
+ "noEvents": "اختر حدثًا واحدًا على الأقل.",
"available": "الأحداث المتاحة",
"saveChanges": "حفظ التغييرات",
"filters": {
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index 44cd7924b..8df63c045 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -446,6 +446,7 @@
"selectSession": "Sitzung auswählen...",
"session": "Sitzung",
"events": "Ereignisse",
+ "noEvents": "Wähle mindestens ein Ereignis aus.",
"available": "Verfügbare Ereignisse",
"saveChanges": "Änderungen speichern",
"filters": {
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index 0ca5dc75c..29f21e5ec 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -446,6 +446,7 @@
"selectSession": "Select session...",
"session": "Session",
"events": "Events",
+ "noEvents": "Select at least one event.",
"available": "Available Events",
"saveChanges": "Save Changes",
"filters": {
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index d5a1cba6b..6acbc8ec2 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -451,6 +451,7 @@
"selectSession": "Seleccionar sesión...",
"session": "Sesión",
"events": "Eventos",
+ "noEvents": "Selecciona al menos un evento.",
"available": "Eventos disponibles",
"saveChanges": "Guardar cambios",
"filters": {
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index 4dd692621..ef5a714d6 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -451,6 +451,7 @@
"selectSession": "Sélectionner une session...",
"session": "Session",
"events": "Événements",
+ "noEvents": "Sélectionnez au moins un événement.",
"available": "Événements disponibles",
"saveChanges": "Enregistrer les modifications",
"filters": {
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 929df282c..34e1002e8 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -452,6 +452,7 @@
"selectSession": "בחירת Session...",
"session": "Session",
"events": "אירועים",
+ "noEvents": "בחרו לפחות אירוע אחד.",
"available": "אירועים זמינים",
"saveChanges": "שמירת שינויים",
"filters": {
diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.json
index b72d67010..e895fdc5c 100644
--- a/dashboard/src/i18n/locales/hi.json
+++ b/dashboard/src/i18n/locales/hi.json
@@ -446,6 +446,7 @@
"selectSession": "सत्र चुनें...",
"session": "सत्र",
"events": "घटनाएँ",
+ "noEvents": "कम से कम एक घटना चुनें।",
"available": "उपलब्ध घटनाएँ",
"saveChanges": "परिवर्तन सहेजें",
"filters": {
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index 8f0023d57..49e3bc30a 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -451,6 +451,7 @@
"selectSession": "Seleziona sessione...",
"session": "Sessione",
"events": "Eventi",
+ "noEvents": "Seleziona almeno un evento.",
"available": "Eventi Disponibili",
"saveChanges": "Salva Modifiche",
"filters": {
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index b50a43e21..c436543d7 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -446,6 +446,7 @@
"selectSession": "세션 선택...",
"session": "세션",
"events": "이벤트",
+ "noEvents": "이벤트를 하나 이상 선택하세요.",
"available": "사용 가능한 이벤트",
"saveChanges": "변경 사항 저장",
"filters": {
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 24704dfc6..2135b6242 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -451,6 +451,7 @@
"selectSession": "Selecionar sessão...",
"session": "Sessão",
"events": "Eventos",
+ "noEvents": "Selecione pelo menos um evento.",
"available": "Eventos disponíveis",
"saveChanges": "Salvar alterações",
"filters": {
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index 159e360c8..0ed9e3aa1 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -446,6 +446,7 @@
"selectSession": "సెషన్‌ను ఎంచుకోండి...",
"session": "సెషన్",
"events": "ఈవెంట్స్",
+ "noEvents": "కనీసం ఒక ఈవెంట్‌ను ఎంచుకోండి.",
"available": "అందుబాటులో ఉన్న ఈవెంట్స్",
"saveChanges": "మార్పులను సేవ్ చేయి",
"filters": {
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index d789ab72d..0391a6622 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -446,6 +446,7 @@
"selectSession": "Oturum seçin...",
"session": "Oturum",
"events": "Olaylar",
+ "noEvents": "En az bir olay seçin.",
"available": "Kullanılabilir Olaylar",
"saveChanges": "Değişiklikleri Kaydet",
"filters": {
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index c2a2ab616..3a9969665 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -446,6 +446,7 @@
"selectSession": "选择会话...",
"session": "会话",
"events": "事件",
+ "noEvents": "请至少选择一个事件。",
"available": "可用事件",
"saveChanges": "保存更改",
"filters": {
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index 567d485f8..1a5286755 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -446,6 +446,7 @@
"selectSession": "選擇工作階段...",
"session": "工作階段",
"events": "事件",
+ "noEvents": "請至少選擇一個事件。",
"available": "可用事件",
"saveChanges": "儲存變更",
"filters": {
diff --git a/dashboard/src/pages/Webhooks.css b/dashboard/src/pages/Webhooks.css
index 820ec13f2..86088166b 100644
--- a/dashboard/src/pages/Webhooks.css
+++ b/dashboard/src/pages/Webhooks.css
@@ -18,6 +18,17 @@
margin-bottom: 0.75rem;
}
+.webhooks-page .modal-body > .hint {
+ display: block;
+ font-size: 0.75rem;
+ color: var(--text-muted);
+ margin: -0.375rem 0 0.75rem;
+}
+
+.webhooks-page .modal-body > .hint.error {
+ color: var(--error-text);
+}
+
.webhooks-page .modal-body > .event-tags {
display: flex;
flex-wrap: wrap;
diff --git a/dashboard/src/pages/Webhooks.test.ts b/dashboard/src/pages/Webhooks.test.ts
index d5c70d004..aa4a9029c 100644
--- a/dashboard/src/pages/Webhooks.test.ts
+++ b/dashboard/src/pages/Webhooks.test.ts
@@ -11,6 +11,7 @@ let webhooksStatus = 200;
let webhookList: unknown[] = [];
let sessionList: unknown[] = [];
let createCalls = 0;
+let updateCalls = 0;
function jsonResponse(data: unknown, status = 200): Response {
return new Response(JSON.stringify(data), { status, headers: { 'Content-Type': 'application/json' } });
@@ -26,6 +27,10 @@ function installFetchStub(): void {
createCalls++;
return new Promise<Response>(() => {});
}
+ if (init?.method === 'PUT' && path === '/api/sessions/sess-1/webhooks/w1') {
+ updateCalls++;
+ return new Promise<Response>(() => {});
+ }
if (path === '/api/webhooks') {
if (webhooksStatus === 403) {
return Promise.resolve(jsonResponse({ message: 'Insufficient permissions. Required: operator' }, 403));
@@ -63,6 +68,7 @@ afterEach(() => {
webhookList = [];
sessionList = [];
createCalls = 0;
+ updateCalls = 0;
window.sessionStorage.setItem('openwa_user_role', 'viewer');
});
@@ -187,3 +193,75 @@ test('Create stays disabled until both a session and a URL are filled in', async
fireEvent.change(screen.getByLabelText('URL'), { target: { value: '' } });
assert.equal(create.disabled, true, 'session without a URL');
});
+
+test('Create stays disabled with a hint while no event is selected', async () => {
+ const { screen, fireEvent } = rtl;
+ webhooksStatus = 200;
+ sessionList = [{ id: 'sess-1', name: 'Main', status: 'ready', createdAt: '2026-01-01T00:00:00.000Z' }];
+ window.sessionStorage.setItem('openwa_user_role', 'operator');
+ renderWebhooks();
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Add Webhook' }));
+ const sessionSelect = screen.getByLabelText<HTMLSelectElement>('Session');
+ await rtl.findByText(sessionSelect, 'Main');
+ fireEvent.change(sessionSelect, { target: { value: 'sess-1' } });
+ fireEvent.change(screen.getByLabelText('URL'), { target: { value: 'https://example.test/hook' } });
+ const create = screen.getByRole<HTMLButtonElement>('button', { name: 'Create' });
+ assert.equal(create.disabled, false);
+ assert.equal(screen.queryByText('Select at least one event.'), null);
+
+ fireEvent.click(screen.getByRole('button', { name: 'message.received' }));
+ assert.equal(create.disabled, true, 'no event selected');
+ screen.getByText('Select at least one event.');
+ fireEvent.click(create);
+ await new Promise(resolve => setTimeout(resolve, 50));
+ assert.equal(createCalls, 0);
+
+ fireEvent.click(screen.getByRole('button', { name: 'message.received' }));
+ assert.equal(create.disabled, false);
+});
+
+async function openEditModal(): Promise<HTMLButtonElement> {
+ webhooksStatus = 200;
+ webhookList = [
+ { id: 'w1', sessionId: 'sess-1', url: 'https://example.test/hook', events: ['message.received'], active: true },
+ ];
+ window.sessionStorage.setItem('openwa_user_role', 'operator');
+ renderWebhooks();
+ rtl.fireEvent.click(await rtl.screen.findByTitle('Edit'));
+ return rtl.screen.getByRole<HTMLButtonElement>('button', { name: 'Save Changes' });
+}
+
+test('Save stays disabled with a hint while no event is selected', async () => {
+ const { screen, fireEvent } = rtl;
+ const save = await openEditModal();
+ assert.equal(save.disabled, false);
+
+ fireEvent.click(screen.getByRole('button', { name: 'message.received' }));
+ assert.equal(save.disabled, true, 'no event selected');
+ screen.getByText('Select at least one event.');
+ fireEvent.click(save);
+ await new Promise(resolve => setTimeout(resolve, 50));
+ assert.equal(updateCalls, 0);
+});
+
+test('Save stays disabled while the URL is empty', async () => {
+ const { screen, fireEvent } = rtl;
+ const save = await openEditModal();
+ fireEvent.change(screen.getByLabelText('URL'), { target: { value: ' ' } });
+ assert.equal(save.disabled, true);
+ fireEvent.click(save);
+ await new Promise(resolve => setTimeout(resolve, 50));
+ assert.equal(updateCalls, 0);
+});
+
+test('a second click on Save while the first update is in flight sends nothing', async () => {
+ const { fireEvent, waitFor } = rtl;
+ const save = await openEditModal();
+ fireEvent.click(save);
+ await waitFor(() => assert.equal(updateCalls, 1));
+ await new Promise(resolve => setTimeout(resolve, 50));
+ fireEvent.click(save);
+ await new Promise(resolve => setTimeout(resolve, 50));
+ assert.equal(updateCalls, 1);
+});
diff --git a/dashboard/src/pages/Webhooks.tsx b/dashboard/src/pages/Webhooks.tsx
index a71ebdfaa..7bc246cec 100644
--- a/dashboard/src/pages/Webhooks.tsx
+++ b/dashboard/src/pages/Webhooks.tsx
@@ -121,9 +121,16 @@ export function Webhooks() {
return t(`webhooks.eventDescriptions.${name}`, { defaultValue: name });
};
+ // The gateway requires a URL and at least one event, so the buttons stay disabled until both are set
+ // instead of surfacing the raw validation message in a toast.
+ const canCreate =
+ !createMutation.isPending && !!newWebhook.url.trim() && !!newWebhook.sessionId && newWebhook.events.length > 0;
+ const canSave =
+ !!editWebhook && !updateMutation.isPending && !!editWebhook.url.trim() && editWebhook.events.length > 0;
+
const handleCreate = async () => {
// The gateway saves every create it receives, so a double click would register the webhook twice.
- if (createMutation.isPending || !newWebhook.url || !newWebhook.sessionId) return;
+ if (!canCreate) return;
try {
await createMutation.mutateAsync({
sessionId: newWebhook.sessionId,
@@ -191,7 +198,7 @@ export function Webhooks() {
};
const handleEdit = async () => {
- if (!editWebhook) return;
+ if (!editWebhook || !canSave) return;
try {
await updateMutation.mutateAsync({
sessionId: editWebhook.sessionId,
@@ -279,11 +286,7 @@ export function Webhooks() {
<button className="btn-secondary" onClick={() => setShowCreateModal(false)}>
{t('common.cancel')}
</button>
- <button
- className="btn-primary"
- onClick={handleCreate}
- disabled={createMutation.isPending || !newWebhook.url || !newWebhook.sessionId}
- >
+ <button className="btn-primary" onClick={handleCreate} disabled={!canCreate}>
{t('common.create')}
</button>
</>
@@ -327,6 +330,11 @@ export function Webhooks() {
);
})}
</div>
+ {newWebhook.events.length === 0 && (
+ <span className="hint error" role="status">
+ {t('webhooks.noEvents')}
+ </span>
+ )}
{supportsFilters(newWebhook.events) && (
<FilterBuilder
filters={newWebhook.filters}
@@ -348,7 +356,7 @@ export function Webhooks() {
<button className="btn-secondary" onClick={() => setShowEditModal(false)}>
{t('common.cancel')}
</button>
- <button className="btn-primary" onClick={handleEdit}>
+ <button className="btn-primary" onClick={handleEdit} disabled={!canSave}>
{t('webhooks.saveChanges')}
</button>
</>
@@ -378,6 +386,11 @@ export function Webhooks() {
);
})}
</div>
+ {editWebhook.events.length === 0 && (
+ <span className="hint error" role="status">
+ {t('webhooks.noEvents')}
+ </span>
+ )}
{supportsFilters(editWebhook.events) && (
<FilterBuilder
filters={editWebhook.filters}