Quick overview
This workflow receives incoming Twilio WhatsApp messages, looks up gold chain availability and last-approved prices from Google Sheets (or built-in demo stock), optionally uses an OpenAI-compatible model to parse what the customer wants, and replies with matching in-stock items or escalates complex requests to the owner.
How it works
- Receives an inbound WhatsApp message via a Twilio webhook (or uses built-in demo messages when run manually).
- Loads the current catalogue from a Google Sheets Stock tab, or falls back to the workflow’s demo stock data if no sheet is configured.
- Parses the customer’s text to extract style, karat, length, and quantity using keyword rules, optionally refining those fields with an OpenAI-compatible chat completion request.
- Builds a response based on the sheet data: confirms opt-out requests, escalates bulk/orders/custom/complaints to the owner, or returns up to three closest in-stock matches with quantities and list prices.
- Routes messages based on mode (preview/test/live) and sends replies and owner alerts through Twilio WhatsApp, or outputs a preview when sending is disabled.
- If the customer opted out and live writing is enabled, updates the Google Sheets Customers tab to mark the WhatsApp number as opted out.
Setup
- Create a Twilio WhatsApp sender and configure Twilio’s “A message comes in” webhook to POST to this workflow’s webhook URL.
- Add Twilio credentials in n8n and set your WhatsApp sender number in
TWILIO_WHATSAPP_FROM and your escalation number in OWNER_WHATSAPP in the config.
- Create a Google Sheet with Stock and Customers tabs (and the expected columns), add Google Sheets credentials in n8n, and set
SHEET_ID in the config.
- (Optional) Add an OpenAI API key (or compatible endpoint) and set
AI_API_KEY, AI_BASE_URL, and AI_MODEL in the config to improve message parsing.
- Choose your run mode by setting
TEST_RUN and (optionally) TEST_WHATSAPP in the config before switching to live sending and writing.