# 2026-03-04

## Phone System / AI Chat Build

### Launch27 API
- Production API fully mapped: 36 services across 5 categories
- Categories: Keep It Clean (Standard), Top-To-Bottom Deep, Move-Ready Deep, Premium Fabric & Surface, Renovation
- Pricing tool deployed to Twilio Serverless (`/vapi-tools`) - tested and working
- Estimate endpoint tested: returns accurate pricing with 13% HST
- Frequencies: One Time (0%), Weekly (15% off), Every 2 Weeks (10%), Every 3 Weeks (5%), Every 4 Weeks (5%)

### Anthropic API Key
- Mike created API key at console.anthropic.com, saved to `~/.openclaw/secrets/anthropic-api-key.txt`
- Model: claude-sonnet-4-20250514 confirmed working

### Vapi Agent (Leah - Voice)
- Full agent config written (`nmc-phone/vapi-agent-config.json`)
- Model: GPT-4o-mini for voice (fastest latency), Claude for text
- Vapi API was down/timing out during session - couldn't push update
- Still pending: push config to Vapi when API recovers

### GHL Chat Bot - LESSON LEARNED
- ⚠️ Wasted time trying to use GHL Workflows for AI chat
- GHL workflows don't support real-time back-and-forth (re-enrollment issues)
- Tried: Customer Reply trigger → Custom Webhook → Send SMS. Only worked once, wouldn't re-trigger.
- **LESSON: Always evaluate all integration paths before picking one. Twilio direct was the obvious better choice.**

### SMS AI Handler (Leah - Text) ✅
- Deployed to Twilio Serverless at `/sms-chat`
- Flow: Inbound SMS → Twilio → our handler → Claude AI → TwiML reply
- Forwards inbound messages to GHL (msgsndr.com) so conversations still appear there
- In-memory conversation history (per phone number, last 10 messages)
- SMS webhook on 647-490-2523 now points to `https://nmc-ivr-1509-prod.twil.io/sms-chat`
- Pricing tool integrated - Leah can pull live Launch27 quotes
- Error fallback: friendly message + phone number if AI fails

### Decisions
- One agent (Leah) for both sales and customer service - no split needed
- Voice: GPT-4o-mini (speed), Text: Claude Sonnet (intelligence)
- No personal cell numbers in call transfer flow
- Transfer fallback: try GHL → if no answer → take message + notify Slack (#calls channel CDP3Y6YB0)
- GHL stays as "dumb plumbing" for now (CRM + call routing), not the AI brain

### CRM Research
- Mike feels GHL is archaic
- Researched alternatives: Close CRM, Jobber, CleanCore, HubSpot, QuoteIQ, ZenMaid
- Recommendation: don't switch now (cash-strapped, mid-migration). Revisit Q2.
- GHL as dumb plumbing + custom AI stack = more control than any off-the-shelf

### Twilio Serverless Functions (all on service ZS46e8a58afad9a49742ddbbe2e3d60bbe)
- `/ivr` - IVR handler (existing)
- `/vapi-tools` - Vapi pricing tool server
- `/ghl-chat` - GHL webhook chat handler (deprecated - GHL workflows don't work for this)
- `/sms-chat` - Direct SMS AI handler (ACTIVE)
- Asset: `/greeting.mp3`
- Environment variables: LAUNCH27_API_KEY, ANTHROPIC_API_KEY

### Misc
- Mike wants Siri shortcut to talk to Harvey quickly - parked for later
- Meal scanning APIs researched (LogMeal, Calorie Mama, Spike, FatSecret)
- Cottage cheese = lazy king's protein

### CleanOS Vision - MAJOR PIVOT
- Mike wants to build a SaaS product he can sell to other cleaning businesses
- Multi-tenant platform: each cleaning company gets their own workspace, AI agent, Twilio number, branding
- "What GHL does for agencies, but built for cleaning companies, AI-native"
- Wants fully open source foundation, no SaaS dependencies
- Key components discussed:
  - **Chatwoot** - customer conversations (native Twilio integration, solves GHL conversation logging problem)
  - **Mautic** - marketing automation (open source GHL replacement for email/drip/campaigns)
  - **Twenty CRM** - open source HubSpot alternative for pipeline/deals
  - **PostgreSQL + pgvector** - single database for structured data + AI semantic search
  - **Listmonk** - open source email campaigns (lighter alternative to Mautic)
- Aircall already cancelled (no Friday deadline pressure)
- Mike frustrated with GHL: archaic UI, v1 API half-dead, workflows can't handle real-time chat
- GHL v2 OAuth could fix conversation logging but Mike wants to move beyond GHL entirely
- Harvey tasked with: full architecture doc for the long-term stack, designed as multi-tenant SaaS from day 1

### GHL Conversation Logging - SOLVED ✅
- GHL v2 Private Integration token created (all scopes enabled)
- Token saved to `~/.openclaw/secrets/ghl-v2-token.txt` (prefix: pit-f57f91af)
- v2 API base: `https://services.leadconnectorhq.com`
- Contact search: `GET /contacts/search/duplicate?locationId=BvrCS522k5EuY6TbZQsw&number=...`
- Send message: `POST /conversations/messages` with `{type: "SMS", contactId, message}`
- Both sides of conversation now show in GHL conversations tab
- Leah replies go through GHL v2 API (GHL sends the SMS + logs it)
- Inbound messages forwarded to GHL msgsndr webhook
- GHL_V2_TOKEN added as Twilio env variable
- GHL workflow approach abandoned (Inbound Webhook trigger worked for sending but didn't log in conversations)

### GHL Conversation Logging - Previous Attempts (for reference)
- Solution: Send Leah's replies THROUGH GHL via Inbound Webhook trigger
- New workflow: Inbound Webhook → Find Contact (by phone) → Send SMS → Remove from Workflow
- Webhook URL: `https://services.leadconnectorhq.com/hooks/BvrCS522k5EuY6TbZQsw/webhook-trigger/NSyoPOSUxoU7vxwky6VG`
- Payload: `{"phone": "+1...", "message": "Leah's reply", "contactName": "..."}`
- GHL sends the SMS = naturally logs in conversation history. Problem solved without v2 API.
- Need to rewire sms-handler.js: instead of TwiML reply, POST to GHL webhook
- Also added GHL_API_KEY as Twilio env variable (for contact lookups/notes)
- GHL v1 API notes endpoint works: `POST /v1/contacts/{id}/notes/` 
- GHL v1 API conversations/messages endpoint does NOT work (404, deprecated)
- Mike's personal phone: +14162726683 (used for testing)
- Another test number: +16476688652

### CleanOS Vision - REFINED
- NOT a white-label agency platform (not replicating GHL's agency model)
- IS a **booking management SaaS for cleaning companies** with AI built in
- Think: Launch27 + Jobber + AI agent, all in one
- Cleaning companies sign up, connect phone number, get AI receptionist, manage bookings
- Open source foundation so Mike can customize completely
- PostgreSQL + pgvector for customer data (structured + AI semantic search)
- Customer records in database, not markdown files

### ⚠️ LESSON: API Keys in Chat
- Mike got annoyed when I asked him to paste API keys in conversation
- He has a firm rule: NEVER paste APIs in chat
- Always use file-based approach: `echo "KEY" > ~/.openclaw/secrets/filename.txt`
- Or `openclaw secrets set <name>` if the command works
- **DO NOT ask for keys in conversation again**

### Quote/Follow-Up Engine Discussion
- Mike's current quote flow: homepage lead capture (basic, not wired to API) + Launch27 booking tool + GHL quote email workflows
- Existing GHL workflows are "not great" - Mike doesn't want to build more in GHL
- Plan: build follow-up engine in CODE, not GHL workflows
- Use v2 API as delivery pipe (send SMS/email), but logic lives in our code
- Claude-powered personalized follow-ups instead of static template sequences
- This becomes portable to CleanOS later
- GHL API can't create/modify workflows - but CAN trigger them via tag/stage changes
- GHL Opportunities Pipeline exists but Mike finds it cumbersome

### Still Pending
- [ ] Quote follow-up engine design
- [ ] Push Vapi agent config when API recovers
- [ ] Wire Vapi as IVR missed-call fallback
- [ ] Conversation history persistence (currently in-memory, resets on cold starts)
- [ ] Slack notifications for missed calls / escalations
- [ ] Siri shortcut for Harvey (parked)
- [ ] Can disable GHL "Leah AI Chat Bot" workflow (no longer needed)

---

## Afternoon Session (resumed ~4:30 PM after ~2 hour outage)

### CleanOS Architecture Doc ✅
- Written to `/Users/harvey/.openclaw/workspace/nmc-phone/cleanOS-architecture.md`
- Phase 1: Build for NMC internally (Chatwoot + PostgreSQL + code-based follow-ups replace GHL)
- Phase 2: Multi-tenant SaaS platform (each cleaning co gets own AI agent, Twilio number, booking widget)
- Phase 3: Public SaaS launch (2027) — $49/$99/$199/mo tiers
- Stack: Next.js + Node.js, PostgreSQL + pgvector, Chatwoot, Twilio, Claude/GPT-4o-mini, BullMQ
- Replaces: Launch27 (~$59/mo), GHL (~$97/mo), Aircall (already cancelled)
- Estimated savings: $150-250/month once fully migrated
- Market: 100k+ cleaning companies in North America

### Leah Quote Tool - IN PROGRESS
- Adding `send_quote` tool to sms-handler.js
- GHL pipelines fully mapped via v2 API — key pipeline: "AI Agent Sales Pipeline" (ID: 43wROY9icVX1mP86G8eZ)
  - Stages: Lead In → Follow Up → Quote Sent → Booking Requested → Booking Confirmed → Invoice Paid → Lost/Nurture
  - Quote Sent stage ID: e34307ed-c166-437c-aa69-e74827291dfb
- GHL has 356 custom fields — key ones for quotes:
  - Sq Ft: 2dFzsuxwzyoGE9UKYZEg
  - L27 Bedrooms: zKhkPjFvzOHLAbQAVBY7
  - L27 Baths: xoX6QAd3pqDxbGGBZTXH
  - L27 Half Baths: jUrf6kkUclc1rtYUbIHl
  - L27 Service Category: 7Ir8ypGxwPPKmss7rP06
  - L27 Frequency: FxFnM9iGcJvZenYDK8Md
  - L27 Initial Clean w/Tax: JOe7DniRN2f9Na9JWvVH
- `send_quote` tool added to TOOLS array and tool handler in callClaude()
- `sendQuote()` function: (1) finds contact by phone, (2) updates custom fields, (3) creates opportunity in AI Agent Sales Pipeline at "Quote Sent" stage
- System prompt updated: Leah gives verbal estimate first, then offers to send formal quote; calls send_quote when customer says yes
- **Deployment pending** — need to build + deploy to Twilio Serverless

### Session/Agent Outage
- Mike was pinging for ~2 hours (2:15 PM - 4:23 PM) with no response
- Session was unavailable/unresponsive for that period
- Mike asked how to switch models via OpenRouter → explained `/model` command and aliases

### OpenRouter Model Switching
- `/model openrouter/auto` — OpenRouter picks best available
- `/model sonnet` — Claude Sonnet (good fallback when Claude overloaded)
- `/model opus` — Claude Opus
- `/model gpt` — GPT-5
