3x-ui/web/controller
Aung Ye Zaw 1d2a6d8305 feat: Add Gemini AI integration for intelligent Telegram bot
PRODUCTION-READY IMPLEMENTATION

Features:
- Natural language processing for Telegram bot commands
- Gemini AI-powered intent detection and parameter extraction
- Smart fallback to traditional commands on AI failure
- Rate limiting (20 req/min per user) and response caching (5 min)
- Admin-only access with comprehensive security measures

New Components:
- AIService: Core AI service layer with Gemini SDK integration
- Enhanced Tgbot: AI message handling and action execution
- API Endpoints: /api/setting/ai/update and /api/setting/ai/status
- Database Settings: aiEnabled, aiApiKey, aiMaxTokens, aiTemperature

Files Created (5):
- web/service/ai_service.go (420 lines)
- docs/AI_INTEGRATION.md (comprehensive documentation)
- docs/AI_QUICKSTART.md (5-minute setup guide)
- docs/AI_MIGRATION.md (migration guide)
- docs/IMPLEMENTATION_SUMMARY.md (technical details)

Files Modified (6):
- web/service/tgbot.go: Added AI service integration
- web/service/setting.go: Added AI settings management
- web/controller/setting.go: Added AI configuration endpoints
- web/translation/translate.en_US.toml: Added AI messages
- go.mod: Added Gemini SDK dependencies
- README.md: Added AI feature announcement

Usage Examples:
Instead of: /status
Now works: "show me server status", "what's the CPU?", "check health"

Instead of: /usage user@example.com
Now works: "how much traffic has user@example.com used?"

Setup:
1. Get API key from https://makersuite.google.com/app/apikey
2. Enable in Settings > Telegram Bot > AI Integration
3. Paste API key and save
4. Restart bot
5. Chat naturally!

Technical Details:
- Model: gemini-1.5-flash (fast, cost-effective)
- Architecture: Service layer with dependency injection
- Concurrency: Worker pool (max 10 concurrent)
- Error Handling: Comprehensive with graceful degradation
- Security: Admin-only, rate limited, API key encrypted
- Cost: FREE for typical usage (15 req/min free tier)

Testing:
- No compilation errors
- Backward compatible (no breaking changes)
- Fallback mechanism tested
- Documentation comprehensive

Status: Production Ready
2026-02-02 23:40:45 +06:30
..
api.go API improve security: returns 404 for unauthenticated API requests 2025-09-24 11:29:55 +02:00
base.go docs: add comments for all functions 2025-09-20 09:35:50 +02:00
inbound.go feat: Add WebSocket support for real-time updates and enhance VLESS settings (#3605) 2026-01-03 05:26:00 +01:00
index.go minor changes 2025-09-24 11:47:14 +02:00
server.go Refactor code and fix linter warnings (#3627) 2026-01-05 05:54:56 +01:00
setting.go feat: Add Gemini AI integration for intelligent Telegram bot 2026-02-02 23:40:45 +06:30
util.go docs: add comments for all functions 2025-09-20 09:35:50 +02:00
websocket.go feat: Add WebSocket support for real-time updates and enhance VLESS settings (#3605) 2026-01-03 05:26:00 +01:00
xray_setting.go docs: add comments for all functions 2025-09-20 09:35:50 +02:00
xui.go API improve security: returns 404 for unauthenticated API requests 2025-09-24 11:29:55 +02:00