Skip to content

Discord Animus Agent - GitHub webhook processor for Discord integration

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-CC-BY-SA
Notifications You must be signed in to change notification settings

AnimusUNO/animus-discord

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Discord Animus Agent - Complete GitHub to Discord Integration

A production-ready Flask webhook processor that receives GitHub organization events, validates HMAC signatures, processes them through Letta AI agents, and delivers intelligent Discord notifications.

πŸ“’ Repository Status: This repository is now public and open for contributions!

🎯 Project Status: COMPLETE βœ…

Full GitHub β†’ Letta β†’ Discord integration is operational and production-ready!

βœ… Complete System Features

  • πŸ” HMAC-SHA256 Signature Verification - Secure webhook authentication
  • πŸ“‘ GitHub Event Processing - Issues, PRs, pushes, releases, comments, and more
  • πŸ€– Letta AI Integration - Sends events to Mouse agent for intelligent processing
  • πŸ’¬ Discord Messaging - Self-contained Discord tool with zero dependencies
  • ⏱️ Event Buffering - 2-second delays prevent overwhelming AI agents
  • πŸ“Š Health Monitoring - Health check and statistics endpoints
  • πŸ”„ Auto-Recovery - Cron-based auto-restart system
  • πŸ“ Structured Logging - JSON-formatted logs with full context
  • πŸ§ͺ Comprehensive Testing - Real GitHub event testing completed
  • πŸš€ Production Management - Complete deployment and management scripts
  • πŸ“š Full Documentation - Comprehensive guides and API references

πŸ—οΈ Complete Architecture

GitHub Events β†’ Webhook Processor β†’ Letta Agent (Mouse) β†’ Discord Channel
     ↓              ↓                    ↓              ↓
  HMAC Verify   Event Buffer        AI Processing   Self-Contained
  Event Parse   2s Delay           Agent Targeting   HTTP Client

πŸš€ Quick Start

1. Clone and Setup

git clone https://github.com/AnimusUNO/animus-discord.git
cd animus-discord
python3 -m venv venv
source venv/bin/activate  # Linux/Mac
# .\venv\Scripts\Activate.ps1  # Windows
pip install -r requirements.txt

2. Configure Environment

# Copy example configuration
cp config.env.example .env

# Edit .env file with your settings
# WEBHOOK_SECRET=your_github_webhook_secret
# LETTA_API_KEY=your_letta_api_key
# DISCORD_BOT_TOKEN=your_discord_bot_token
# DISCORD_CHANNEL_ID=your_discord_channel_id

3. Start Webhook Processor

# Production mode (recommended)
./manage-webhook.sh start

# Development mode
python webhook_processor.py

4. Verify Installation

# Check health
curl http://localhost:5000/health

# Check statistics
curl http://localhost:5000/stats

# View logs
./manage-webhook.sh logs

API Endpoints

POST /webhook

Main webhook endpoint for receiving GitHub events.

Headers Required:

  • X-Hub-Signature-256: HMAC-SHA256 signature
  • X-GitHub-Event: Event type (issues, push, pull_request, etc.)
  • X-GitHub-Delivery: Unique delivery ID
  • Content-Type: application/json

Response:

{
  "status": "processed",
  "event_id": "delivery-id",
  "processed_at": "2025-10-09T20:44:05Z",
  "event_count": 1
}

GET /health

Health check endpoint.

Response:

{
  "status": "healthy",
  "uptime_seconds": 3600,
  "events_processed": 42,
  "timestamp": "2025-10-09T20:44:05Z"
}

GET /stats

Statistics endpoint.

Response:

{
  "uptime_seconds": 3600,
  "events_processed": 42,
  "start_time": "2025-10-09T19:44:05Z",
  "webhook_secret_configured": true,
  "debug_mode": false
}

Supported Event Types

  • Issues: opened, closed, assigned, labeled, etc.
  • Pull Requests: opened, closed, merged, reviewed, etc.
  • Push: code commits, branch updates, tags
  • Release: published, unpublished
  • Repository: created, deleted, archived, renamed
  • Team: member added/removed, permissions changed
  • Organization: member added/removed, billing changes
  • Workflow Runs: CI/CD pipeline events
  • Deployments: deployment status updates
  • Security Events: vulnerability alerts, dependency updates

Event Processing

Normalized Event Structure

All events are normalized into a consistent structure:

{
  "event_type": "issues",
  "delivery_id": "unique-delivery-id",
  "timestamp": "2025-10-09T20:44:05Z",
  "action": "opened",
  "repository": {
    "id": 111222333,
    "name": "repo-name",
    "full_name": "org/repo-name",
    "url": "https://github.com/org/repo-name",
    "private": false,
    "default_branch": "main"
  },
  "sender": {
    "id": 987654321,
    "login": "username",
    "name": "User Name",
    "email": "user@example.com",
    "avatar_url": "https://avatars.githubusercontent.com/u/987654321"
  },
  "organization": {
    "id": 444555666,
    "login": "org-name",
    "name": "Organization Name",
    "url": "https://github.com/org-name"
  },
  "issue": {
    "issue_id": 123456789,
    "number": 42,
    "title": "Issue Title",
    "body": "Issue description",
    "state": "open",
    "labels": ["bug", "priority-high"],
    "assignees": ["username"],
    "url": "https://github.com/org/repo/issues/42"
  }
}

Event Filtering

Events are filtered based on configurable rules:

  • Parse Errors: Automatically skipped
  • Test Repositories: Skipped (repositories with "test" in name)
  • Custom Rules: Extensible filtering system

Security

HMAC Signature Verification

All webhook requests are verified using HMAC-SHA256 signatures:

def verify_signature(payload_body: bytes, signature_header: str) -> bool:
    sha_name, signature = signature_header.split('=')
    expected = hmac.new(
        WEBHOOK_SECRET.encode(),
        payload_body,
        hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(expected, signature)

Environment Variables

  • WEBHOOK_SECRET: GitHub webhook secret (required)
  • FLASK_SECRET_KEY: Flask secret key (required)
  • PORT: Server port (default: 5000)
  • DEBUG: Debug mode (default: False)
  • LOG_LEVEL: Logging level (default: INFO)

Testing

Unit Tests

# Run all tests
python -m pytest test_webhook_processor.py -v

# Run specific test categories
python -m pytest test_webhook_processor.py::TestWebhookProcessor -v
python -m pytest test_webhook_processor.py::TestWebhookEndpoints -v
python -m pytest test_webhook_processor.py::TestEventParsing -v

Integration Tests

# Test with running server
python start_webhook.py &
python test_webhook_cli.py --test-endpoint

Manual Testing

  1. Start webhook processor:

    python start_webhook.py
  2. Update GitHub webhook URL:

    gh api --method PATCH /orgs/AnimusUNO/hooks/574364342 \
      -f config='{"url":"http://localhost:5000/webhook","content_type":"json","secret":"animus_webhook_secret_2024"}'
  3. Trigger test events:

    • Make commits to AnimusUNO/animus-discord
    • Create issues in the repository
    • Create pull requests
  4. Monitor logs:

    # Check webhook processor logs
    # Verify events are received and processed

πŸ“ Complete Project Structure

animus-discord/
β”œβ”€β”€ webhook_processor.py      # Main Flask application with Letta integration
β”œβ”€β”€ letta_integration.py       # Letta AI client integration
β”œβ”€β”€ letta_discord_tool.py      # Self-contained Discord tool
β”œβ”€β”€ manage-webhook.sh          # Production webhook management script
β”œβ”€β”€ manage-cron.sh             # Cron job management for auto-recovery
β”œβ”€β”€ launch-webhook.sh          # Webhook startup script
β”œβ”€β”€ requirements.txt           # Python dependencies
β”œβ”€β”€ requirements-dev.txt       # Development dependencies
β”œβ”€β”€ config.env.example         # Environment configuration template
β”œβ”€β”€ docs/                      # Complete documentation
β”‚   β”œβ”€β”€ discord-bot-setup.md   # Discord bot configuration guide
β”‚   β”œβ”€β”€ discord-tool.md        # Discord tool documentation
β”‚   β”œβ”€β”€ letta-api-reference.md # Letta API reference
β”‚   β”œβ”€β”€ letta_tool_compatibility_notes.md
β”‚   β”œβ”€β”€ production-deployment.md # Production deployment guide
β”‚   └── project-plan.md        # Original project plan
β”œβ”€β”€ scripts/                   # Setup utilities
β”‚   β”œβ”€β”€ setup-webhook.sh       # GitHub webhook setup
β”‚   └── setup-webhook.ps1      # Windows version
β”œβ”€β”€ test_webhook_processor.py  # Unit tests
β”œβ”€β”€ test_webhook_cli.py        # CLI testing tool
β”œβ”€β”€ LAUNCH_SCRIPTS.md          # Management script documentation
β”œβ”€β”€ LICENSE                    # AGPLv3 license for code
β”œβ”€β”€ LICENSE-CC-BY-SA          # CC-BY-SA license for documentation
└── CONTRIBUTING.md            # Contribution guidelines

πŸ”§ Complete Configuration

Environment Variables

Variable Required Description
WEBHOOK_SECRET βœ… GitHub webhook secret for HMAC verification
LETTA_API_KEY βœ… Letta API key for agent communication
DISCORD_BOT_TOKEN βœ… Discord bot token for messaging
DISCORD_CHANNEL_ID βœ… Discord channel ID for notifications
FLASK_SECRET_KEY βœ… Flask secret key for sessions
PORT ❌ Server port (default: 5000)
DEBUG ❌ Debug mode (default: False)
LOG_LEVEL ❌ Logging level (default: INFO)

GitHub Webhook Setup

  1. Create Organization Webhook:

    ./scripts/setup-webhook.sh AnimusUNO https://your-domain.com/webhook your_secret
  2. Configure Events: Select all events (["*"]) for comprehensive monitoring

  3. Verify Setup:

    gh api /orgs/AnimusUNO/hooks

πŸ€– Complete Letta Integration

Agent Configuration

The system sends GitHub events to the Mouse agent (agent-c2fef691-44d3-4e86-9dbb-a6a681355a8b) which:

  • Processes events using AI reasoning
  • Formats messages for Discord
  • Sends notifications via self-contained Discord tool
  • Handles rate limiting with 2-second buffering

Discord Tool

The letta_discord_tool.py provides a self-contained Discord messaging function:

  • βœ… Zero external dependencies - Uses only Python built-ins
  • βœ… Letta-compatible - Proper JSON schema and function signature
  • βœ… Agent-specific - Targets Animus agent explicitly
  • βœ… Production-ready - Comprehensive error handling

πŸ› οΈ Complete Management Commands

Webhook Management

# Start webhook
./manage-webhook.sh start

# Stop webhook
./manage-webhook.sh stop

# Restart webhook
./manage-webhook.sh restart

# Check status
./manage-webhook.sh status

# View logs
./manage-webhook.sh logs

# Health check
./manage-webhook.sh health

# Statistics
./manage-webhook.sh stats

Auto-Recovery Setup

# Install cron job for auto-restart
./manage-cron.sh install

# Check cron status
./manage-cron.sh status

# Remove cron job
./manage-cron.sh remove

πŸ§ͺ Complete Testing

Manual Testing

# Create test issue
gh issue create --title "Test Issue" --body "Testing webhook integration"

# Add comment
gh issue comment 1 --body "Test comment"

# Close issue
gh issue close 1

Health Verification

# Check webhook health
curl http://localhost:5000/health

# Check statistics
curl http://localhost:5000/stats

# Monitor logs
./manage-webhook.sh logs

πŸš€ Complete Production Deployment

Server Setup

# Clone repository
git clone https://github.com/AnimusUNO/animus-discord.git
cd animus-discord

# Setup virtual environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Configure environment
cp config.env.example .env
# Edit .env with production values

# Start webhook
./manage-webhook.sh start

# Setup auto-recovery
./manage-cron.sh install

GitHub Webhook Configuration

# Update webhook URL
gh api --method PATCH /orgs/AnimusUNO/hooks/574364342 \
  --field config[url]="https://your-domain.com/webhook" \
  --field config[secret]="your-production-secret"

Current Production Status

  • Webhook ID: 574364342
  • Organization: AnimusUNO
  • Events: All events (["*"])
  • Status: βœ… Active and processing events
  • Agent: Mouse (Mini model 4.1)
  • Buffer: 2-second delays active

Monitoring

Health Checks

  • Endpoint: GET /health
  • Response: JSON with status, uptime, event count
  • Use Case: Load balancer health checks

Statistics

  • Endpoint: GET /stats
  • Response: Detailed statistics
  • Use Case: Monitoring dashboards

Logs

  • Format: Structured JSON logs
  • Levels: DEBUG, INFO, WARNING, ERROR
  • Context: Event details, processing results

πŸ“š Complete Documentation

🎯 Project Completion Summary

This project successfully delivers a complete end-to-end GitHub to Discord integration:

βœ… Phase 1: GitHub Webhook Processor - Complete
βœ… Phase 2: Letta AI Integration - Complete
βœ… Phase 3: Discord Messaging Tool - Complete
βœ… Production Management: Auto-recovery and monitoring - Complete
βœ… Documentation: Comprehensive guides and references - Complete

Future Enhancement Opportunities

While the core project is complete, potential enhancements could include:

  • Enhanced Event Filtering - Advanced filtering rules
  • Multiple Agent Support - Support for multiple Letta agents
  • Metrics Integration - Prometheus/StatsD integration
  • Alerting System - Error notification system
  • Web Dashboard - Real-time monitoring interface

Troubleshooting

Common Issues

  1. Signature Verification Failed:

    • Check WEBHOOK_SECRET matches GitHub webhook secret
    • Verify webhook URL is correct
  2. Events Not Processing:

    • Check webhook is active in GitHub
    • Verify webhook URL is accessible
    • Check logs for errors
  3. High Memory Usage:

    • Check for memory leaks in event processing
    • Monitor event queue size

Debug Mode

Enable debug mode for detailed logging:

export DEBUG="True"
python start_webhook.py

🀝 Contributing

We welcome contributions to the Discord Animus Agent! Since this repository is now public, we encourage community participation.

πŸ“– For detailed contribution guidelines, see CONTRIBUTING.md

Quick Start

  1. Fork the repository on GitHub
  2. Clone your fork and set up the development environment
  3. Create a feature branch and make your changes
  4. Run tests and ensure everything passes
  5. Create a Pull Request with a clear description

Areas for Contribution

While the core project is complete, contributions are welcome for:

  • Enhanced Features: Advanced filtering, multiple agent support
  • Testing: Additional test coverage and edge cases
  • Documentation: Improvements and additional examples
  • Performance: Optimization and monitoring enhancements
  • Security: Enhanced security features and audits
  • Bug Fixes: Issue resolution and improvements

License

This project uses dual licensing:

  • Source Code: Licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details
  • Documentation & Media: Licensed under Creative Commons Attribution-ShareAlike 4.0 International - see the LICENSE-CC-BY-SA file for details

What this means:

  • Code: AGPLv3 ensures that any modifications or network services using this code must also be open source
  • Documentation: CC-BY-SA allows sharing and adaptation of documentation with proper attribution

About

Discord Animus Agent - GitHub webhook processor for Discord integration

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-CC-BY-SA

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published