# Quick Setup Guide

## Prerequisites
- PHP 8.2+
- Composer
- MySQL/PostgreSQL
- Twilio Account

## Installation Steps

1. **Install Dependencies**
   ```bash
   composer install
   ```

2. **Environment Setup**
   ```bash
   cp .env.example .env
   php artisan key:generate
   ```

3. **Configure Database**
   Edit `.env` and set your database credentials:
   ```env
   DB_CONNECTION=mysql
   DB_HOST=127.0.0.1
   DB_DATABASE=twilio_chatbot
   DB_USERNAME=root
   DB_PASSWORD=your_password
   ```

4. **Configure Twilio**
   Edit `.env` and add your Twilio credentials:
   ```env
   TWILIO_ACCOUNT_SID=your_account_sid
   TWILIO_AUTH_TOKEN=your_auth_token
   TWILIO_WHATSAPP_FROM=whatsapp:+1234567890
   TWILIO_WHATSAPP_SANDBOX_NUMBER=whatsapp:+14155238886
   TWILIO_WEBHOOK_TOKEN=your_webhook_token
   ```

5. **Run Migrations**
   ```bash
   php artisan migrate
   ```

6. **Seed Database (Optional)**
   ```bash
   php artisan db:seed
   ```
   This creates a default admin user:
   - Email: `admin@example.com`
   - Password: `password`

7. **Start Queue Worker**
   ```bash
   php artisan queue:work
   ```
   Keep this running in a separate terminal.

8. **Start Development Server**
   ```bash
   php artisan serve
   ```

9. **Access Admin Panel**
   - URL: `http://localhost:8000/admin/login`
   - Login with the seeded credentials

## Twilio Webhook Configuration

1. Go to Twilio Console → WhatsApp Sandbox
2. Set webhook URL: `https://yourdomain.com/api/webhook/twilio/incoming`
3. Set status callback: `https://yourdomain.com/api/webhook/twilio/status`
4. Copy the webhook token to `.env` as `TWILIO_WEBHOOK_TOKEN`

## Testing

1. Send a WhatsApp message to your Twilio sandbox number
2. Check the admin panel for incoming messages
3. Create a flow in the admin panel
4. Test the conversation flow

## Production Deployment

1. Set `APP_ENV=production` and `APP_DEBUG=false`
2. Run `php artisan config:cache` and `php artisan route:cache`
3. Set up Supervisor for queue worker
4. Configure SSL for webhook endpoints
5. Set up database backups
