vBot-2.1 / SERVER_SETUP.md
Ajit Panday
Clarify database architecture: call_records table only on FreePBX side
52ab21e
# vBot Central Server Setup Guide
## Overview
This guide provides detailed instructions for setting up the central vBot server that handles call transcription and analysis. The central server is deployed on Hugging Face Space and manages customer accounts, API keys, and webhook delivery.
## Prerequisites
- Hugging Face account
- MySQL database (version 5.7 or higher)
- Python 3.8 or higher
- Git
## Step 1: Deploy to Hugging Face Space
1. Create a new Space:
- Go to https://huggingface.co/spaces
- Click "New Space"
- Choose "Gradio" as the SDK
- Set the Space name (e.g., "vBot")
- Set visibility (public/private)
2. Clone the repository:
```bash
git clone https://huggingface.co/spaces/iajitpanday/vBot
cd vBot
```
3. Configure environment variables:
```bash
cp .env.example .env
# Edit .env with your configuration
```
4. Required environment variables:
```bash
DATABASE_URL=mysql://user:password@host:port/database
SECRET_KEY=your-secret-key
API_BASE_URL=https://your-space.huggingface.space
```
5. Push to Hugging Face:
```bash
git add .
git commit -m "Initial deployment"
git push
```
## Step 2: Database Setup
1. Create the database:
```sql
CREATE DATABASE vbot_central;
USE vbot_central;
```
2. Create required tables:
```sql
CREATE TABLE customers (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
company_name VARCHAR(255),
email VARCHAR(255) NOT NULL,
api_key VARCHAR(64) NOT NULL UNIQUE,
webhook_url VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
```
## Step 3: Admin Setup
1. Access the admin interface:
- URL: `https://your-space.huggingface.space/admin`
- Default credentials: admin/admin
2. Change admin password:
- Click "Change Password"
- Enter new secure password
- Save changes
3. Create first customer:
- Click "Add Customer"
- Fill in customer details
- System will generate API key
- Save customer information
## Step 4: API Configuration
1. Verify API endpoints:
```bash
curl https://your-space.huggingface.space/health
```
2. Test customer API:
```bash
curl -X POST https://your-space.huggingface.space/api/process-call \
-H "X-API-Key: customer-api-key" \
-H "Content-Type: multipart/form-data" \
-F "file=@test.wav" \
-H "caller_number=+1234567890" \
-H "called_number=+0987654321"
```
## Step 5: Security Setup
1. Configure SSL:
- Hugging Face Spaces provides SSL by default
- Verify SSL certificate is valid
2. API Security:
- All API endpoints require valid API key
- Implement rate limiting
- Validate input data
- Sanitize output data
3. Webhook Security:
- Require HTTPS for webhook URLs
- Validate webhook signatures
- Implement retry mechanism
- Log webhook delivery attempts
## Step 6: Monitoring Setup
1. Log Configuration:
```bash
# Application logs
tail -f logs/app.log
# Error logs
tail -f logs/error.log
# Access logs
tail -f logs/access.log
```
2. Health Monitoring:
- Set up health check endpoint
- Monitor API response times
- Track webhook delivery success
- Monitor database performance
## Step 7: Maintenance
1. Regular Tasks:
- Monitor system logs
- Check API performance
- Verify webhook delivery
- Review security logs
2. Backup Strategy:
- Regular database backups
- Configuration backups
- Log rotation
- API key rotation
3. Update Process:
```bash
# Update code
git pull
# Update dependencies
pip install -r requirements.txt
# Restart application
```
## Troubleshooting
1. Common Issues:
- API authentication failures
- Webhook delivery failures
- Database connection issues
- Performance problems
2. Debug Tools:
```bash
# Check application logs
tail -f logs/app.log
# Check error logs
tail -f logs/error.log
# Check database connection
mysql -u user -p vbot_central
```
3. Support:
- Check documentation
- Review logs
- Contact support
- Submit issues
## Security Best Practices
1. API Security:
- Use strong API keys
- Implement rate limiting
- Validate all inputs
- Sanitize all outputs
2. Database Security:
- Use strong passwords
- Limit database access
- Regular backups
- Encryption at rest
3. Webhook Security:
- Require HTTPS
- Validate signatures
- Implement retries
- Monitor delivery
## Performance Optimization
1. API Optimization:
- Implement caching
- Optimize database queries
- Use connection pooling
- Monitor response times
2. Webhook Optimization:
- Implement queue system
- Use async processing
- Monitor delivery times
- Handle failures gracefully
3. Database Optimization:
- Index frequently queried columns
- Optimize table structure
- Regular maintenance
- Monitor performance