See llms.txt for all machine-readable content.

Back to Templates

Answer WhatsApp FAQs with keyword matching and an OpenAI fallback

Quick overview

This workflow handles WhatsApp Business Cloud API webhooks, verifies the callback URL, and replies to incoming WhatsApp text messages using keyword-matched FAQs with an OpenAI fallback that can only select from approved FAQ IDs before sending the stored answer back via WhatsApp.

How it works

  1. Receives a GET request from Meta to verify the WhatsApp webhook and returns the hub.challenge only when the provided verify token matches.
  2. Receives WhatsApp webhook POST events and keeps only incoming text messages while ignoring delivery/read receipts.
  3. Scores each message against a built-in FAQ list using keyword matching and selects the highest-scoring FAQ answer when a match is found.
  4. If no keyword match is found, sends the customer message plus the FAQ IDs and questions to an OpenAI chat model to choose a single FAQ ID or null.
  5. Validates the model’s output against the known FAQ IDs and selects either the corresponding stored answer or a fixed fallback message.
  6. Sends the chosen reply back to the customer via the WhatsApp Business Cloud API using the same phone number that received the message.

Setup

  1. Create a Meta app with the WhatsApp product, connect a business phone number, and configure webhook subscriptions for messages.
  2. In n8n, add WhatsApp Business Cloud API credentials and an OpenAI (or OpenAI-compatible) credential for the chat model node.
  3. Replace YOUR_VERIFY_TOKEN in the webhook verification check and use the same token in Meta’s webhook settings.
  4. Activate the workflow and copy the production webhook URL for the whatsapp-faq path into Meta’s webhook configuration.
  5. Edit the FAQ list (IDs, questions, keywords, answers) and update placeholders like YOUR_BOOKING_LINK and the fallback message to match your business.

Additional info

Need signature verification, deduplication, opt-out handling and human handoff? A production version is available at https://zhangautomation.gumroad.com/l/ecvlr