A secure Telegram bot that integrates with Claude Code CLI for SRE operations, providing intelligent assistance for Kubernetes, ArgoCD, Jira, GitHub, Datadog, and more.
- Claude Code Integration: Spawns Claude Code CLI processes for each conversation
- Per-Chat Isolation: Each Telegram group gets its own isolated session and workspace
- 2-Hour Context Expiry: Automatic cleanup of inactive sessions after 2 hours
- Security First: Output sanitization to prevent credential leakage
- MCP Server Support: Pre-configured access to Kubernetes, ArgoCD, Jira, GitHub, Datadog, Slack, and Telegram
- Context Validation: Ensures queries relate to SRE operations
- Group-Only Access: Bot only responds in Telegram groups/channels (not private messages)
- Expandable: Platform abstraction layer ready for future Slack integration
- Go 1.22 or higher
- Docker and Docker Compose (for containerized deployment)
- Telegram Bot Token (from @BotFather)
- Anthropic API Key (for Claude Code CLI)
- Configured Claude Code environment (with MCP servers)
- Open Telegram and search for @BotFather
- Send
/newbotand follow the instructions - Save the bot token provided
Copy the example environment file:
cp .env.example .envEdit .env and set your credentials:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
ANTHROPIC_API_KEY=your_anthropic_api_key_hereEdit configs/config.yaml:
claude:
cli_path: "/usr/local/bin/claude-code"
project_path: "/path/to/claude/workspace" # Path to your Claude workspace
query_timeout: "5m"
max_concurrent_sessions: 20
context:
ttl: "2h"
cleanup_interval: "5m"
validation_enabled: true
storage:
db_path: "./data/bot.db"# Build and start the bot
docker-compose up -d
# View logs
docker-compose logs -f bot
# Stop the bot
docker-compose down- Add your bot to a Telegram group or channel
- Grant the bot permission to read messages
- Send a message to test:
What pods are running in production?
# Install dependencies
go mod download
# Run migrations
mkdir -p data
sqlite3 data/bot.db < migrations/001_initial_schema.sql
# Run the bot
go run cmd/bot/main.go# Build for your platform
go build -o bot cmd/bot/main.go
# Build for Linux
GOOS=linux GOARCH=amd64 go build -o bot-linux cmd/bot/main.go
# Run the binary
./botaiops/
├── cmd/
│ └── bot/ # Main application entry point
├── internal/
│ ├── bot/ # Message handler and middleware
│ ├── claude/ # Claude CLI process management
│ ├── context/ # Context lifecycle and validation
│ ├── storage/ # SQLite database layer
│ ├── security/ # Output sanitization
│ ├── messaging/ # Platform abstraction (Telegram/Slack)
│ └── config/ # Configuration management
├── configs/ # Configuration files
├── migrations/ # Database migrations
├── Dockerfile # Docker build configuration
├── docker-compose.yml # Docker Compose setup
└── README.md # This file
The bot is configured via configs/config.yaml:
- telegram.token: Telegram bot token (can use env var
${TELEGRAM_BOT_TOKEN}) - claude.cli_path: Path to claude-code CLI binary
- claude.project_path: Path to Claude workspace with MCP servers
- claude.query_timeout: Maximum time for a query (default: 5m)
- claude.max_concurrent_sessions: Max concurrent chat sessions (default: 20)
- context.ttl: Session expiry time after last interaction (default: 2h)
- context.cleanup_interval: How often to check for expired sessions (default: 5m)
- context.validation_enabled: Whether to validate queries relate to SRE context
- storage.db_path: Path to SQLite database file
- security.secret_patterns: Regex patterns for credential detection
The bot requires a configured Claude Code environment with:
-
MCP Servers: Configured in
.mcp.json- Kubernetes
- ArgoCD
- Jira/Confluence (Atlassian)
- GitHub
- Datadog
- Slack
- Telegram
-
Context Files: For query validation
CLAUDE.md: Bot instructions and contextRUNBOOKS.md: SRE runbooks and proceduresRESOURCES.md: Tools, dashboards, and links
-
Permissions: Read-only access configured in
.claude/settings.json
- Create or open a Telegram group
- Add your bot as a member
- Ensure bot can read messages (group privacy settings)
- Send a message to the group
Kubernetes Operations:
What pods are running in the production namespace?
Show me logs for the payment-api deployment
Describe the nginx-ingress service
ArgoCD:
List all applications in ArgoCD
Show the sync status of payment-service
What resources are managed by the api-gateway app?
Jira:
Show me open incidents
What's the status of PROJ-123?
List issues in the current sprint
Datadog:
Show recent alerts
What monitors are currently firing?
Query logs for errors in the last hour
- Group/Channel Only: Bot ignores private messages
- Context Validation: Rejects unrelated queries with explanation
- Session Management: Each group gets isolated conversation context
- Auto-Expiry: Sessions expire after 2 hours of inactivity
- Security: All responses sanitized to remove credentials
The bot implements multiple security layers:
-
Output Sanitization: Regex-based filtering of:
- API keys
- Tokens
- Passwords
- Secrets
- Base64-encoded credentials
- JWT tokens
- Slack tokens
-
Read-Only Access: All MCP tools are configured as read-only
- kubectl get/describe/logs only
- Jira/GitHub read operations only
- No write/delete/modify permissions
-
Environment Isolation: Secrets never hardcoded
- Use environment variables
- Secrets stored outside workspaces
- Injected at runtime
-
Group-Only Access: Bot only works in groups/channels
- Prevents private misuse
- Better audit trail
-
Credential Management:
- Never commit
.envfiles - Use secret management tools (Vault, AWS Secrets Manager)
- Rotate credentials regularly
- Never commit
-
MCP Configuration:
- Use environment variables in
.mcp.json - Don't hardcode API tokens
- Example:
{ "mcpServers": { "argocd-mcp": { "env": { "ARGOCD_API_TOKEN": "${ARGOCD_API_TOKEN}" } } } }
- Use environment variables in
-
Access Control:
- Limit bot to specific groups
- Use Telegram group permissions
- Monitor bot usage via logs
The bot logs important events:
# View real-time logs
docker-compose logs -f bot
# View last 100 lines
docker-compose logs --tail=100 bot
# Search logs
docker-compose logs bot | grep ERRORInspect the SQLite database:
# Open database
sqlite3 data/bot.db
# Check active contexts
SELECT chat_id, created_at, expires_at FROM chat_contexts WHERE is_active = 1;
# View recent messages
SELECT chat_id, role, created_at FROM messages ORDER BY created_at DESC LIMIT 10;
# Check cleanup log
SELECT * FROM cleanup_log ORDER BY created_at DESC LIMIT 10;Key metrics to monitor:
- Active chat contexts:
SELECT COUNT(*) FROM chat_contexts WHERE is_active = 1; - Messages per chat:
SELECT chat_id, COUNT(*) FROM messages GROUP BY chat_id; - Tool executions:
SELECT tool_name, COUNT(*) FROM tool_executions GROUP BY tool_name;
- Check logs:
docker-compose logs bot - Verify bot is running:
docker-compose ps - Check chat type: Bot only works in groups/channels
- Test connection: Send
/startin the group
- Check claude-code is installed:
which claude-code - Verify API key:
echo $ANTHROPIC_API_KEY - Check project path: Ensure workspace exists and is accessible
- View process logs: Check stderr output in container logs
Normal behavior - sessions expire after 2 hours of inactivity:
- Simply send a new message to create a fresh session
- Previous conversation history is cleaned up automatically
If you see "database is locked" errors:
- Check for multiple bot instances running
- Ensure only one process accesses the database
- Restart the bot:
docker-compose restart bot
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run specific package tests
go test ./internal/storage/-
New MCP Server:
- Add to Claude workspace
.mcp.json - Update permissions in
.claude/settings.json - Restart bot to pick up changes
- Add to Claude workspace
-
Custom Validation:
- Edit
internal/context/validator.go - Add keywords or implement custom logic
- Edit
-
Response Formatting:
- Modify
internal/bot/response.go - Customize formatting functions
- Modify
- Slack integration
- Prometheus metrics
- Rate limiting per user
- Admin commands (
/stats,/cleanup) - Multi-language support
- Voice message support
- Context export/import
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions:
- Create an issue on GitHub
- Check existing documentation
- Review logs for error details
- Built with Claude Code
- Uses go-telegram-bot-api
- Inspired by SRE best practices