See llms.txt for all machine-readable content.

Back to Templates

Run a 24/7 website chatbot with OpenAI, Google Sheets, and Gmail

Quick Overview

This workflow powers an @n8n/chat website widget that answers visitor questions using an n8n Data Table knowledge base via OpenAI, keeps per-session memory, captures leads to Google Sheets only with consent, emails you via Gmail, and logs unanswered questions for follow-up.

How it works

  1. Receives a new message from the @n8n/chat widget trigger.
  2. Cleans and validates the visitor input, returning a prompt if the message is empty.
  3. Uses an OpenAI-powered agent with session memory to search the n8n Data Table knowledge_base and generate a structured, grounded reply.
  4. If the visitor has explicitly consented and provided a name and valid email, appends the lead details to a Google Sheets “Leads” tab and sends a Gmail notification.
  5. If the answer is supported, returns the agent’s reply to the chat widget.
  6. If the answer is not supported, logs the question and missing information to the n8n Data Table unanswered_questions and returns a fallback response offering human follow-up.

Setup

  1. Add OpenAI credentials (or n8n AI Gateway) for the chat model used by the agent.
  2. Create n8n Data Tables named knowledge_base and unanswered_questions and ensure they contain the expected string columns (topic/details/last_verified_date and session_id/question/missing_info/asked_at).
  3. Connect Google Sheets OAuth credentials, set the target spreadsheet in the Google Sheets node, and create a “Leads” sheet with the mapped columns.
  4. Connect Gmail OAuth credentials and replace the placeholder recipient email address in the Gmail node.
  5. Configure the Chat Widget Trigger allowed origins and publish the workflow, then embed the @n8n/chat widget on your site using the production chat URL.