Capability - live operator inbox

Chat that knows when to step aside

An inbound WhatsApp message runs a short pipeline before any model is called. Cost is bounded per user, and when the bot is not the right answer it hands off to a human instead of guessing.

Inbound message pipeline

1. Inbound message

WhatsApp webhook delivers the user's text to the console.

2. Rate-limit gate

Per-user window (default 15 / hour). Over the cap means stop paying for model calls.

over cap → human handoff

3. Retrieve context

Keyword search over the catalogue in BigQuery builds a small context block.

4. Call provider

Claude primary, OpenAI alternative, selected by AI_PROVIDER.

error → fallback

5. Fallback

Rule-based reply needs no API key, so a provider outage still answers the basics.

6. Reply or hand off

Send the answer, or flip the thread to operator mode.

Two modes per thread

AI-bot mode

The gateway auto-replies within the guardrails above. Default for new threads.

Operator mode

A human takes over; the bot stops auto-replying for that conversation until released.

The toggle is per conversation, so a busy operator can let the bot hold routine threads while they work a hard one.

Relay - anonymized engineering case study. Code in ../src/chat/ai-gateway.js.