# Enhanced Discord Integration Blocks Introduces new blocks for sending DMs, embeds, files, and replies in Discord, as well as blocks for retrieving user and channel information. Enhances existing message blocks with additional metadata fields and server/channel identification. Improves test coverage and input/output schemas for all Discord-related blocks. Co-Authored-By: Claude <claude@users.noreply.github.com> ## Why These Changes Are Needed 🎯 The existing Discord integration was limited to basic message sending and reading. Users needed more sophisticated Discord functionality to build comprehensive automation workflows: 1. **Limited messaging options** - Could only send plain text to channels, no DMs, embeds, or file attachments 2. **Poor graph connectivity** - Blocks didn't output IDs needed for chaining operations (e.g., couldn't reply to a message after sending it) 3. **No user management** - Couldn't get user information or send direct messages 4. **Type safety issues** - Discord.py's incomplete type hints caused linting errors 5. **No channel resolution** - Had to manually find channel IDs instead of using names ### Changes 🏗️ #### New Blocks Added - **SendDiscordDMBlock** - Send direct messages to users via their Discord ID - **SendDiscordEmbedBlock** - Create rich embedded messages with images, fields, and formatting - **SendDiscordFileBlock** - Upload any file type (images, PDFs, videos, etc.) using MediaFileType - **ReplyToDiscordMessageBlock** - Reply to specific messages in threads - **DiscordUserInfoBlock** - Retrieve user profile information (username, avatar, creation date, etc.) - **DiscordChannelInfoBlock** - Resolve channel names to IDs and get channel metadata #### Enhanced Existing Blocks - **ReadDiscordMessagesBlock**: - Now outputs: `message_id`, `channel_id`, `user_id` (previously missing all IDs) - Enables workflows like: read message → reply to it, or read message → DM the author - **SendDiscordMessageBlock**: - Now outputs: `message_id`, `channel_id` (previously had no outputs except status) - Enables tracking sent messages and replying to them later #### Technical Improvements - **MediaFileType Support**: SendDiscordFileBlock accepts data URIs, URLs, or local paths - **Defensive Programming**: Added runtime type checks for Discord.py's incomplete typing - **ID Passthrough**: DiscordUserInfoBlock passes through user_id for chaining - **Better Error Messages**: Clear feedback when operations fail (e.g., "Channel cannot receive messages") - **Channel Flexibility**: Blocks accept both channel names and IDs ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: #### Test Plan 🧪 - [x] **Import and initialization**: All 8 Discord blocks import and initialize without errors - [x] **Type checking**: `poetry run format` passes with no type errors - [x] **Interface connectivity**: Verified blocks can chain together: - [x] ReadDiscordMessages → ReplyToDiscordMessage (via message_id, channel_id) - [x] ReadDiscordMessages → SendDiscordDM (via user_id) - [x] SendDiscordMessage → ReplyToDiscordMessage (via message_id, channel_id) - [x] DiscordUserInfo → SendDiscordDM (via user_id passthrough) - [x] DiscordChannelInfo → SendDiscordEmbed/File (via channel_id) - [x] **MediaFileType handling**: SendDiscordFileBlock correctly processes: - [x] Data URIs (base64 encoded files) - [x] URLs (downloads from web) - [x] Local paths (from other blocks) - [x] **Defensive checks**: Verified error handling for: - [x] Non-text channels (forums, categories) - [x] Private/DM channels without guilds - [x] Missing attributes on channel objects - [x] **Mock test data**: All blocks have appropriate test inputs/outputs defined ## Example Workflows Now Possible 🚀 1. **Auto-reply to mentions**: Read messages → Check if bot mentioned → Reply in thread 2. **File distribution**: Generate report → Send as PDF to Discord channel 3. **User notifications**: Get user info → Check if online → Send DM with alert 4. **Cross-platform sync**: Receive email attachment → Forward to Discord channel 5. **Rich notifications**: Create embed with thumbnail → Add fields → Send to announcement channel ## Breaking Changes ⚠️ None - all changes are backward compatible. Existing workflows using SendDiscordMessageBlock and ReadDiscordMessagesBlock will continue to work, they just now have additional outputs available. ## Dependencies 📦 No new dependencies added. Uses existing: - `discord.py` (already in project) - `aiohttp` (already in project) - Backend utilities: `MediaFileType`, `store_media_file` (already in project) --------- Co-authored-by: Claude <claude@users.noreply.github.com>
6.5 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Repository Overview
AutoGPT Platform is a monorepo containing:
- Backend (
/backend): Python FastAPI server with async support - Frontend (
/frontend): Next.js React application - Shared Libraries (
/autogpt_libs): Common Python utilities
Essential Commands
Backend Development
# Install dependencies
cd backend && poetry install
# Run database migrations
poetry run prisma migrate dev
# Start all services (database, redis, rabbitmq, clamav)
docker compose up -d
# Run the backend server
poetry run serve
# Run tests
poetry run test
# Run specific test
poetry run pytest path/to/test_file.py::test_function_name
# Run block tests (tests that validate all blocks work correctly)
poetry run pytest backend/blocks/test/test_block.py -xvs
# Run tests for a specific block (e.g., GetCurrentTimeBlock)
poetry run pytest 'backend/blocks/test/test_block.py::test_available_blocks[GetCurrentTimeBlock]' -xvs
# Lint and format
# prefer format if you want to just "fix" it and only get the errors that can't be autofixed
poetry run format # Black + isort
poetry run lint # ruff
More details can be found in TESTING.md
Creating/Updating Snapshots
When you first write a test or when the expected output changes:
poetry run pytest path/to/test.py --snapshot-update
⚠️ Important: Always review snapshot changes before committing! Use git diff to verify the changes are expected.
Frontend Development
# Install dependencies
cd frontend && npm install
# Start development server
npm run dev
# Run E2E tests
npm run test
# Run Storybook for component development
npm run storybook
# Build production
npm run build
# Type checking
npm run type-check
Architecture Overview
Backend Architecture
- API Layer: FastAPI with REST and WebSocket endpoints
- Database: PostgreSQL with Prisma ORM, includes pgvector for embeddings
- Queue System: RabbitMQ for async task processing
- Execution Engine: Separate executor service processes agent workflows
- Authentication: JWT-based with Supabase integration
- Security: Cache protection middleware prevents sensitive data caching in browsers/proxies
Frontend Architecture
- Framework: Next.js App Router with React Server Components
- State Management: React hooks + Supabase client for real-time updates
- Workflow Builder: Visual graph editor using @xyflow/react
- UI Components: Radix UI primitives with Tailwind CSS styling
- Feature Flags: LaunchDarkly integration
Key Concepts
- Agent Graphs: Workflow definitions stored as JSON, executed by the backend
- Blocks: Reusable components in
/backend/blocks/that perform specific tasks - Integrations: OAuth and API connections stored per user
- Store: Marketplace for sharing agent templates
- Virus Scanning: ClamAV integration for file upload security
Testing Approach
- Backend uses pytest with snapshot testing for API responses
- Test files are colocated with source files (
*_test.py) - Frontend uses Playwright for E2E tests
- Component testing via Storybook
Database Schema
Key models (defined in /backend/schema.prisma):
User: Authentication and profile dataAgentGraph: Workflow definitions with version controlAgentGraphExecution: Execution history and resultsAgentNode: Individual nodes in a workflowStoreListing: Marketplace listings for sharing agents
Environment Configuration
- Backend:
.envfile in/backend - Frontend:
.env.localfile in/frontend - Both require Supabase credentials and API keys for various services
Common Development Tasks
Adding a new block:
- Create new file in
/backend/backend/blocks/ - Inherit from
Blockbase class - Define input/output schemas
- Implement
runmethod - Register in block registry
- Generate the block uuid using
uuid.uuid4()
Note: when making many new blocks analyze the interfaces for each of these blcoks and picture if they would go well together in a graph based editor or would they struggle to connect productively? ex: do the inputs and outputs tie well together?
Modifying the API:
- Update route in
/backend/backend/server/routers/ - Add/update Pydantic models in same directory
- Write tests alongside the route file
- Run
poetry run testto verify
Frontend feature development:
- Components go in
/frontend/src/components/ - Use existing UI components from
/frontend/src/components/ui/ - Add Storybook stories for new components
- Test with Playwright if user-facing
Security Implementation
Cache Protection Middleware:
- Located in
/backend/backend/server/middleware/security.py - Default behavior: Disables caching for ALL endpoints with
Cache-Control: no-store, no-cache, must-revalidate, private - Uses an allow list approach - only explicitly permitted paths can be cached
- Cacheable paths include: static assets (
/static/*,/_next/static/*), health checks, public store pages, documentation - Prevents sensitive data (auth tokens, API keys, user data) from being cached by browsers/proxies
- To allow caching for a new endpoint, add it to
CACHEABLE_PATHSin the middleware - Applied to both main API server and external API applications
Creating Pull Requests
- Create the PR aginst the
devbranch of the repository. - Ensure the branch name is descriptive (e.g.,
feature/add-new-block)/ - Use conventional commit messages (see below)/
- Fill out the .github/PULL_REQUEST_TEMPLATE.md template as the PR description/
- Run the github pre-commit hooks to ensure code quality.
Conventional Commits
Use this format for commit messages and Pull Request titles:
Conventional Commit Types:
feat: Introduces a new feature to the codebasefix: Patches a bug in the codebaserefactor: Code change that neither fixes a bug nor adds a feature; also applies to removing featuresci: Changes to CI configurationdocs: Documentation-only changesdx: Improvements to the developer experience
Recommended Base Scopes:
platform: Changes affecting both frontend and backendfrontendbackendinfrablocks: Modifications/additions of individual blocks
Subscope Examples:
backend/executorbackend/dbfrontend/builder(includes changes to the block UI component)infra/prod
Use these scopes and subscopes for clarity and consistency in commit messages.