OI
owner-chat

API Reference

Cloudflare Pages Function endpoints for the Owner Chat widget.

Chat Endpoints

POST
/api/chat/ai

Main AI conversation endpoint — sends messages to Claude Haiku

Input: { messages: [{ role, content }] }

Output: { reply, tool_call?: { name, result } }

Model: claude-haiku-4-5-20251001, max 400 tokens

Tools: create_lead, handoff_to_human

POST
/api/chat/send

Send conversation to Slack for human handoff

Input: { messages, visitorInfo?: { name, phone } }

Output: { thread_ts } (Slack thread timestamp for polling)

Posts formatted conversation history to the configured Slack channel.

GET
/api/chat/messages?thread=THREAD_TS

Poll Slack thread for team replies

Returns only human replies (excludes bots). Client polls every 4 seconds.

Output: [{ text, user, ts }]

GET
/api/chat/status

Check if team members are online via Slack presence

Output: { online: boolean }

Checks presence of CHAT_RESPONDER_IDS. Cached 60 seconds in Cloudflare KV.

Utility Endpoints

GET
/api/health

Health check — returns { status: 'ok' }

GET
/api/sentry-test

Test Sentry error tracking integration

CORS Configuration

All /api/ routes have CORS middleware applied. Allowed origins:

  • https://ownerinspections.com.au
  • https://chat.ownerinspections.com.au
  • http://localhost:3000 (development)

Configured via ALLOWED_ORIGINS environment variable. Handles preflight OPTIONS requests.