Barefoot AI HubTHE BAREFOOT FREELANCER
Start learning
⇄ Workflows & Automation · Lesson 2 of 2

14Build an AI Lead Workflow in n8n

Hands-on: install n8n free, then build a complete lead pipeline — form intake, AI qualification to JSON, CRM logging, a drafted personal reply and Telegram approval before anything is sent.

⏱ 45 min📶 Intermediate🧪 3-question check

What you'll learn

  • Run n8n locally with Docker or npx
  • Connect a chat model (local Ollama or cloud)
  • Extract structured data with AI and branch on it
  • Add human approval before sending, and error alerts

The workflow you'll build

TRIGGERForm Triggername, email, message, budget
AIQualify lead→ JSON: intent, budget, score
ACTIONGoogle Sheetsappend lead
IFScore ≥ 70?hot vs nurture
AIDraft replypersonalized
HUMANTelegram approvalapprove / reject
SENDGmailreply sent
Result: every inquiry is logged, scored and answered within minutes — and nothing reaches a client without your approval.

Part 1 — Run n8n

terminalbash
docker volume create n8n_data

docker run -it --rm --name n8n -p 5678:5678 \
  -v n8n_data:/home/node/.n8n \
  docker.n8n.io/n8nio/n8n

Open http://localhost:5678 and create your owner account. Your workflows persist in the n8n_data volume.

terminalbash
# requires Node.js 20+
npx n8n

Great for quick tests. For anything long-running, use Docker or n8n Cloud.

Prefer not to self-host? Start a trial on n8n Cloud. Everything in this lesson works the same. Note: a cloud instance can't reach Ollama on your laptop — use a cloud model there.

Part 2 — Connect a model

In n8n: Credentials → Add credential → Ollama.

n8n runs…Base URL
with npx on the same computer as Ollamahttp://localhost:11434
in Docker, Ollama on the hosthttp://host.docker.internal:11434

On Linux Docker, add --add-host=host.docker.internal:host-gateway to the docker run command. Use a tool-capable model like qwen3:8b.

Add a credential for your provider (Anthropic, OpenAI, Google Gemini, OpenRouter…) with your API key. Cloud models give stronger results for drafting and are necessary if n8n is hosted in the cloud.

Part 3 — Build it node by node

  1. Form Trigger

    Create a workflow → add n8n Form Trigger. Title: “Work with me”. Fields: Name (text, required), Email (email, required), What do you need? (textarea, required), Budget (dropdown: Under ₱20k / ₱20–50k / ₱50–100k / ₱100k+ / Not sure). Click Test step and submit a sample inquiry.

  2. AI qualification → structured JSON

    Add Basic LLM Chain (connect your chat model). Turn on Require Specific Output Format and attach a Structured Output Parser with this JSON example:

    Structured Output Parser — examplejson
    {
      "service": "website",
      "summary": "Café owner wants a 5-page site with online menu by November.",
      "budget_php": 40000,
      "deadline": "2026-11-15",
      "urgency": "high",
      "lead_score": 85,
      "red_flags": []
    }

    Prompt (switch the field to Expression to use the {{ }} variables):

    LLM Chain promptprompt
    You qualify inbound leads for a freelance web designer in the Philippines.
    Services: websites, branding, SEO. Ideal client: small business, budget ₱30k+,
    clear goal, timeline over 2 weeks.
    
    Score 0–100 for fit. Deduct for: no clear need, budget under ₱20k,
    unrealistic deadline (under 1 week), requests outside services.
    Use null for anything not stated. Never invent a budget.
    
    <lead>
    Name: {{ $json.Name }}
    Budget selected: {{ $json.Budget }}
    Message: {{ $json["What do you need?"] }}
    </lead>
  3. Log to Google Sheets

    Add Google Sheets → Append Row. Create a sheet with columns: Date, Name, Email, Service, Budget, Score, Urgency, Summary, Status. Map each column from the form and AI output (e.g. {{ $json.output.lead_score }}). Set Status to “New”.

  4. Branch on score

    Add an IF node: {{ $json.output.lead_score }} is greater than or equal to 70. True → hot path. False → nurture path (a polite auto-reply with your portfolio link and booking page — still a good idea to review at first).

  5. Draft a personal reply

    On the hot path, add another Basic LLM Chain:

    Draft reply promptprompt
    Write a reply email from Jae, a freelance web designer, to this new lead.
    
    Lead: {{ $('n8n Form Trigger').item.json.Name }}
    Their request: {{ $('n8n Form Trigger').item.json["What do you need?"] }}
    Qualification summary: {{ $('Basic LLM Chain').item.json.output.summary }}
    
    Goals: thank them, reflect their specific need in one sentence,
    suggest a 20-minute call and include the booking link
    https://cal.example.com/jae/discovery .
    Warm, professional, under 120 words. No prices. Return only the email body.
  6. Ask for approval on Telegram

    Create a bot with @BotFather, add the Telegram credential, then add Telegram → Send and Wait for Response (approval type: Approve/Disapprove). Message: the lead summary, score and draft. The workflow pauses until you tap a button.

  7. Send and update the log

    Add an IF on the approval result. Approved → Gmail → Send to the lead's email with the draft, then Google Sheets → Update Row Status = “Replied”. Disapproved → update Status = “Needs manual reply”.

  8. Add an error workflow

    Create a second workflow starting with Error Trigger → Telegram message: “Lead workflow failed: {{ $json.execution.error.message }}”. In the main workflow's Settings, set it as the Error Workflow. Now you'll know immediately if something breaks.

  9. Test with 10 realistic inquiries, then activate

    Include: a great lead, a vague one, a tiny budget, an urgent one, one in Taglish, and one spam message. Check scores and drafts, tune the prompts, then toggle the workflow to Active and share the production form URL.

Level it up

🤖

Swap in an AI Agent node

Give an AI Agent node tools (Google Calendar availability, your pricing sheet) so it can propose real meeting times.

📚

Add your knowledge

Connect a vector store with your services and FAQs so drafts reference your real offerings (RAG).

💬

More channels

Add triggers for Facebook Messenger, WhatsApp Business or email so every channel flows into the same pipeline.

📅

Follow-ups

A scheduled workflow checks the sheet daily and drafts follow-ups for leads with no reply after 3 days.

Key takeaways

  • n8n runs free with one Docker command; use a VPS or n8n Cloud for always-on client work.
  • Use a Structured Output Parser so AI output is reliable JSON the workflow can branch on.
  • Send and Wait for Response gives you one-tap human approval before anything is sent.
  • An error workflow and a log sheet make it trustworthy enough to run a real business on.

Knowledge check

0 / 3

Q1n8n runs in Docker and Ollama on the host machine. Which base URL?

Q2Why attach a Structured Output Parser?

Q3Which node pauses the workflow for your approval?

Finished this lesson?Your progress is saved in this browser.