SurfSense icon indicating copy to clipboard operation
SurfSense copied to clipboard

Feat/Discord Connector

Open MuhamadAjiW opened this issue 6 months ago • 5 comments

Description

  1. Added a rough implementation of discord connector. Related to issue #43
  2. Knowledge store and retrieval is unoptimized (Probably too much is stored for now)

Motivation and Context

I am highly interested in this project. Self-hosted knowledge base is awesome. Aside from that, I need the functionality since I use discord quite intensely

Changes Overview

  • Added discord connector. Lots of copy pasting from slack connector, hopefully it fits the code style.
  • Added the discord package for the backend repo

It's working so far, but may require plenty of tuning as seen from the query on the first and second screenshot

Screenshots

Query test 1 image Query test 2 image Edit view image Add view image Setup view 1 image Setup view 2 image

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Performance improvement (non-breaking change which enhances performance)
  • [ ] Documentation update
  • [x] Breaking change (fix or feature that would cause existing functionality to change)

Testing

  • [x] I have tested these changes locally
  • [ ] I have added/updated unit tests
  • [ ] I have added/updated integration tests

Checklist:

  • [x] My code follows the code style of this project
  • [x] My change requires documentation updates
  • [ ] I have updated the documentation accordingly
  • [x] My change requires dependency updates
  • [x] I have updated the dependencies accordingly
  • [x] My code builds clean without any errors or warnings
  • [x] All new and existing tests passed

Hopefully this is useful, thank you and nice meeting you all!

Summary by CodeRabbit

  • New Features

    • Introduced Discord as a new connector to index and search messages from Discord servers.
    • Added a dedicated setup page with form and documentation for connecting Discord via bot token.
    • Enabled Discord connector visibility and availability in the "Team Chats" category with icon support.
  • Improvements

    • Added support for editing and updating Discord connector settings, including bot token management.
    • Integrated Discord messages as a recognized knowledge source for AI-powered search and research.
  • Chores

    • Updated dependencies to include the Discord package for integration support.

MuhamadAjiW avatar Jun 02 '25 13:06 MuhamadAjiW

@MuhamadAjiW is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jun 02 '25 13:06 vercel[bot]

Walkthrough

This change introduces full support for a Discord connector across the backend and frontend. It adds Discord as a connector type, implements Discord bot integration for message retrieval and indexing, updates database enums and migrations, extends validation and indexing logic, and provides UI components for adding, editing, and displaying Discord connectors.

Changes

File(s) Change Summary
.../alembic/versions/9_add_discord_connector_enum_and_documenttype.py, .../app/db.py Added DISCORD_CONNECTOR to PostgreSQL enums and corresponding Python enums for document and connector types. Migration script includes upgrade/downgrade logic.
.../app/connectors/discord_connector.py New module implementing DiscordConnector class for Discord bot authentication, guild/channel/message retrieval, and user info access via discord.py.
.../app/agents/researcher/nodes.py Added Discord connector support in fetch_relevant_documents, including async search and streaming logic for Discord messages.
.../app/agents/researcher/sub_section_writer/prompts.py Added Discord as a knowledge source in citation prompt descriptions.
.../app/routes/search_source_connectors_routes.py Added Discord connector support in connector indexing endpoint; new async helpers for Discord indexing, following established patterns for other connectors.
.../app/schemas/search_source_connector.py Extended config validation to support DISCORD_CONNECTOR with required DISCORD_BOT_TOKEN key.
.../app/tasks/connectors_indexing_tasks.py Added index_discord_messages async function for indexing Discord messages, handling deduplication, chunking, embedding, and database updates.
.../app/utils/connector_service.py Added search_discord async method to ConnectorService for searching Discord messages in chunks or documents mode, formatting results for UI.
.../pyproject.toml Added discord>=2.5.2 as a backend dependency.
.../dashboard/[search_space_id]/connectors/add/discord-connector/page.tsx New React page for adding a Discord connector, with form validation, documentation, and UI for bot token entry.
.../dashboard/[search_space_id]/connectors/add/page.tsx Updated Discord connector entry: changed ID, set status to "available", and expanded "Team Chats" category by default.
.../dashboard/[search_space_id]/connectors/[connector_id]/edit/page.tsx Added form rendering for editing Discord connector, supporting bot token updates.
.../dashboard/[search_space_id]/connectors/[connector_id]/page.tsx, .../lib/connectors/utils.ts Added Discord connector type to display name mappings and API key field name logic.
.../components/chat/ConnectorComponents.tsx Added Discord icon to connector icon mapping.
.../components/editConnector/types.ts Added optional DISCORD_BOT_TOKEN field to connector edit schema.
.../hooks/useConnectorEditPage.ts Integrated Discord bot token support into connector edit workflow, including form state and update logic.
.../app/dashboard/[search_space_id]/documents/(manage)/page.tsx Added support for DISCORD_CONNECTOR document type and associated icon in documents management UI.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebUI
    participant BackendAPI
    participant DiscordConnector
    participant DiscordAPI
    participant DB

    User->>WebUI: Add Discord Connector (enter bot token)
    WebUI->>BackendAPI: POST /connectors (type=DISCORD_CONNECTOR, token)
    BackendAPI->>DB: Save connector config
    User->>WebUI: Trigger Indexing
    WebUI->>BackendAPI: POST /connectors/{id}/index
    BackendAPI->>DiscordConnector: Start bot with token
    DiscordConnector->>DiscordAPI: Fetch guilds, channels, messages
    DiscordAPI-->>DiscordConnector: Return data
    DiscordConnector->>BackendAPI: Return messages
    BackendAPI->>DB: Store indexed messages as documents
    BackendAPI->>WebUI: Indexing complete

    User->>WebUI: Query Discord messages
    WebUI->>BackendAPI: Search request (type=DISCORD_CONNECTOR)
    BackendAPI->>DB: Retrieve Discord documents
    BackendAPI->>WebUI: Return search results

Possibly related PRs

  • MODSetter/SurfSense#42: Adds Linear connector support following the same backend and frontend integration patterns as the Discord connector in this PR.
  • MODSetter/SurfSense#90: Introduces a general search mode enum and modifies search functions, which directly relates to the Discord search integration in this PR.
  • MODSetter/SurfSense#37: Adds GitHub connector support with similar enum, migration, indexing, and search logic changes as this Discord connector PR.

Suggested reviewers

  • MODSetter

Poem

In Discord’s halls, the rabbits hop,
Fetching messages, they never stop.
With tokens safe and channels wide,
They index chats with bounding pride.
Now Discord joins the warren’s crew—
A connector fresh, a world anew!
🐰💬✨

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jun 02 '25 13:06 coderabbitai[bot]

⚠️ Only 5 files will be analyzed due to processing limits.

recurseml[bot] avatar Jun 02 '25 13:06 recurseml[bot]

⚠️ Only 5 files will be analyzed due to processing limits.

recurseml[bot] avatar Jun 02 '25 13:06 recurseml[bot]

😱 Found 2 issues. Time to roll up your sleeves! 😱

recurseml[bot] avatar Jun 02 '25 13:06 recurseml[bot]

Looks good to me. This is a major contribution. Thanks @MuhamadAjiW AWESOME WORK 🥇

MODSetter avatar Jun 02 '25 18:06 MODSetter