# VAPI OpenAI Realtime API Setup

## Current State Analysis
- VAPI API keys exist in `/root/.clawdbot/secrets.json`
- OpenAI API key exists in `/root/.clawdbot/.env`
- VAPI webhook endpoint exists at `/api/vapi/webhook` in the Growth Engine
- Phone numbers: +61 468 087 171 and +61 426 246 472
- VAPI SDK is installed in package.json
- Database schema for vapi_tasks exists

## What Needs to Be Done

### 1. Create VAPI Assistant Configuration
Create a script to set up a VAPI assistant using OpenAI Realtime API with:
- Model: `gpt-realtime-2025-08-28` (production-ready)
- Voice: Australian male voice (OpenAI's `alloy` or `echo` for male voice)
- System prompt with RateRight context
- Webhook URL configured to point to Growth Engine

### 2. RateRight Context for Natural Conversations
The assistant should know:
- RateRight is a construction hiring marketplace
- $50 flat fee per hire (employers pay, workers pay nothing)
- Connects contractors with workers in Australia
- Focus on construction industry (builders, tradies, laborers)
- Can answer questions about how it works, pricing, signup process

### 3. Configuration Files
Create configuration files in `/home/ccuser/rateright-growth/phone-ai/`:
- `vapi-config.json` - Assistant configuration
- `setup-vapi.js` - Script to create/update VAPI assistant
- `.env` - Environment variables for VAPI

### 4. Test Configuration
Test the setup by:
1. Creating the assistant via VAPI API
2. Making a test call to verify natural conversation
3. Ensuring webhooks are received correctly

## Steps Taken

### Step 1: Created phone-ai directory structure
```bash
mkdir -p /home/ccuser/rateright-growth/phone-ai
```

### Step 2: Created environment configuration
Created `.env` file with:
- VAPI API keys from `/root/.clawdbot/secrets.json`
- OpenAI API key from `/root/.clawdbot/.env`
- Webhook URL to Growth Engine
- Phone numbers: +61 468 087 171 and +61 426 246 472

### Step 3: Created VAPI assistant configuration
Created `vapi-config.json` with:
- OpenAI Realtime model: `gpt-realtime-2025-08-28`
- Voice: `alloy` (OpenAI male voice)
- System prompt with RateRight context
- Temperature: 0.7 for natural conversation
- Max tokens: 250 for concise responses
- Webhook configured to Growth Engine endpoint

### Step 4: Created setup script
Created `setup-vapi.js` to:
- Programmatically create/update VAPI assistant
- Assign phone numbers to assistant
- Test configuration
- Provide detailed feedback

### Step 5: Created test script
Created `test-vapi.js` to:
- Test VAPI API connection
- List existing assistants and phone numbers
- Check for RateRight assistant
- Verify configuration

### Step 6: Created README documentation
Created comprehensive README with:
- Setup instructions
- Configuration details
- Testing procedures
- Troubleshooting guide

## Assistant Configuration Details

### Model Configuration
- Provider: `openai`
- Model: `gpt-realtime-2025-08-28`
- Temperature: 0.7 (for natural conversation)
- Max tokens: 250 (for concise responses)

### Voice Configuration
- Provider: `openai`
- Voice: `alloy` (natural-sounding male voice)
- Alternative: `echo` (also male-sounding)

### System Prompt
The assistant should:
1. Be friendly and conversational
2. Know about RateRight's business model
3. Answer questions naturally, not like a script
4. Ask clarifying questions when needed
5. Sound like a helpful Australian assistant

### Webhook Configuration
- URL: `https://rateright-growth-production.up.railway.app/api/vapi/webhook`
- Events: `end-of-call-report` (for task parsing)

## Notes
- OpenAI Realtime API handles speech-to-speech natively (no separate STT/TTS)
- Only certain OpenAI voices work with Realtime API (`alloy`, `echo`, `shimmer`, `marin`, `cedar`)
- Voice `alloy` is a natural-sounding male voice suitable for Australian context
- The assistant should be configured for natural conversation, not task-oriented only