[Workflow Breakdown] Building an Inbound AI Lead Qualifier Chatbot with n8n Chat Trigger, Google Gemini, and Google Sheets LoggingBuilt with n8n

Hey everyone! :waving_hand:

I wanted to share a lightweight, self-hostable AI lead qualification workflow built with n8n, Google Gemini, and Google Sheets.

If you run an agency, freelance business, or SMB, inbound chat leads often require quick triage: asking what the prospect needs, gathering their budget/urgency, and recording their details without paying $100+/month for enterprise chat platforms.

Here is a step-by-step breakdown of how to build an interactive AI lead qualification bot in n8n.

:building_construction: Workflow Architecture

[ Visitor Chat Input ]
          │
          ▼
1. n8n Chat Trigger ──► 2. AI Agent Node ◄── (Google Gemini Model + Window Memory)
                              │
                              ▼
                        3. Parse Lead (Code Node)
                              │
                              ▼
                        4. Reply to Visitor
                              │
                              ▼
                        5. Completeness Check (If Node)
                              │
                              ▼ (If Name + Email Present)
                        6. Google Sheets Logger

:light_bulb: Key Technical Setup

1. AI Agent System Prompt:

You are a helpful, professional AI Lead Qualification assistant.
Your goal is to assist website visitors and gather key business details:
1. Contact Name
2. Email Address
3. Company / Project Scope
4. Estimated Budget
5. Implementation Urgency (e.g. Immediately, 1-3 months)

Guidelines:
- Keep responses concise (1-3 sentences max).
- Answer visitor questions about our services warmly.
- Seamlessly weave questions to collect missing contact or project details.
- Once you have collected Name and Email, thank the visitor and inform them our team will follow up shortly.

2. JavaScript Lead Extractor (Parse Lead Code Node):

const item = $input.first().json;
const text = item.output || item.response || "";

return {
  json: {
    raw_response: text,
    extracted_at: new Date().toISOString(),
    session_id: item.sessionId || $node["n8n Chat Trigger"].json.sessionId,
    has_contact_info: (text.includes("@") || text.toLowerCase().includes("email"))
  }
};

3. Google Sheets Destination:
Create a Google Sheet with columns: Timestamp | Session ID | Name | Email | Company | Budget | Urgency | Summary. Map the n8n Google Sheets node (Append Row) to these fields.

:rocket: Costs & Performance

  • Platform Fee: $0/mo (Self-hosted n8n / free cloud tier).
  • AI Cost: Google Gemini 1.5 Flash generous free tier / fractions of a cent per session.

:package: Pre-built Template (Optional)

If you’d like to jumpstart setup with the ready-to-import JSON workflow file, complete field-mapping Code node, and setup guide, I’ve packaged the complete template on Gumroad ($19):
:backhand_index_pointing_right: AI Lead Qualifier Chatbot — n8n Template on Gumroad

(The breakdown above is 100% self-contained if you want to build it yourself from scratch in n8n!)

Let me know if you have any questions or feedback! Happy automating! :high_voltage:

Nice clear breakdown. One thing I’d check in the Parse Lead node: has_contact_info is computed from the agent’s reply text, so it turns true whenever the bot says “could you share your email?”, before the visitor has given one. And Name/Email/Budget aren’t actually extracted into fields, so the Sheets mapping has nothing structured to write.

What I’d suggest instead: put a Structured Output Parser (or a second small LLM call) on the conversation with a fixed schema (name, email, company, budget, urgency), then gate the If node on a regex-valid email field rather than a string search.

A side benefit of a fixed schema: an email-intake workflow can write to the same sheet, so chat and email leads end up in one list.