[PR #6486] [MERGED] feat(discord): add Discord notification bot service #6300

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6486
Author: @poise52
Created: 9/12/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei

Base: main ← Head: feature/discord-bot


📝 Commits (10+)

  • 9811902 feat(discord): add Discord notification bot service, settings UI, and event subscriber
  • c364e16 fix(discord): address PR review findings on concurrency, linting, i18n, and stories
  • 7609741 docs: add Discord bot setup and operations guide
  • 3692a63 feat(discord): add discordLang, discordRunTime, discordBotBackup settings and update settings UI
  • 230031e feat(discord): implement scheduled status reports and database backup attachments
  • 52dbefc feat(discord): add interactive bot commands via Gateway WebSocket and update documentation
  • 0e80103 style(discord): fix goimports formatting and add 3x-ui to gitignore
  • 8ba6d37 Merge branch 'main' into feature/discord-bot
  • 055ff7a Merge branch 'main' into feature/discord-bot
  • dbfd5d6 fix(discord): stop gateway panics, reconnect storms and proxy bypass

📊 Changes

59 files changed (+6271 additions, -206 deletions)

View changed files

📝 .gitignore (+1 -0)
📝 docs/content/docs/en/config/panel.mdx (+1 -0)
➕ docs/content/docs/en/operations/discord-bot.mdx (+121 -0)
📝 docs/content/docs/en/operations/meta.json (+1 -0)
📝 docs/content/docs/en/reference/api/clients.mdx (+4 -2)
📝 docs/content/docs/en/reference/api/settings.mdx (+8 -1)
📝 docs/content/docs/fa/operations/meta.json (+1 -0)
📝 docs/content/docs/ru/config/panel.mdx (+1 -0)
➕ docs/content/docs/ru/operations/discord-bot.mdx (+121 -0)
📝 docs/content/docs/ru/operations/meta.json (+1 -0)
📝 docs/content/docs/zh/operations/meta.json (+1 -0)
📝 docs/public/openapi.json (+126 -0)
📝 frontend/public/openapi.json (+126 -0)
📝 frontend/src/components/command-palette/CommandPalette.tsx (+8 -0)
➕ frontend/src/components/ui/notifications/DiscordNotifications.stories.tsx (+89 -0)
➕ frontend/src/components/ui/notifications/DiscordNotifications.tsx (+123 -0)
📝 frontend/src/generated/examples.ts (+21 -0)
📝 frontend/src/generated/schemas.ts (+92 -0)
📝 frontend/src/generated/types.ts (+21 -0)
📝 frontend/src/generated/zod.ts (+21 -0)

...and 39 more files

📄 Description

Summary

Integrates native Discord notification support via a lightweight Discord REST API v10 client and the existing internal/eventbus/ infrastructure, accompanied by a dedicated Discord settings tab and event notification triggers in the UI.

Why

Many server administrators prefer Discord over Telegram for monitoring server health and receiving incident alerts. This adds first-class support for Discord embeds covering system health (cpu.high, memory.high), node status (node.down, node.up), outbound connectivity (outbound.down, outbound.up), core crashes (xray.crash), and security events (login.attempt), complete with rate limiting and secret protection.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  1. Automated Unit & Contract Tests:

    • go test -v ./internal/web/service/discord/... — all 18 tests passed (covering HTTP status codes, rate limiter semantics, rune-safe embed truncation, value/pointer event data).
    • go test -v -run TestRouteRegistryContract ./internal/web — verified bidirectional route parity for POST /panel/api/setting/testDiscord.
    • npx vitest run src/test/factory-defaults-contract.test.ts — verified setting default synchronisation across Go and TypeScript.
    • npx vitest run src/test/i18n-dead-keys.test.ts — verified 0 dead keys and exact key parity across all 13 locales.
    • npm run typecheck && npm run lint && npm run format:check — clean.
    • go build ./... and npm run build pass without warnings.
  2. Manual & Live Discord API Testing:

    • Configured a real Discord Bot Token and Channel ID in /settings#discord.
    • Clicked "Send Test Notification" in the UI and verified instant receipt of the test embed in the Discord channel.
    • Dispatched mock payloads for all 8 event types (outbound.down/up, node.down/up, xray.crash, cpu.high, memory.high, login.attempt) and confirmed color bars and embed formatting in a live Discord channel.

Screenshots / recordings

image image image

Breaking changes

None


🔄 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/6486 **Author:** [@poise52](https://github.com/poise52) **Created:** 9/12/2026 **Status:** ✅ Merged **Merged:** 9/13/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feature/discord-bot` --- ### 📝 Commits (10+) - [`9811902`](https://github.com/MHSanaei/3x-ui/commit/981190217f4826a26eb114925f4cc4ec3b7cb35a) feat(discord): add Discord notification bot service, settings UI, and event subscriber - [`c364e16`](https://github.com/MHSanaei/3x-ui/commit/c364e16f0f57390cd332bdf1f3daac82bc692084) fix(discord): address PR review findings on concurrency, linting, i18n, and stories - [`7609741`](https://github.com/MHSanaei/3x-ui/commit/7609741c71afd6a631ad1409fd9bbc960a7bbaac) docs: add Discord bot setup and operations guide - [`3692a63`](https://github.com/MHSanaei/3x-ui/commit/3692a63dceb638e66d86edd95a679e1dab841729) feat(discord): add discordLang, discordRunTime, discordBotBackup settings and update settings UI - [`230031e`](https://github.com/MHSanaei/3x-ui/commit/230031ebebb0805df82a62e6ba0890ed62822585) feat(discord): implement scheduled status reports and database backup attachments - [`52dbefc`](https://github.com/MHSanaei/3x-ui/commit/52dbefc4b8226f36ee51deb40fef911e98ba0f49) feat(discord): add interactive bot commands via Gateway WebSocket and update documentation - [`0e80103`](https://github.com/MHSanaei/3x-ui/commit/0e80103e1a7ab30c55a984ba2b4a6a1896c82085) style(discord): fix goimports formatting and add 3x-ui to gitignore - [`8ba6d37`](https://github.com/MHSanaei/3x-ui/commit/8ba6d37fa9203722ac67e8ec508f0ab7fa2b991e) Merge branch 'main' into feature/discord-bot - [`055ff7a`](https://github.com/MHSanaei/3x-ui/commit/055ff7aa489c58ca5c2c6ce1460ba882e954e605) Merge branch 'main' into feature/discord-bot - [`dbfd5d6`](https://github.com/MHSanaei/3x-ui/commit/dbfd5d63e685dd5917a051c1f3485b8f7b2e4bc5) fix(discord): stop gateway panics, reconnect storms and proxy bypass ### 📊 Changes **59 files changed** (+6271 additions, -206 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+1 -0) 📝 `docs/content/docs/en/config/panel.mdx` (+1 -0) ➕ `docs/content/docs/en/operations/discord-bot.mdx` (+121 -0) 📝 `docs/content/docs/en/operations/meta.json` (+1 -0) 📝 `docs/content/docs/en/reference/api/clients.mdx` (+4 -2) 📝 `docs/content/docs/en/reference/api/settings.mdx` (+8 -1) 📝 `docs/content/docs/fa/operations/meta.json` (+1 -0) 📝 `docs/content/docs/ru/config/panel.mdx` (+1 -0) ➕ `docs/content/docs/ru/operations/discord-bot.mdx` (+121 -0) 📝 `docs/content/docs/ru/operations/meta.json` (+1 -0) 📝 `docs/content/docs/zh/operations/meta.json` (+1 -0) 📝 `docs/public/openapi.json` (+126 -0) 📝 `frontend/public/openapi.json` (+126 -0) 📝 `frontend/src/components/command-palette/CommandPalette.tsx` (+8 -0) ➕ `frontend/src/components/ui/notifications/DiscordNotifications.stories.tsx` (+89 -0) ➕ `frontend/src/components/ui/notifications/DiscordNotifications.tsx` (+123 -0) 📝 `frontend/src/generated/examples.ts` (+21 -0) 📝 `frontend/src/generated/schemas.ts` (+92 -0) 📝 `frontend/src/generated/types.ts` (+21 -0) 📝 `frontend/src/generated/zod.ts` (+21 -0) _...and 39 more files_ </details> ### 📄 Description ## Summary Integrates native Discord notification support via a lightweight Discord REST API v10 client and the existing `internal/eventbus/` infrastructure, accompanied by a dedicated Discord settings tab and event notification triggers in the UI. ## Why Many server administrators prefer Discord over Telegram for monitoring server health and receiving incident alerts. This adds first-class support for Discord embeds covering system health (`cpu.high`, `memory.high`), node status (`node.down`, `node.up`), outbound connectivity (`outbound.down`, `outbound.up`), core crashes (`xray.crash`), and security events (`login.attempt`), complete with rate limiting and secret protection. ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? 1. **Automated Unit & Contract Tests:** - `go test -v ./internal/web/service/discord/...` — all 18 tests passed (covering HTTP status codes, rate limiter semantics, rune-safe embed truncation, value/pointer event data). - `go test -v -run TestRouteRegistryContract ./internal/web` — verified bidirectional route parity for `POST /panel/api/setting/testDiscord`. - `npx vitest run src/test/factory-defaults-contract.test.ts` — verified setting default synchronisation across Go and TypeScript. - `npx vitest run src/test/i18n-dead-keys.test.ts` — verified 0 dead keys and exact key parity across all 13 locales. - `npm run typecheck && npm run lint && npm run format:check` — clean. - `go build ./...` and `npm run build` pass without warnings. 2. **Manual & Live Discord API Testing:** - Configured a real Discord Bot Token and Channel ID in `/settings#discord`. - Clicked "Send Test Notification" in the UI and verified instant receipt of the test embed in the Discord channel. - Dispatched mock payloads for all 8 event types (`outbound.down/up`, `node.down/up`, `xray.crash`, `cpu.high`, `memory.high`, `login.attempt`) and confirmed color bars and embed formatting in a live Discord channel. ## Screenshots / recordings <img width="697" height="765" alt="image" src="https://github.com/user-attachments/assets/aeed25b3-d27d-4772-b6bc-c80e185e5a86" /> <img width="3358" height="635" alt="image" src="https://github.com/user-attachments/assets/5de978ca-bd3d-46aa-a707-88d6a75cd726" /> <img width="3357" height="547" alt="image" src="https://github.com/user-attachments/assets/bb89d47c-d607-4cab-9d46-f12a5507afc0" /> ## Breaking changes None --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:47 +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#6300
No description provided.