Skip to content

prompt-stack/vapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

VAPI Multi-Tenant Lead Generation System

A production-ready, multi-tenant voice AI system for automated lead qualification and appointment booking using VAPI.

πŸš€ Features

  • Multi-Tenant Architecture - Support unlimited clients with isolated configurations
  • Automated Lead Qualification - Smart scoring based on customizable rules
  • Google Sheets Integration - Automatic lead logging
  • Google Calendar Integration - Automated appointment booking
  • Comprehensive Testing - 60+ unit and integration tests
  • Modular Configuration - Edit prompts, rules, and settings without code changes
  • Production Ready - Built-in error handling, logging, and monitoring

🎯 Quick Start

Prerequisites

  • Node.js 18+
  • VAPI account (vapi.ai)
  • Google Cloud service account (for Sheets/Calendar)
  • ngrok account (for local development)

Installation

# 1. Clone and install
npm install

# 2. Configure environment
cp .env.example .env
# Edit .env with your credentials

# 3. Add Google credentials
# Place google-credentials.json in project root

# 4. Start server
npm start

# 5. (Development) Start with ngrok tunnel
npm run dev

First Client Setup

  1. Create VAPI Assistant:
node scripts/setup/setup-assistant.js
  1. Configure client in clients/demo-landscaping/config.json:

    • Add assistant ID from step 1
    • Update spreadsheet ID
    • Customize prompt in prompt.txt
  2. Test webhook:

curl -X POST http://localhost:8547/webhook \
  -H "Content-Type: application/json" \
  -d @scripts/testing/test-webhook.js

πŸ“ Project Structure

vapi/
β”œβ”€β”€ server.js                 # Main Express server
β”œβ”€β”€ .env                      # Environment variables
β”œβ”€β”€ .gitignore               # Git ignore rules
β”‚
β”œβ”€β”€ clients/                  # 🎯 Multi-tenant configs
β”‚   └── demo-landscaping/
β”‚       β”œβ”€β”€ config.json       # Client settings
β”‚       β”œβ”€β”€ prompt.txt        # Conversation prompt
β”‚       β”œβ”€β”€ qualification.json # Lead scoring rules
β”‚       └── tools.json        # Function definitions (NEW!)
β”‚
β”œβ”€β”€ routes/                   # Express routes (NEW!)
β”‚   └── webhook.js            # VAPI webhook handler
β”‚
β”œβ”€β”€ services/                 # Core business logic
β”‚   β”œβ”€β”€ clientManager.js      # Multi-tenant routing
β”‚   β”œβ”€β”€ leadProcessor.js      # Lead processing pipeline
β”‚   β”œβ”€β”€ qualifier.js          # Lead qualification
β”‚   β”œβ”€β”€ calendar.js           # Google Calendar API
β”‚   └── vapiAssistant.js      # VAPI API client
β”‚
β”œβ”€β”€ storage/                  # Storage adapters
β”‚   β”œβ”€β”€ index.js              # Storage factory
β”‚   β”œβ”€β”€ json.js               # JSON file storage
β”‚   └── googleSheets.js       # Google Sheets adapter
β”‚
β”œβ”€β”€ tests/                    # Test suites (60+ tests)
β”‚   β”œβ”€β”€ unit/                 # Unit tests
β”‚   └── integration/          # Integration tests
β”‚
β”œβ”€β”€ scripts/                  # Utility scripts
β”‚   β”œβ”€β”€ setup/                # Setup & configuration
β”‚   β”‚   β”œβ”€β”€ setup-assistant.js       # Create new assistant
β”‚   β”‚   └── update-assistant.js      # Update assistant config
β”‚   └── testing/              # Test utilities
β”‚
β”œβ”€β”€ docs/                     # Documentation
β”‚   β”œβ”€β”€ ARCHITECTURE-REFACTOR.md
β”‚   β”œβ”€β”€ FIELD-MAPPING.md
β”‚   └── ROADMAP.md
β”‚
β”œβ”€β”€ config/                   # Global configuration
β”œβ”€β”€ utils/                    # Utilities
└── data/                     # Local storage (JSON mode)

🌐 API Endpoints

POST /webhook

Main endpoint for VAPI callbacks. Automatically routes to correct client based on assistant ID.

GET /clients

Lists all configured clients with their settings.

GET /health

Health check showing loaded clients and system status.

GET /leads

View all leads (development only).

βš™οΈ Configuration

Client Configuration Structure

Each client has a dedicated folder in clients/ with four configuration files:

clients/your-client-name/
β”œβ”€β”€ config.json           # Main configuration
β”œβ”€β”€ prompt.txt            # Conversation prompt
β”œβ”€β”€ qualification.json    # Lead scoring rules
└── tools.json           # VAPI function definitions

Environment Variables

Create .env file in project root:

# Server
PORT=8547
NODE_ENV=development

# VAPI
VAPI_PRIVATE_KEY=your_private_key
VAPI_PUBLIC_KEY=your_public_key

# Google (optional, can be configured per-client)
GOOGLE_CREDENTIALS_PATH=./google-credentials.json

Client config.json

{
  "clientId": "your-client-id",
  "name": "Your Business Name",
  "businessType": "service",

  "assistant": {
    "id": "vapi-assistant-id",
    "phoneNumber": null,
    "promptFile": "./prompt.txt",
    "firstMessage": "Hi! Thanks for calling..."
  },

  "services": ["service1", "service2"],

  "qualification": {
    "rulesFile": "./qualification.json",
    "minScore": 8
  },

  "storage": {
    "type": "googleSheets",
    "spreadsheetId": "your_sheet_id",
    "sheetName": "Sheet1",
    "credentialsPath": "google-credentials.json"
  },

  "calendar": {
    "enabled": true,
    "calendarId": "your@email.com",
    "credentialsPath": "../../google-credentials.json",
    "defaultDuration": 60,
    "timezone": "America/New_York",
    "businessHours": {
      "monday": ["09:00-17:00"],
      "tuesday": ["09:00-17:00"],
      "wednesday": ["09:00-17:00"],
      "thursday": ["09:00-17:00"],
      "friday": ["09:00-17:00"],
      "saturday": [],
      "sunday": []
    }
  }
}

Storage Options

JSON (Local):

"storage": {
  "type": "json"
}

Google Sheets:

"storage": {
  "type": "googleSheets",
  "spreadsheetId": "your_sheet_id",
  "sheetName": "Sheet1",
  "credentialsPath": "google-credentials.json"
}

Airtable (Coming Soon):

"storage": {
  "type": "airtable",
  "apiKey": "your_key",
  "baseId": "your_base"
}

πŸ†• Adding New Clients

Method 1: Manual Setup

  1. Create client folder:
mkdir -p clients/new-client
  1. Copy template files:
cp clients/demo-landscaping/config.json clients/new-client/
cp clients/demo-landscaping/prompt.txt clients/new-client/
cp clients/demo-landscaping/qualification.json clients/new-client/
cp clients/demo-landscaping/tools.json clients/new-client/
  1. Create VAPI assistant:
node scripts/setup/setup-assistant.js
  1. Update config files with assistant ID, spreadsheet ID, and business details

  2. Restart server to load new client

Method 2: CLI (Coming Soon)

npm run add-client --name="New Client" --type="service"

πŸ§ͺ Testing

Run All Tests

npm test

Run Specific Test Suites

# Unit tests only
npm test tests/unit

# Integration tests only
npm test tests/integration

# Specific file
npm test tests/unit/qualifier.test.js

Test Coverage

npm test -- --coverage

Manual Testing

# Test webhook with sample data
curl -X POST http://localhost:8547/webhook \
  -H "Content-Type: application/json" \
  -d @scripts/testing/test-webhook-data.json

# Check server health
curl http://localhost:8547/health

# List all clients
curl http://localhost:8547/clients

πŸ› οΈ Development

Local Development Server

# Start server
npm start

# Start with ngrok tunnel (for VAPI testing)
npm run dev

Making Changes

Update conversation prompt:

  1. Edit clients/your-client/prompt.txt
  2. Run: node scripts/setup/update-assistant.js your-client

Modify qualification rules: Edit clients/your-client/qualification.json - changes take effect immediately (no restart needed).

Add/update VAPI functions:

  1. Edit clients/your-client/tools.json
  2. Run: node scripts/setup/update-assistant.js your-client

Quick Update Workflow:

# 1. Edit your files
vi clients/demo-landscaping/prompt.txt
vi clients/demo-landscaping/tools.json

# 2. Push changes to VAPI
node scripts/setup/update-assistant.js demo-landscaping

# 3. Test immediately!

Debugging

# Enable verbose logging
NODE_ENV=development npm start

# Check logs for errors
tail -f logs/server.log

πŸš€ Deployment

Development (ngrok)

# Start ngrok tunnel
ngrok http 8547

# Copy the HTTPS URL and update your VAPI assistant webhook URL

Production Options

Railway / Render / Heroku:

  1. Connect GitHub repository
  2. Set environment variables
  3. Add google-credentials.json via file upload or secret
  4. Deploy

Docker:

# Build image
docker build -t vapi-lead-gen .

# Run container
docker run -p 8547:8547 --env-file .env vapi-lead-gen

VPS (Ubuntu):

# Install dependencies
sudo apt update
sudo apt install nodejs npm

# Clone and setup
git clone your-repo
cd vapi
npm install

# Run with PM2
npm install -g pm2
pm2 start server.js --name vapi-lead-gen
pm2 startup
pm2 save

Production Checklist

  • Set NODE_ENV=production
  • Configure HTTPS (SSL certificate)
  • Secure Google credentials
  • Set up monitoring/logging
  • Configure webhook URL in VAPI
  • Test webhook with sample call
  • Set up backup strategy

πŸ”’ Security

Credentials Management

  • Never commit google-credentials.json or .env
  • Use environment variables for production
  • Rotate API keys regularly
  • Implement webhook signature verification (see webhookSecret in config)

Data Privacy

  • PII is sanitized in leadProcessor.js:167
  • Implement data retention policies
  • Enable Google Sheets access logging
  • Consider encryption for sensitive fields

Rate Limiting

Add rate limiting to prevent abuse:

const rateLimit = require('express-rate-limit');

const limiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100 // limit each IP to 100 requests per windowMs
});

app.use('/webhook', limiter);

πŸ’Ό Selling to Clients

Pricing Model

  • Setup Fee: $2,000 - $5,000 (one-time)
  • Monthly: $300 - $500 (per client)
  • VAPI Costs: Pass through (~$0.05-0.10/min)

Value Proposition

  • Never miss calls - 47% of small businesses miss calls regularly
  • 24/7 availability - No more voicemail
  • Instant qualification - AI qualifies leads in real-time
  • Automated booking - Direct to calendar
  • Time savings - 15-20 min per call saved

ROI Example

Business receiving 50 calls/month:

  • Without system: 47% miss rate = 23.5 missed calls
  • Lost revenue: 23.5 Γ— $350 avg = $8,225/month
  • Your cost: $500/month
  • ROI: 16x return on investment

Client Onboarding

  1. Discovery call - understand their business
  2. Setup VAPI phone number
  3. Configure client folder with custom prompt
  4. Test calls and refine
  5. Go live and monitor
  6. Monthly optimization reviews

πŸ› Troubleshooting

Webhook Not Receiving Calls

# Check server is running
curl http://localhost:8547/health

# Verify VAPI assistant webhook URL is correct
# Ensure server is publicly accessible (use ngrok for testing)

# Check logs
tail -f logs/server.log

Google Calendar Not Booking

  • Verify calendar is shared with service account email
  • Check calendar.calendarId matches your calendar
  • Ensure google-credentials.json path is correct
  • Verify Google Calendar API is enabled in Cloud Console

Leads Not Saving to Sheets

  • Share spreadsheet with service account email (found in google-credentials.json)
  • Verify storage.spreadsheetId is correct
  • Check sheet name matches storage.sheetName
  • Ensure Google Sheets API is enabled

Tests Failing

# Clear Jest cache
npm test -- --clearCache

# Run with verbose output
npm test -- --verbose

# Run single test file
npm test tests/unit/qualifier.test.js

Client Not Loading

# Check server logs on startup
npm start

# Verify client folder structure
ls -la clients/your-client/

# Validate JSON syntax
node -e "console.log(JSON.parse(require('fs').readFileSync('clients/your-client/config.json')))"

πŸ“š Documentation

  • Architecture: See docs/ARCHITECTURE-REFACTOR.md
  • Field Mapping: See docs/FIELD-MAPPING.md
  • Roadmap: See docs/ROADMAP.md
  • VAPI Docs: docs.vapi.ai

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Run tests (npm test)
  4. Commit changes (git commit -m 'Add amazing feature')
  5. Push to branch (git push origin feature/amazing-feature)
  6. Open Pull Request

πŸ“„ License

MIT License - feel free to use this for your business or clients.

About

Voice API integration and voice AI assistant platform

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published