Imported from rontendo-jp/devinbot (
AGENTS.md). Install upstream withnpx skills add rontendo-jp/devinbot. Copyright stays with the author.
DevinBot - Custom Devin API Integration Platform
Project Overview
DevinBot is a custom backend application that integrates with Devin's API to automate software development workflows for a one-man developer. It provides GitHub webhook integration, Telegram-based control and monitoring, scheduled task execution, and real-time observability through a mobile web dashboard.
Core Use Cases
- Pull Request Review: Automatically trigger Devin to review PRs when they are raised on GitHub repositories
- Issue-based Development: Automatically start Devin sessions to work on code when GitHub issues are created
- Scheduled Tasks: Create and manage scheduled tasks that run Devin sessions with custom prompts
- Telegram Control: Two-way Telegram integration for monitoring job status and controlling Devin sessions
- Real-time Observability: Mobile web dashboard showing success rates, session counts, cost consumption, and active/completed sessions
Architecture
High-Level Components
GitHub Webhooks → FastAPI Backend → Devin API
↓
Telegram Bot ← FastAPI Backend ← Devin Sessions/Sessions/Metrics
↓
Next.js Mobile Dashboard
Backend (Python/FastAPI)
Main Components:
webhook_receiver.py- GitHub webhook handler for PRs and issuesdevin_client.py- Devin API client wrapper (sessions, PR reviews, metrics)telegram_bot.py- Telegram bot with two-way communicationscheduler.py- Scheduled task management using APSchedulerobservability.py- Real-time metrics fetching from Devin Analytics APIdatabase.py- PostgreSQL for job tracking, repository configuration, and user state
API Endpoints:
POST /webhooks/github- GitHub webhook receiverPOST /webhooks/telegram- Telegram webhook receiverGET /api/sessions- List active/completed sessionsPOST /api/sessions- Create new Devin sessionPOST /api/sessions/{id}/cancel- Cancel running sessionGET /api/metrics- Real-time observability metricsPOST /api/scheduled-tasks- Create scheduled taskGET /api/repositories- List configured repositories
Frontend (Next.js Mobile Web App)
Components:
Dashboard- Main mobile-optimized dashboardSessionList- Active vs completed sessions viewMetricsCard- Success rates, cost consumption, session countsRepositorySelector- Multi-repository selectionRealTimeUpdates- WebSocket or polling for real-time data
Mobile-First Design:
- Responsive layout optimized for mobile screens
- Touch-friendly interface
- Bottom navigation for key metrics
- Swipe gestures for session management
Devin API Integration
Key Endpoints Used:
POST /v3/organizations/{org_id}/sessions- Create sessionsGET /v3/organizations/{org_id}/sessions- List sessionsGET /v3/organizations/{org_id}/sessions/{id}- Get session detailsDELETE /v3/organizations/{org_id}/sessions/{id}- Terminate sessionsPOST /v3/organizations/{org_id}/pr-reviews- Trigger PR reviewsGET /v3/organizations/{org_id}/metrics/usage- Usage metricsGET /v3/organizations/{org_id}/consumption/daily- Daily ACU consumption
Telegram Integration Strategy
Two-Way Communication:
- Notifications → Telegram: Devin session status updates, completion notifications, error alerts
- Commands → Backend: Telegram commands to control sessions and query status
Chat Topic Organization:
- Each GitHub repository maps to a specific Telegram chat topic
- Repository configuration stored in database with topic mapping
- Messages routed to appropriate topic based on repository context
Telegram Commands:
/status- Show active sessions for current repo topic/cancel <session_id>- Cancel a running session/create <prompt>- Create new session with custom prompt/metrics- Show current metrics for repository/help- List available commands
GitHub Webhook Handling
PR Events:
pull_request(opened, synchronized) → Trigger Devin session or PR review- Extract PR URL, branch, commit details
- Create Devin session with repository context and PR review prompt
Issue Events:
issues(opened, labeled) → Trigger Devin session for issue resolution- Extract issue title, body, labels
- Create Devin session with issue context and development prompt
Webhook Security:
- Verify GitHub webhook signatures using HMAC-SHA256
- Store GitHub webhook secrets in environment variables
- Reject invalid signatures with 401 response
Multi-Repository Support
Database Schema:
repositories:
- id (UUID, primary key)
- github_repo_path (e.g., "owner/repo")
- telegram_chat_id (for topic mapping)
- telegram_topic_id (optional, for topics)
- devin_org_id (Devin organization ID)
- webhook_secret (GitHub webhook secret)
- created_at, updated_at
sessions:
- id (UUID, primary key)
- devin_session_id (Devin session ID)
- repository_id (foreign key)
- trigger_type (pr_review, issue, scheduled, manual)
- trigger_context (JSON with PR/issue details)
- status (pending, running, completed, failed, cancelled)
- prompt (used prompt)
- created_at, updated_at, completed_at
scheduled_tasks:
- id (UUID, primary key)
- repository_id (foreign key)
- cron_expression (APScheduler format)
- prompt (task prompt)
- devin_mode (normal, fast, lite, ultra, fusion)
- enabled (boolean)
- last_run_at, next_run_at
Scheduled Task Management
Using APScheduler:
- Python-based scheduler with cron-like expressions
- Persistent job storage in database
- Support for one-time and recurring tasks
- Automatic retry on failure
Task Configuration:
- Repository-specific scheduled tasks
- Custom prompts per task
- Devin mode selection (normal, fast, lite, ultra, fusion)
- Enable/disable functionality
Real-Time Observability
Metrics Sources:
-
Devin Usage Metrics API (
/v3/organizations/{org_id}/metrics/usage)- Session counts, active vs completed
- Time-range filtering capabilities
-
Devin Consumption API (
/v3/organizations/{org_id}/consumption/daily)- Daily ACU consumption (Enterprise plans only)
- Daily aggregated data (midnight PST boundaries)
- Flexible filtering and grouping
-
Session Status Tracking (local database)
- Real-time session status updates
- Success rate calculations
- Per-repository metrics
Real-Time Updates:
- WebSocket connection from Next.js dashboard to FastAPI backend
- Push-based updates when session status changes
- Fallback to polling (30-second intervals) if WebSocket unavailable
Dashboard Metrics:
- Success Rate: (completed sessions / total sessions) × 100
- Active Sessions: Count of sessions with status 'running'
- Completed Sessions: Count of sessions with status 'completed'
- Cost Consumption: Total ACUs from the consumption API
- Session Count: Total sessions per time period (day, week, month)
Development Approach
Phase 1: Core Backend Infrastructure
- Set up FastAPI project structure with proper dependencies
- Implement database schema and migrations (Alembic)
- Create Devin API client wrapper with authentication
- Implement GitHub webhook receiver with signature verification
- Set up basic Telegram bot with command handling
Phase 2: Devin Integration
- Implement session creation with repository context
- Add PR review triggering via Devin API
- Implement session status polling and updates
- Add session cancellation functionality
- Test end-to-end GitHub webhook → Devin session flow
Phase 3: Telegram Features
- Implement repository-to-Telegram topic mapping
- Add session status notifications to Telegram
- Implement Telegram commands for session control
- Add error handling and retry logic for Telegram API
- Test two-way communication flow
Phase 4: Scheduling
- Integrate APScheduler for task scheduling
- Implement scheduled task CRUD operations
- Add database persistence for scheduled tasks
- Implement scheduled task execution with Devin API
- Add scheduling UI controls (optional)
Phase 5: Observability Dashboard
- Set up Next.js project with mobile-first design
- Implement FastAPI WebSocket endpoint for real-time updates
- Create dashboard components for metrics display
- Integrate Devin Analytics API for cost data
- Add repository selector and filtering
- Implement real-time updates via WebSocket/polling
Phase 6: Testing & Deployment
- Add comprehensive unit tests for core components
- Implement integration tests for webhook flows
- Add error handling and logging throughout
- Set up environment configuration management
- Create deployment documentation
Technology Stack
Backend
- Framework: FastAPI (Python 3.11+)
- Database: PostgreSQL with SQLAlchemy ORM
- Task Scheduling: APScheduler
- HTTP Client: httpx for async Devin API calls
- Telegram: python-telegram-bot library
- WebSockets: FastAPI WebSocket support
- Environment: python-dotenv for configuration
Frontend
- Framework: Next.js 14+ with App Router
- Styling: Tailwind CSS for mobile-first design
- Real-time: Native WebSocket client or SWR for polling
- Charts: Recharts or Chart.js for metrics visualization
- State Management: React Context or Zustand
DevOps
- Containerization: Docker for both backend and frontend
- Process Management: systemd or Docker Compose
- Reverse Proxy: Nginx for production deployment
- SSL: Let's Encrypt for HTTPS
Configuration Required
Environment Variables
# Devin API
DEVIN_API_KEY=cog_xxxxxxxxxxxx
DEVIN_ORG_ID=org-xxxxxxxxxxxxx
# GitHub
GITHUB_WEBHOOK_SECRET=your_webhook_secret
GITHUB_TOKEN=your_personal_access_token
# Telegram
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_main_chat_id
# Database
DATABASE_URL=postgresql://user:password@localhost/devinbot
# Application
APP_BASE_URL=https://your-domain.com
LOG_LEVEL=INFO
Devin Service User Permissions
UseDevinSessions- Create and manage sessionsImpersonateOrgSessions- Create sessions on behalf of users (if needed)UseReviewManual- Trigger PR reviewsViewOrgMetrics- Access usage metricsViewOrgConsumption- Access daily ACU consumption
Security Considerations
- Webhook Verification: Always verify GitHub webhook signatures
- API Key Security: Store Devin API keys in environment variables, never commit to git
- Telegram Security: Validate chat IDs and implement access control
- Rate Limiting: Implement rate limiting for public endpoints
- Input Validation: Validate all user inputs and webhook payloads
- Database Security: Use parameterized queries, never string concatenation
- HTTPS Only: Force HTTPS in production for all communications
Error Handling Strategy
- Webhook Errors: Return appropriate HTTP status codes, log errors, retry on transient failures
- Devin API Errors: Implement exponential backoff, handle rate limits (429), log detailed errors
- Telegram Errors: Implement retry logic for failed message sends, log delivery failures
- Database Errors: Use transactions, implement connection pooling, handle connection failures
- Scheduler Errors: Log task failures, implement retry logic, alert on repeated failures
Logging & Monitoring
- Structured Logging: Use JSON-formatted logs with correlation IDs
- Log Levels: DEBUG for development, INFO for production, ERROR for failures
- Key Events: Webhook receipts, session creation, status changes, errors
- Metrics: Track API call counts, response times, error rates
- Alerts: Alert on repeated failures, high error rates, service unavailability
Development Guidelines for Coding Agents
- Start with database schema: Implement the core data model first
- Test Devin API integration: Verify API credentials and permissions before building complex flows
- Implement webhook security early: Don't skip signature verification
- Use async/await consistently: FastAPI and httpx work best with async patterns
- Modular design: Keep components loosely coupled for easier testing and maintenance
- Error-first thinking: Handle errors at each integration point before happy path
- Mobile-first frontend: Design for mobile screens from the start, not as an afterthought
- Real-time considerations: Plan for WebSocket connection management and reconnection logic
- Configuration management: Use environment variables for all configurable values
- Documentation: Keep code well-documented with docstrings and comments
Testing Strategy
- Unit Tests: Test individual functions and classes in isolation
- Integration Tests: Test webhook flows, Devin API calls, database operations
- End-to-End Tests: Test complete workflows from GitHub webhook to Telegram notification
- Load Testing: Test webhook handling under high load
- Manual Testing: Test Telegram bot commands and dashboard UX
Deployment Checklist
- Set up PostgreSQL database with proper backup strategy
- Configure environment variables in production
- Set up SSL certificates with Let's Encrypt
- Configure Nginx reverse proxy
- Set up process monitoring (systemd or Docker)
- Configure log rotation and retention
- Set up monitoring and alerting
- Test webhook delivery from GitHub
- Test Telegram bot functionality
- Verify real-time dashboard updates
Future Enhancements
- Slack Integration: Add Slack as an alternative to Telegram
- Advanced Scheduling: UI for creating complex scheduled tasks
- Custom Playbooks: Allow users to select Devin playbooks for tasks
- Session Templates: Pre-defined prompts for common tasks
- Cost Optimization: Suggestions for reducing Devin costs
- Multi-User Support: Extend beyond one-man developer use case
- Analytics Export: Export metrics data for external analysis
- Webhook Replay: Replay failed webhooks for debugging
