Skip to content
reaatechREAATECH

Files · xAI Grok Voice Lead Intake for Small Business

76 (1 binary, 592.4 kB total)attempt 1

README.md·2816 B·markdown
markdown
# xAI Grok Voice Lead Intake for Small Business
 
> Phone-based lead capture agent that qualifies callers using xAI Grok and syncs to your CRM automatically.
 
A tutorialized reference solution from [reaatech.com](https://reaatech.com), demonstrating how to build a production-grade voice lead intake system with xAI Grok (via `@ai-sdk/xai`), Twilio telephony, Deepgram STT/TTS, and the `@reaatech/*` package family.
 
## What it does
 
Answers incoming phone calls, transcribes caller speech via Deepgram, uses xAI Grok for natural language understanding, classifies caller intent with `@reaatech/confidence-router`, qualifies leads, and logs results to a CRM. Session state is preserved across multi-turn conversations using Redis-backed session continuity.
 
## Architecture
 
```
Twilio PSTN → TwiML <Stream> → WebSocket → Deepgram STT

                              xAI Grok (via @ai-sdk/xai)

                              @reaatech/confidence-router

                              MCP agent server → CRM sync

                              Deepgram TTS → audio back to caller
```
 
## Prerequisites
 
- Node.js >=22
- pnpm
- Redis instance
- Twilio account with a phone number
- Deepgram API key
- xAI API key
 
## Quick Start
 
```bash
# Copy and fill environment variables
cp .env.example .env
# Edit .env with your API keys
 
# Install dependencies
pnpm install
 
# Start the dev server
pnpm dev
 
# The WebSocket server starts on port 8081 for Twilio Media Streams
```
 
## REAA Packages
 
| Package | Role |
|---------|------|
| `@reaatech/voice-agent-core` | Pipeline orchestration, session management, latency enforcement |
| `@reaatech/voice-agent-telephony` | Twilio Media Streams WebSocket handler |
| `@reaatech/voice-agent-mcp-client` | JSON-RPC 2.0 MCP client |
| `@reaatech/mcp-server-core` | Shared Zod schemas, types, env config |
| `@reaatech/session-continuity` | Multi-turn session lifecycle management |
| `@reaatech/session-continuity-storage-redis` | Redis storage adapter |
| `@reaatech/confidence-router` | Threshold-based intent routing |
 
## API Reference
 
- `POST /api/twilio/voice` — Twilio Voice webhook; returns TwiML to connect call to Media Streams WebSocket
- `POST /api/twilio/status` — Twilio call status callback; manages session lifecycle
- `GET /api/leads` — List recent leads and sessions
- `POST /api/leads` — Manually qualify a lead from transcript text
 
## Environment Variables
 
See [.env.example](.env.example) for the full list of required env vars.
 
## Testing
 
```bash
pnpm typecheck
pnpm lint
pnpm test
```
 
## License
 
MIT — see [LICENSE](./LICENSE).