[PR #6108] [CLOSED] feat(notifications): add webhook subscriber for event bus #6081

Closed
opened 2026-11-02 04:06:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6108
Author: @lordfre
Created: 7/26/2026
Status: ❌ Closed

Base: main ← Head: main


📝 Commits (1)

  • 757ce36 feat(notifications): add webhook subscriber for event bus

📊 Changes

22 files changed (+1390 additions, -18 deletions)

View changed files

📝 frontend/public/openapi.json (+120 -2)
➕ frontend/src/components/ui/notifications/WebhookNotifications.stories.tsx (+85 -0)
➕ frontend/src/components/ui/notifications/WebhookNotifications.tsx (+112 -0)
📝 frontend/src/generated/examples.ts (+15 -2)
📝 frontend/src/generated/schemas.ts (+62 -2)
📝 frontend/src/generated/types.ts (+13 -0)
📝 frontend/src/generated/zod.ts (+13 -0)
📝 frontend/src/layouts/AppSidebar.tsx (+1 -0)
📝 frontend/src/models/setting.ts (+13 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+7 -0)
📝 frontend/src/pages/settings/SettingsPage.tsx (+3 -1)
➕ frontend/src/pages/settings/WebhookTab.tsx (+122 -0)
📝 internal/web/controller/setting.go (+41 -7)
📝 internal/web/entity/entity.go (+8 -0)
📝 internal/web/service/setting.go (+79 -4)
➕ internal/web/service/webhook/subscriber.go (+57 -0)
➕ internal/web/service/webhook/subscriber_test.go (+102 -0)
➕ internal/web/service/webhook/webhook.go (+153 -0)
➕ internal/web/service/webhook/webhook_test.go (+321 -0)
📝 internal/web/translation/en-US.json (+22 -0)

...and 2 more files

📄 Description

Summary

Adds a generic HTTP webhook notification channel to the event bus, alongside the existing Telegram and SMTP subscribers. Panel events (outbound/node health, Xray crashes, CPU/RAM thresholds, login attempts) can now be delivered as a signed JSON POST to any user-configured URL.

Why

Telegram is blocked or unreliable in some regions/networks, and not every operator wants email. A generic webhook lets events be routed into whatever the operator already uses — Discord/Slack via a relay, n8n, a custom endpoint, etc. — without depending on Telegram connectivity.

Closes #5727

Type of change

  • New feature

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)

How was this tested?

Backend

  • Added internal/web/service/webhook/webhook_test.go and subscriber_test.go: payload shape, HMAC-SHA256 signing (present/absent based on configured secret), non-2xx response handling, missing-URL error path, CPU/Memory threshold gating (above/below/disabled), and TestConnection() success/failure — all against an httptest.Server recording requests.
  • Added internal/web/controller/setting_webhook_test.go: POST /panel/api/setting/testWebhook success and downstream-failure cases via httptest + a fresh sqlite DB per test.
  • Reused the existing eventbus.RateLimiter (per event-type + source, 1-minute cooldown, login.attempt bypasses it) — covered by subscriber tests (rate-limited, per-source independence, login bypass).
  • Manual: enabled webhook in Settings → pointed it at a local webhook.site/ncat -l listener → confirmed POST body, X-Webhook-Event header, and X-Webhook-Signature header (when secret set) → toggled individual event checkboxes and confirmed only enabled events fire → verified secret-clear checkbox actually removes the stored secret after Save.

Frontend

  • Added WebhookNotifications.stories.tsx (Storybook) mirroring EmailNotifications.stories.tsx — event group selection states (nothing/thresholds/infra/all).
  • Manual: Settings → Webhook tab — enable/URL/secret fields, "Generate" secret button, "Send Test Webhook" button (success + failure states), event-notification checkboxes, save/reset button state.
  • npm run build passes with the new AllSetting fields (webhookEnable, webhookURL, webhookSecret, hasWebhookSecret, clearWebhookSecret, webhookEnabledEvents, webhookCpu, webhookMemory).

Screenshots / recordings

image image

Breaking changes

None. Webhook is disabled by default (webhookEnable: false); existing installs are unaffected until an operator opts in.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6108 **Author:** [@lordfre](https://github.com/lordfre) **Created:** 7/26/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (1) - [`757ce36`](https://github.com/MHSanaei/3x-ui/commit/757ce365fc7ea2c8128fecbd4792d137256e4900) feat(notifications): add webhook subscriber for event bus ### 📊 Changes **22 files changed** (+1390 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+120 -2) ➕ `frontend/src/components/ui/notifications/WebhookNotifications.stories.tsx` (+85 -0) ➕ `frontend/src/components/ui/notifications/WebhookNotifications.tsx` (+112 -0) 📝 `frontend/src/generated/examples.ts` (+15 -2) 📝 `frontend/src/generated/schemas.ts` (+62 -2) 📝 `frontend/src/generated/types.ts` (+13 -0) 📝 `frontend/src/generated/zod.ts` (+13 -0) 📝 `frontend/src/layouts/AppSidebar.tsx` (+1 -0) 📝 `frontend/src/models/setting.ts` (+13 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+7 -0) 📝 `frontend/src/pages/settings/SettingsPage.tsx` (+3 -1) ➕ `frontend/src/pages/settings/WebhookTab.tsx` (+122 -0) 📝 `internal/web/controller/setting.go` (+41 -7) 📝 `internal/web/entity/entity.go` (+8 -0) 📝 `internal/web/service/setting.go` (+79 -4) ➕ `internal/web/service/webhook/subscriber.go` (+57 -0) ➕ `internal/web/service/webhook/subscriber_test.go` (+102 -0) ➕ `internal/web/service/webhook/webhook.go` (+153 -0) ➕ `internal/web/service/webhook/webhook_test.go` (+321 -0) 📝 `internal/web/translation/en-US.json` (+22 -0) _...and 2 more files_ </details> ### 📄 Description ## Summary Adds a generic HTTP webhook notification channel to the event bus, alongside the existing Telegram and SMTP subscribers. Panel events (outbound/node health, Xray crashes, CPU/RAM thresholds, login attempts) can now be delivered as a signed JSON POST to any user-configured URL. ## Why Telegram is blocked or unreliable in some regions/networks, and not every operator wants email. A generic webhook lets events be routed into whatever the operator already uses — Discord/Slack via a relay, n8n, a custom endpoint, etc. — without depending on Telegram connectivity. Closes #5727 ## Type of change - [x] New feature ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) ## How was this tested? **Backend** - Added `internal/web/service/webhook/webhook_test.go` and `subscriber_test.go`: payload shape, HMAC-SHA256 signing (present/absent based on configured secret), non-2xx response handling, missing-URL error path, CPU/Memory threshold gating (above/below/disabled), and `TestConnection()` success/failure — all against an `httptest.Server` recording requests. - Added `internal/web/controller/setting_webhook_test.go`: `POST /panel/api/setting/testWebhook` success and downstream-failure cases via `httptest` + a fresh sqlite DB per test. - Reused the existing `eventbus.RateLimiter` (per event-type + source, 1-minute cooldown, `login.attempt` bypasses it) — covered by subscriber tests (rate-limited, per-source independence, login bypass). - Manual: enabled webhook in Settings → pointed it at a local `webhook.site`/`ncat -l` listener → confirmed POST body, `X-Webhook-Event` header, and `X-Webhook-Signature` header (when secret set) → toggled individual event checkboxes and confirmed only enabled events fire → verified secret-clear checkbox actually removes the stored secret after Save. **Frontend** - Added `WebhookNotifications.stories.tsx` (Storybook) mirroring `EmailNotifications.stories.tsx` — event group selection states (nothing/thresholds/infra/all). - Manual: Settings → Webhook tab — enable/URL/secret fields, "Generate" secret button, "Send Test Webhook" button (success + failure states), event-notification checkboxes, save/reset button state. - `npm run build` passes with the new `AllSetting` fields (`webhookEnable`, `webhookURL`, `webhookSecret`, `hasWebhookSecret`, `clearWebhookSecret`, `webhookEnabledEvents`, `webhookCpu`, `webhookMemory`). ## Screenshots / recordings <!-- TODO: attach screenshots of the new Webhook settings tab (enable/URL/secret fields) and the event-notifications checkbox grid before opening the PR. --> <img width="1682" height="397" alt="image" src="https://github.com/user-attachments/assets/288b9800-aa94-4e1d-b316-347cd4d7fbe8" /> <img width="1682" height="507" alt="image" src="https://github.com/user-attachments/assets/c6480474-ec78-4632-ba7b-d7191bc85655" /> ## Breaking changes None. Webhook is disabled by default (`webhookEnable: false`); existing installs are unaffected until an operator opts in. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:14 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6081
No description provided.