Skip to content

feat: persistent Discord bot, OAuth invite button, dedup alerts#24

Merged
rafia9005 merged 2 commits into
mainfrom
dev
Jun 12, 2026
Merged

feat: persistent Discord bot, OAuth invite button, dedup alerts#24
rafia9005 merged 2 commits into
mainfrom
dev

Conversation

@rafia9005

@rafia9005 rafia9005 commented Jun 12, 2026

Copy link
Copy Markdown
Member

Changes

Discord Bot - Persistent Session

  • Keep discordgo session open 24/7 (not per-alert connect/disconnect)
  • Rich presence: monitor count, activity "monitoring uptime" with app icon
  • Reconnects automatically on disconnect
  • Restarts session when bot token changed via settings

Discord Invite Button

  • Replace discord_invite_link setting with discord_client_id
  • Notification preferences shows Invite Bot button → proper OAuth URL
  • Users can add bot to their own servers

Alert Dedup

  • Email: 1 per incident (owner only). Removed admin backup CC.
  • Email channel type removed from channel alerts — email already sent once.
  • No more spam from repeated checks.

Files Changed

  • modules/notifications/module.go — persistent Discord session, presence, dedup
  • modules/settings/module.go — add discord_client_id default setting
  • web/src/validations/setting.ts — add discord_client_id schema
  • web/src/views/App.Settings.vue — Client ID field, fetch/save
  • web/src/views/App.Notifications.vue — Invite Bot button, MessageCircle icon

Summary by CodeRabbit

  • New Features

    • Added Discord bot integration with persistent session management and presence updates.
    • Added Discord Client ID setting with generated OAuth invite link display in the notifications dashboard.
    • Enhanced notification channel routing for Discord bot alerts.
  • Bug Fixes

    • Improved incident email alert delivery to send exactly one email per incident to the owner.

- Replace discord_invite_link with discord_client_id for proper OAuth URL
- Add Discord invite button in notification preferences (auto-generates bot invite URL)
- Persistent discordgo session — always online, reconnects on token change
- Rich Discord presence with monitor count + large image
- Dedup alerts: 1 email per incident (owner only), remove admin backup CC
- Skip email channel type — email already sent once
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7b5fb20c-9db9-4b38-a2fc-1049abe01dbf

📥 Commits

Reviewing files that changed from the base of the PR and between 1a559c7 and 76b21a5.

📒 Files selected for processing (5)
  • modules/notifications/module.go
  • modules/settings/module.go
  • web/src/validations/setting.ts
  • web/src/views/App.Notifications.vue
  • web/src/views/App.Settings.vue

📝 Walkthrough

Walkthrough

This PR establishes persistent Discord bot session management in the notifications module, refactors incident email alerts to consolidate them at the incident level (owner only), and adds Discord Client ID configuration across settings and UI views to display bot invite links.

Changes

Discord Bot Session Persistence and Alert Flow

Layer / File(s) Summary
Module struct and sync import for Discord persistence
modules/notifications/module.go
Module struct extended with discordMu, discordSession, and discordToken fields for maintaining a reusable session across alerts; sync import added.
Discord session lifecycle and initialization
modules/notifications/module.go
Full persistent session lifecycle in NewModule: token lookup, session creation/open, ready/reconnect handlers with presence updates, and graceful shutdown/token clearing.
Setting change listener and session restart
modules/notifications/module.go
HandleSettingSaved event handler restarts the persistent Discord session when discord_bot_token setting changes.
Incident-level email consolidation
modules/notifications/module.go
Incident handlers now send exactly one email per incident (owner only) via new sendEmail helper; per-channel email dispatch removed.
Channel alert dispatch and persistent session routing
modules/notifications/module.go
sendChannelAlerts refactored to skip email dispatch (handled at incident level) and route discord_bot alerts through persistent session instead of per-alert client creation.
Webhook payload type updates
modules/notifications/module.go
Webhook payloads use map[string]any for typed sub-objects; sendJSONPost signature accepts payload any instead of payload interface{}.

Discord Client ID Configuration UI

Layer / File(s) Summary
Settings module default
modules/settings/module.go
Added discord_client_id default setting entry with empty initial value and OAuth invite description.
Frontend Zod validation schema
web/src/validations/setting.ts
Extended settingSchema with optional discord_client_id field accepting string or empty-string literal.
Settings form field for Discord Client ID
web/src/views/App.Settings.vue
Added discordClientId reactive ref, wired fetch/save to discord_client_id setting, and rendered form input in Notification Bot Settings card.
Notifications view Discord invite banner
web/src/views/App.Notifications.vue
Derived discordInviteLink computed property from discord_client_id, updated icon imports, and rendered conditional Discord Bot invite banner with external link button.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 A bot to persist through the flow,
One email per incident, not a show,
With tokens reused and settings saved,
Discord invites—the feast is paved! 🎯✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rafia9005 rafia9005 merged commit e8ae6fc into main Jun 12, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant