WhatsApp AI Bot dengan Flask: Transkripsi, Analisis & Dashboard

# 🤖 WhatsApp AI Bot + Flask Dashboard
Powerful WhatsApp bot dengan fitur AI (transcription, summarization, media analysis) dan dashboard web yang responsive untuk monitoring dan analytics.
## ✨ Fitur Utama
### 🤖 Bot WhatsApp Features
- **Universal Media Downloader**: Support 1000+ platform (YouTube, TikTok, Instagram, Facebook, dll)
- **AI Processing**:
- Audio transcription menggunakan Gemini AI
- Content summarization
- Media analysis (image, video, audio)
- YouTube content analysis untuk SEO
- **Smart Commands**:
- `mp3`, `video` - Download media
- `transcribe`, `summary`, `analyze` - AI processing
- `smart` - Full AI analysis
- `ytvideo`, `ytaudio` - YouTube analysis
- `ai` - Direct AI chat
### 📊 Dashboard Web Features
- **Real-time Analytics**: Live statistics dan monitoring
- **User Management**: Track user activity dan engagement
- **Command History**: Detailed command execution logs
- **Performance Metrics**: Response time, success rate, error analysis
- **Mobile Responsive**: Optimized untuk semua device
- **Interactive Charts**: Visualisasi data yang menarik
## 🚀 Quick Start
### Prerequisites
```bash
# Install Python 3.8+
python --version
# Install yt-dlp
pip install yt-dlp
# Install FFmpeg (for audio processing)
# Windows: Download from https://ffmpeg.org/
# Ubuntu: sudo apt install ffmpeg
# macOS: brew install ffmpeg
```
### Installation
1. **Clone dan Setup**
```bash
git clone <repository-url>
cd whatsapp-ai-bot-dashboard
pip install -r requirements.txt
```
2. **Konfigurasi**
```bash
# Copy dan edit file konfigurasi
cp config.example.py config.py
```
Edit `config.py`:
```python
# Gemini AI API Key
GEMINI_API_KEY = "your-gemini-api-key-here"
# Database path
DATABASE_PATH = "bot_analytics.db"
# Flask settings
FLASK_HOST = "0.0.0.0"
FLASK_PORT = 5000
FLASK_DEBUG = False
```
3. **Setup Database**
```bash
python setup_db.py
```
4. **Run Application**
```bash
python app.py
```
Dashboard akan tersedia di: http://localhost:5000
## 📱 WhatsApp Bot Commands
### Basic Commands
```
ping - Test bot responsiveness
help - Show all commands
info <URL> - Get media information
```
### Download Commands
```
mp3 <URL> - Download audio (MP3)
video <URL> [quality] - Download video (720p default)
audio <URL> - Same as mp3
vid <URL> - Same as video
```
Quality options: `worst`, `480p`, `720p`, `1080p`, `best`
### AI Commands
```
transcribe <URL> - Audio transcription
summary <URL> - AI content summary
analyze <URL> - Full media analysis
smart <URL> - Download + transcribe + summary
ai <question> - Direct AI chat
```
### YouTube Analysis
```
ytvideo <URL> - Analyze video for YouTube SEO
ytaudio <URL> - Analyze audio for YouTube SEO
```
### Quoted Media Commands
```
# Reply to audio/video message:
transcribe - Transcribe quoted media
analyze - Analyze quoted media
```
## 🌐 Supported Platforms
✅ **Video Platforms**
- YouTube, TikTok, Instagram Reels
- Facebook Videos, Twitter Videos
- Vimeo, Dailymotion, Twitch Clips
✅ **Audio Platforms**
- SoundCloud, Spotify (preview)
- YouTube Music, Bandcamp
✅ **Social Media**
- Instagram Posts, Facebook Posts
- Twitter Threads, Reddit Videos
Dan 1000+ platform lainnya melalui yt-dlp!
## 📊 Dashboard Pages
### 1. **Main Dashboard** (`/`)
- Live statistics
- Activity trends (7-day chart)
- Command distribution
- Top platforms & users
- Real-time activity feed
### 2. **User Management** (`/users`)
- User list dengan search & filter
- User activity tracking
- User details modal
- Export user data
### 3. **Command History** (`/commands`)
- Detailed command logs
- Real-time updates
- Filter by command/status/platform
- Performance metrics
### 4. **Advanced Analytics** (`/analytics`)
- Deep performance analysis
- Response time distribution
- Error analysis
- User engagement metrics
- Data transfer statistics
## 🎨 UI Features
### Design
- **Modern Design**: Tailwind CSS dengan gradient backgrounds
- **Responsive**: Mobile-first design
- **Dark/Light**: Auto theme detection
- **Icons**: Font Awesome icons
- **Animations**: Smooth transitions dan loading states
### Charts & Visualizations
- Line charts untuk trends
- Doughnut charts untuk distribution
- Bar charts untuk performance
- Real-time updating charts
### Mobile Experience
- Bottom navigation untuk mobile
- Swipe gestures
- Touch-optimized controls
- Progressive Web App (PWA) ready
## ⚙️ Configuration
### Environment Variables
```bash
# .env file
GEMINI_API_KEY=your_api_key_here
FLASK_ENV=production
DATABASE_URL=sqlite:///bot_analytics.db
SECRET_KEY=your_secret_key_here
```
### Bot Settings
```python
# config.py
BOT_CONFIG = {
"auto_cleanup": True,
"cleanup_interval": 24, # hours
"max_file_size": 64 * 1024 * 1024, # 64MB
"supported_formats": ["mp3", "mp4", "webm", "m4a"],
"ai_features": {
"transcription": True,
"summarization": True,
"analysis": True,
"youtube_seo": True
}
}
```
## 🔧 Development
### Project Structure
```
whatsapp-ai-bot-dashboard/
├── app.py # Main application
├── requirements.txt # Dependencies
├── config.py # Configuration
├── setup_db.py # Database setup
├── templates/ # HTML templates
│ ├── dashboard.html
│ ├── users.html
│ ├── commands.html
│ └── analytics.html
├── static/ # Static files
│ ├── css/
│ ├── js/
│ └── images/
├── downloads/ # Downloaded files
├── temp_media/ # Temporary files
└── logs/ # Log files
```
### Adding New Features
1. **New Command**
```python
# Add to handle_message function
elif command == "newcommand":
# Your command logic
analytics.log_command(user_phone, 'newcommand', 'System', None, 'success', response_time)
```
2. **New Analytics**
```python
# Add to BotAnalytics class
def get_new_metric(self):
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
# Your query
conn.close()
return result
```
3. **New Dashboard Page**
```python
@app.route('/newpage')
def new_page():
data = analytics.get_new_metric()
return render_template('newpage.html', data=data)
```
## 📈 Performance Tips
### Bot Optimization
- Use `worst` quality untuk analysis (faster)
- Enable auto-cleanup untuk save storage
- Limit concurrent downloads
- Cache AI responses
### Dashboard Optimization
- Enable gzip compression
- Use CDN untuk static files
- Implement pagination untuk large datasets
- Add database indexing
## 🛡️ Security
### Bot Security
- Validate all URLs
- Sanitize user inputs
- Rate limiting
- File type validation
### Web Security
- CSRF protection
- XSS prevention
- SQL injection protection
- Secure session management
## 🚨 Troubleshooting
### Common Issues
**Bot tidak respond**
```bash
# Check logs
tail -f logs/bot.log
# Restart bot
python app.py
```
**Download gagal**
```bash
# Update yt-dlp
pip install --upgrade yt-dlp
# Check platform support
yt-dlp --list-extractors | grep platform
```
**AI error**
```bash
# Check API key
echo $GEMINI_API_KEY
# Test API
curl -H "Authorization: Bearer $GEMINI_API_KEY" https://api.gemini.com/test
```
### Logs Location
- Bot logs: `logs/bot.log`
- Flask logs: `logs/web.log`
- Error logs: `logs/error.log`
## 🤝 Contributing
1. Fork repository
2. Create feature branch: `git checkout -b feature/amazing-feature`
3. Commit changes: `git commit -m 'Add amazing feature'`
4. Push branch: `git push origin feature/amazing-feature`
5. Open Pull Request
## 📄 License
MIT License - lihat file LICENSE untuk detail.
## 🙏 Credits
- **neonize**: WhatsApp client library
- **yt-dlp**: Universal media downloader
- **Gemini AI**: AI processing
- **Chart.js**: Data visualization
- **Tailwind CSS**: UI framework
- **Font Awesome**: Icons
## 📞 Support
- Issues: [GitHub Issues](https://github.com/your-repo/issues)
- Discussions: [GitHub Discussions](https://github.com/your-repo/discussions)
- Email: [email protected]
---
**⚡ Happy Coding!** 🚀