Quick Overview
This workflow accepts customer requests via a webhook or email, logs them in Supabase, uses OpenAI to classify intent, and then either checks/cancels bookings via an HTTP API or answers general questions from a Supabase knowledge base before replying via Gmail.
How it works
- Receives a POST webhook request containing customer, message, and bookingId, validates that the message is not empty, and returns HTTP 400 for invalid submissions.
- Stores valid requests in a Supabase table and uses OpenAI to classify the message as reschedule, cancellation, general_enquiry, or unclear.
- For reschedule requests, updates the Supabase record as classified, looks up the booking via an HTTP API, and returns HTTP 200 if found or HTTP 404 if not found.
- For cancellation requests, retrieves the booking via an HTTP API and emails a Gmail “send and wait” approval request if the booking exists.
- If cancellation is approved, sends an HTTP API request to cancel the booking and emails a confirmation or failure message via Gmail based on the API response.
- For general enquiries, searches a Supabase vector-store knowledge base with OpenAI embeddings, uses OpenAI to draft a reply based only on the retrieved documents, and emails the response via Gmail.
- For unclear requests, uses OpenAI to generate a clarification question, emails it via Gmail, and saves the Gmail thread ID back to the Supabase request record.
- Separately, a Gmail trigger polls for incoming replies, retrieves the email, finds the original request in Supabase by Gmail thread ID, extracts the customer’s reply text, and re-runs intent classification for follow-up handling.
Setup
- Create and connect credentials for OpenAI, Supabase, and Gmail (OAuth2) used for classification, knowledge-base search, request logging, and email sending.
- In Supabase, create a client_requests table with fields used by the workflow (for example customer_name, message, booking_id, intent, status, and gmail_thread_id).
- In Supabase, set up a documents vector table/collection compatible with the Supabase vector store node and ensure embeddings are generated with OpenAI.
- Replace the booking API base URL (currently http://host.docker.internal:3000/api/bookings/...) with your own booking system endpoints and ensure they return the expected status codes.
- Update the Gmail recipient addresses, subjects, and any business-specific wording (for example “Northstar Wellness”) to match your environment.
- Copy the production webhook URL for the Incoming Request trigger and configure your website/chat widget/CRM to POST customer, message, and bookingId to it.