How to Build an AI Website Chatbot with CRM Lead Capture Using n8n

AI Website Chatbot n8n workflow template thumbnail

Every visitor who leaves your website without talking to someone is a missed opportunity. Maybe they had a question about your services but didn’t feel like filling out a contact form. Maybe they were ready to buy but got distracted. A live chat widget helps, but you can’t sit at your desk 24/7 waiting for messages. What if an AI chatbot could greet visitors, answer their questions about your business, and quietly collect their name and email — all while you sleep? That’s exactly what you’ll build in this guide using n8n and OpenAI.

Prefer to skip the setup? Grab the ready-made template → and be up and running in under 10 minutes.

What You’ll Build

  1. A visitor lands on your website and sees a chat widget in the corner of the screen.
  2. They type a question — the AI chatbot responds naturally, explains your services, and asks what they need help with.
  3. Once the visitor shares their email and describes their project, the chatbot automatically saves the lead to a Google Sheet acting as your lightweight CRM.
  4. The visitor gets a friendly confirmation message, and you wake up to a spreadsheet full of qualified leads ready for follow-up.

How It Works — The Big Picture

This template uses two connected workflows inside n8n. The main workflow runs the chatbot itself — receiving messages, thinking through responses with GPT-4o mini, and maintaining conversation context. When the visitor shares their contact info, the chatbot calls a sub-workflow tool that extracts the email and description, formats it into clean JSON, and appends a new row to your Google Sheet.

┌──────────────────────────────────────────────────────────────────────────────┐
│  MAIN WORKFLOW — Website Chatbot                                            │
│                                                                              │
│  [Chat Trigger] → [Website Chatbot Agent] ←── [OpenAI GPT-4o mini]         │
│                           ↑                                                  │
│                    [Conversation Memory]                                     │
│                           ↓ (tool call when lead info collected)             │
│                    [Save Lead to CRM]                                        │
└──────────────────────────────────────────────────────────────────────────────┘
                            │
                            ▼
┌──────────────────────────────────────────────────────────────────────────────┐
│  SUB-WORKFLOW — CRM Lead Processing                                         │
│                                                                              │
│  [Receive Lead Data] → [Extract Lead Info] → [Append to Sheet] → [Confirm] │
│                              ↑                                               │
│                     [GPT-4o mini + Output Parser]                            │
└──────────────────────────────────────────────────────────────────────────────┘
                            │
                            ▼
                   ┌─────────────────┐
                   │  Google Sheets   │
                   │  (Leads CRM)     │
                   └─────────────────┘
  

What You’ll Need

  • A self-hosted or cloud n8n instance (version 1.0 or later)
  • An OpenAI API key with access to GPT-4o mini (or any other chat model)
  • A Google account with Google Sheets access (free tier works fine)
  • A website where you can embed the n8n chat widget (any site that supports JavaScript snippets)

Estimated build time: 30–45 minutes from scratch, or under 10 minutes with the template.

Part 1 — The Main Chatbot Workflow

This workflow handles every incoming message from your website visitors. It powers the AI conversation, remembers what the visitor said earlier in the chat, and calls the CRM sub-workflow when it detects lead information.

1 Chat Trigger (n8n Chat Trigger)

The Chat Trigger node is n8n’s built-in way to receive messages from a chat widget you embed on your website. When a visitor types something and hits send, this node fires and passes the message into the workflow.

  1. Add a Chat Trigger node to your canvas (search for “When chat message received”).
  2. Leave the default options as-is — no extra configuration needed.
  3. After saving and activating the workflow, n8n gives you a webhook URL and a small JavaScript snippet you can paste into your site’s HTML to display the chat widget.
{
  "action": "sendMessage",
  "body": {
    "message": "Hi, I'm interested in automating my invoice process."
  },
  "sessionId": "visitor-session-abc123"
}
💡

Tip: The n8n chat widget works on any website — WordPress, Shopify, static HTML, React apps. Just paste the embed snippet before the closing </body> tag.

2 Website Chatbot Agent (AI Agent)

This is the brain of the operation. The AI Agent node receives the visitor’s message, processes it through the OpenAI model, checks conversation history, and generates a helpful response. It’s configured with a system message that tells the AI who it is, what services your company offers, and what information to collect.

  1. Add an AI Agent node and connect it to the Chat Trigger.
  2. In the System Message field under Options, paste your company description and instructions. Here’s the template version (customize for your business):
You are the first point of contact for visitors on our website.
Your company helps businesses automate their internal processes
using n8n, an open-source workflow automation platform.

Keep answers brief and helpful.

Our services include:
- Designing and implementing automations using n8n
- Replacing manual work with fully automated workflows
- Training teams to manage and scale automations in-house

Your primary goals are:
1. Briefly explain what we do in a helpful, conversational tone.
2. Ask the visitor what processes they want to automate.
3. Collect their name and email address for follow-up.

After you have the email and what the user needs, send all the
info together to the CRM tool.
💡

Tip: The last line is critical — it tells the AI agent when to trigger the CRM tool. Without it, the agent won’t know to save the lead. Adjust the wording, but keep the instruction to call the tool once email and description are collected.

3 OpenAI Chat Model (Language Model)

This node provides the actual language model that powers the agent’s responses. It connects to the Agent node via the ai_languageModel connector — not the regular data flow.

  1. Add an OpenAI Chat Model node.
  2. Select gpt-4o-mini as the model (fast, cheap, and accurate enough for customer conversations).
  3. Connect your OpenAI API credential.
  4. Drag a connection from this node’s output to the Agent node’s AI Language Model input (the connector on the bottom-left of the Agent node).
📌

You can swap gpt-4o-mini for gpt-4o if you want more nuanced responses, but it costs roughly 10x more per token. For a lead-capture chatbot, gpt-4o-mini is the sweet spot.

4 Conversation Memory (Buffer Window Memory)

Without memory, the chatbot forgets everything after each message. The Buffer Window Memory node stores the last several exchanges so the AI can reference what the visitor said earlier in the conversation — like when they mentioned their name two messages ago.

  1. Add a Window Buffer Memory node.
  2. Leave defaults as-is (it stores the last 5 message pairs by default).
  3. Connect it to the Agent node’s AI Memory input.

Part 2 — The CRM Sub-Workflow (Lead Processing)

When the chatbot collects enough information (email + project description), the Agent calls the CRM tool. This tool is actually a full sub-workflow embedded inside a Tool Workflow node. It takes the raw conversation data, extracts the structured lead info, and saves it to Google Sheets.

5 Save Lead to CRM (Tool Workflow)

The Tool Workflow node lets you give the AI agent access to a multi-step process as if it were a single tool. When the agent decides it’s time to save the lead, it calls this tool and passes the conversation data in.

  1. Add a Tool Workflow node and connect it to the Agent node’s AI Tool input.
  2. Set the source to Parameter (this embeds the sub-workflow JSON directly inside the node, so you don’t need a separate workflow file).
  3. In the Description field, write: CRM tool to store lead information — call this once you have the visitor's email address and a description of what they need
  4. Paste the sub-workflow JSON into the Workflow JSON field. The template includes this pre-configured.
💡

Tip: The tool description matters more than you’d think. The AI agent reads this description to decide when to call the tool. A vague description like “save data” may cause the agent to trigger it at the wrong time.

6 Extract Lead Info (AI Agent with Output Parser)

Inside the sub-workflow, this agent node takes the raw conversation input (which could be messy — “Sure, my email is sarah.thompson@gmail.com and I need help with onboarding automation”) and extracts it into a clean JSON object with exactly two fields: email and description.

  1. The node receives input from the Receive Lead Data trigger.
  2. It uses GPT-4o mini with a strict system prompt that says: “You are a formatting assistant. Your only job is to extract and convert the input into clean, valid JSON.”
  3. A Structured Output Parser is connected to enforce the JSON schema, making sure the output always has the right shape.

After this node runs, the data looks like this:

{
  "output": {
    "email": "sarah.thompson@gmail.com",
    "description": "Wants help automating client onboarding and sending welcome emails."
  }
}

7 Append Lead to Sheet (Google Sheets)

This node takes the structured lead data and appends it as a new row in your Google Sheet. Each lead gets its own row with the email and project description.

  1. Connect your Google Sheets OAuth2 credential.
  2. Select your spreadsheet (or create a new one called “Leads CRM”).
  3. Choose Sheet1 as the sheet name.
  4. Map the columns: set email to ={{ $json.output.email }} and description to ={{ $json.output.description }}.

8 Send Confirmation (Code Node)

A simple Code node that returns a thank-you message back to the chatbot. This text gets sent back through the tool chain to the agent, which uses it to confirm the lead was saved.

return [
  {
    json: {
      text: "Thanks for the info, we will be in touch soon"
    }
  }
];

The Data Structure

Your Google Sheet acts as a lightweight CRM. It only needs two columns to start, but you can add more later (timestamp, source page, lead score).

Column Type Example Description
email Text sarah.thompson@gmail.com The visitor’s email address, collected during the chat conversation
description Text Wants help automating client onboarding and sending welcome emails A summary of what the visitor needs, extracted by the AI from the conversation

Here’s what a few rows might look like after a week of running the chatbot:

email description
sarah.thompson@gmail.com Wants help automating client onboarding and sending welcome emails
james.carter@outlook.com Looking to sync Shopify orders with their warehouse spreadsheet automatically
emily.rodriguez@acmecorp.com Needs a workflow to route support tickets from email to Slack channels
📌

Column names must match exactly — email and description, all lowercase. The Google Sheets node maps data by column header, so a mismatch like “Email” or “Description” will cause empty cells.

Full System Flow

  Visitor types message in chat widget
                │
                ▼
  ┌─────────────────────────────┐
  │  Chat Trigger               │ ← Receives message via webhook
  └─────────────┬───────────────┘
                │
                ▼
  ┌─────────────────────────────┐     ┌──────────────────────┐
  │  Website Chatbot Agent      │ ←── │ OpenAI GPT-4o mini   │
  │  (System prompt defines     │     └──────────────────────┘
  │   company info + goals)     │     ┌──────────────────────┐
  │                             │ ←── │ Conversation Memory   │
  └─────────────┬───────────────┘     └──────────────────────┘
                │
          Has email + description?
          ┌─────┴─────┐
          No          Yes
          │           │
          ▼           ▼
     Reply with    ┌──────────────────────┐
     follow-up     │ Save Lead to CRM     │ (Tool Workflow call)
     question      └───────────┬───────────┘
                              │
                              ▼
                   ┌──────────────────────┐
                   │ Extract Lead Info     │ ← GPT-4o mini + Output Parser
                   └──────────┬───────────┘
                              │
                              ▼
                   ┌──────────────────────┐
                   │ Append Lead to Sheet  │ → Google Sheets
                   └──────────┬───────────┘
                              │
                              ▼
                   ┌──────────────────────┐
                   │ Send Confirmation     │ → "Thanks, we'll be in touch"
                   └──────────────────────┘
  

Testing Your Workflow

  1. Save and activate the workflow in n8n.
  2. Open the chat widget (you can test it directly in n8n by clicking “Chat” in the top-right corner of the editor, or embed the snippet on a test page).
  3. Send a greeting like: “Hi, I run a small e-commerce store and I’m interested in automating my order fulfillment process.”
  4. Wait for the chatbot to respond and ask for your email. Provide a test email: “Sure, it’s test.user@example.com”
  5. Check your Google Sheet — you should see a new row with the email and a description of the request.
  6. Verify the chatbot sent back a confirmation message like “Thanks for the info, we will be in touch soon.”
Problem Likely Cause Fix
Chatbot responds but never saves the lead The tool description is too vague, or the system prompt doesn’t tell the agent to call the CRM tool Make sure the system message ends with “After you have the email and what the user needs, send all the info together to the CRM tool.”
Google Sheet stays empty Column headers don’t match or OAuth credential expired Check that your sheet has email and description as column headers (lowercase). Re-authorize Google Sheets in n8n if needed.
Chat widget doesn’t appear on site Embed snippet is missing or blocked by CSP Paste the n8n chat embed code before </body>. Check your browser console for Content Security Policy errors.
Agent gives generic or off-topic answers System message doesn’t describe your specific business Rewrite the system message to include your actual services, company name, and the tone you want.
“Could not parse output” error in sub-workflow The Structured Output Parser schema doesn’t match GPT’s output format Ensure the parser’s example JSON has exactly email and description fields. Check the Extract Lead Info node’s execution log for the raw output.

Frequently Asked Questions

Can I use a different AI model instead of GPT-4o mini?

Yes. You can swap in any model that n8n supports — GPT-4o, Claude, Gemini, or even a local model via Ollama. Just replace the OpenAI Chat Model nodes with the appropriate model node. Keep in mind that the system prompts may need slight adjustments for non-OpenAI models.

How do I add the chat widget to my WordPress site?

After activating the workflow, n8n provides an embed snippet (a small block of HTML and JavaScript). In WordPress, go to Appearance → Theme Editor → footer.php and paste the snippet just before the closing </body> tag. Alternatively, use a plugin like “Insert Headers and Footers” to add it without editing theme files.

Will the chatbot work on multiple pages at once?

Yes — the chat widget runs on every page where the embed snippet is loaded. Each visitor gets their own session ID, so conversations stay separate even when dozens of people are chatting at the same time. The Buffer Window Memory keeps each session’s context isolated.

Can I collect more fields like phone number or company name?

Absolutely. Update the system message to ask for those fields, then update the Structured Output Parser schema in the sub-workflow to include the new fields. Finally, add matching columns to your Google Sheet. The AI will extract whatever you tell it to look for.

How much does it cost to run this per month?

The main cost is OpenAI API usage. GPT-4o mini is priced at about $0.15 per million input tokens and $0.60 per million output tokens. A typical chat conversation of 10 messages costs roughly $0.002–$0.005. Even with 500 conversations per month, you’d spend under $3 on AI. n8n self-hosted is free; n8n Cloud starts at $24/month.

What happens if OpenAI’s API goes down while someone is chatting?

The chatbot will fail to respond to that specific message. n8n will log the error in the execution history. The visitor’s message isn’t lost — they can try again once the API recovers. For production use, consider adding an error branch in the Agent node that sends a fallback message like “Sorry, I’m having trouble right now. Please email us at support@yourcompany.com.”

🚀 Get the AI Website Chatbot Template

Skip the 45-minute build. Get the complete workflow JSON, a setup guide with step-by-step screenshots, and a credentials guide that walks you through every API key — ready to import and go live in under 10 minutes.

Get the Template →

Instant download · Works on n8n Cloud and self-hosted

What’s Next?

  • Add email notifications: Connect a Gmail or SendGrid node to email yourself whenever a new lead is captured, so you can follow up faster.
  • Qualify leads with AI scoring: Add a second AI step that rates each lead (hot, warm, cold) based on their description and writes the score to a third column in your sheet.
  • Connect to a real CRM: Replace the Google Sheets node with HubSpot, Salesforce, or Pipedrive to send leads directly into your sales pipeline.
  • Add a knowledge base: Attach a RAG (Retrieval-Augmented Generation) tool so the chatbot can answer detailed questions about your products or services using your own documentation.
n8n
OpenAI
Google Sheets
chatbot
lead capture
CRM
automation
AI agent