An intelligent Slack bot with modular AI capabilities built on a scalable microservice architecture.
┌─────────────────┐ HTTP API ┌─────────────────┐
│ Slack Bot │ ◄──────────────► │ AI Microservice │
│ (Port 8000) │ │ (Port 8001) │
│ │ │ │
│ • Slack Events │ │ • NL2SQL │
│ • User Auth │ │ • Code Gen │
│ • Responses │ │ • General Chat │
└─────────────────┘ └─────────────────┘
- Modularity: Independent AI and Slack services
- Scalability: Scale AI processing independently
- Maintainability: Update AI without touching Slack code
- Flexibility: Easy AI provider swapping
- Docker & Docker Compose
- OpenAI API Key
- Slack App credentials
cp env.example .env
# Edit .env with your credentialsdocker-compose up --build- Slack Bot: http://localhost:8000/health
- AI Service: http://localhost:8001/health
- API Docs: http://localhost:8001/docs
# Slack Configuration
SLACK_BOT_TOKEN=<SLACK_TOKEN>
SLACK_SIGNING_SECRET=your-signing-secret
# AI Configuration
OPENAI_API_KEY=your-openai-key
# Authentication (Optional)
AUTH_URL=your-auth-url
AUTH_API_KEY=your-auth-key
# Database (Optional - for NL2SQL)
DATABASE_URL=postgresql://user:password@localhost:5432/dbnameThe AI microservice provides RESTful endpoints:
POST /api/v1/ai/process- Main AI routingPOST /api/v1/nl2sql/convert- Natural Language to SQLPOST /api/v1/code/generate- Code generationPOST /api/v1/chat/respond- General conversationGET /health- Health checkGET /docs- Interactive API documentation
/hello- Get a personalized greeting from the bot/ai [question]- Ask AI anything (automatically routes to appropriate service)/test-executions [test_id] [limit]- View test execution history/connect-slack- Connect your Slack workspace
The bot automatically routes your requests to the most appropriate AI service:
-
General Chat
- Natural dialogue and conversation
- Question answering and explanations
- Creative brainstorming
- Problem discussion
- Knowledge in science, technology, history, and more
-
Code Generation
- Generate code in multiple languages:
- Python, JavaScript, TypeScript
- Java, Go, Rust
- C++, C#, SQL
- Features:
- Function and class generation
- Algorithm implementation
- API client code
- Data processing scripts
- Test code generation
- Code documentation
- Generate code in multiple languages:
-
NL2SQL (Database Queries)
- Convert natural language to SQL queries
- Supported operations:
- Filtering by test_uid, status, execution_time
- Time-based queries (last week, yesterday, etc.)
- Status filtering (failed, passed, etc.)
- Results in formatted tables
- Safety features:
- SQL injection prevention
- Read-only operations
- Query validation
# General Questions
/ai What is machine learning?
/ai Explain REST APIs to me
# Database Queries
/ai Show me failed tests from yesterday
/ai Count how many tests passed this week
# Code Generation
/ai Write a Python function to calculate fibonacci numbers
/ai Create a JavaScript function that validates emails
# Test Executions
/test-executions TEST_ID 5
/test-executions TEST_ID limit=10
python test_microservice_architecture.pypytest tests/The application is deployed using Docker containers and Cloudflare tunnels for secure connectivity.
├── src/ # Main Slack bot service
│ ├── bot/ # Slack event handling
│ ├── services/ # HTTP client for AI service
│ └── config/ # Configuration
├── ai-microservice/ # Independent AI service
│ ├── src/
│ │ ├── api/ # REST API endpoints
│ │ ├── services/ # AI processing services
│ │ └── models/ # Request/response models
│ └── Dockerfile
├── tests/ # Unit tests
├── scripts/ # Database setup scripts
└── docs/ # Documentation
The microservice architecture makes it easy to add new AI capabilities:
- Add Service: Create new service in
ai-microservice/src/services/ - Register: Add to
AIRouterServiceinai_router_service.py - API Endpoint: Add REST endpoint in
api/routes.py - Deploy: Restart AI microservice only
- Architecture: MICROSERVICE_ARCHITECTURE.md
- API Docs: http://localhost:8001/docs (when running)
- Deployment: docs/deployment.md
# Start main bot only
cd src && python -m uvicorn main:app --reload --port 8000
# Start AI service only
cd ai-microservice && python -m uvicorn src.main:app --reload --port 8001- Slack Features: Modify
src/directory - AI Features: Modify
ai-microservice/directory - Independent deployment of each service
- Fork the repository
- Create feature branch
- Make changes to appropriate service
- Test with
test_microservice_architecture.py - Submit pull request
MIT License - see LICENSE file for details.
Built with ❤️ using FastAPI, Docker, and OpenAI