All Projects

B2B AI Leads Automation

B2B AI Leads Automation

B2B AI Leads Automation

A small B2B sales team was manually reviewing every inbound lead submission: looking up the prospect's company, deciding whether the fit justified outreach, writing a personalized cold email, and logging the contact to a spreadsheet. With no consistent qualification criteria, effort was distributed evenly across strong and weak leads alike.

We built an n8n pipeline that enriches every inbound lead via Apollo.io, scores them against an AI rubric, sends a personalized outreach email only to leads that qualify, and appends the record to a Google Sheet — all within a single automated execution.

The Workflow

Trigger: Three Entry Points

Node 1 - Form Trigger: "Contact Us" Renders a public web form with four fields: Full Name, Email Address, Phone Number, and LinkedIn Profile URL. On submission, all values pass downstream to the enrichment stage.

Node 2 - Webhook Listens on a fixed path for programmatic lead submissions — used when leads enter from a third-party system rather than the public form. Assumes the same field structure as the form trigger.

Node 3 - Google Sheets Trigger Polls every minute for new rows added to a connected sheet, enabling leads entered directly into a spreadsheet to enter the same pipeline. Requires a valid document ID and sheet name to be configured before deployment.


Stage 1: Lead Enrichment

Node 4 - HTTP Request → Apollo.io People Match POSTs to the Apollo.io /people/match endpoint with four query parameters: name, email, phone number, and LinkedIn URL from the form submission. Returns the enriched person object including job title, current company, industry, employment history, and seniority. Authentication uses a header-based API key.


Stage 2: AI Lead Scoring

Node 5 - AI Agent: Lead Scoring (Groq) Receives the Apollo-enriched person object and applies a two-dimension scoring rubric returning a single integer from 1 to 10:

INDUSTRY MATCH (5 points max)
  5 points: AI, Artificial Intelligence, Machine Learning, Data Science
  3–4 points: Analytics, automation, enterprise AI tools
  0–2 points: Unrelated industry

JOB TITLE MATCH (5 points max)
  5 points: Decision-makers in AI (Head of AI, AI Director, CTO, AI Product Manager)
  3–4 points: Mid-level AI professionals (ML Engineer, Data Scientist)
  0–2 points: Non-AI or junior roles

The agent returns only the numeric score — no explanation, no labels.

Node 6 - Groq Chat Model Powers the scoring agent via the ai_languageModel connection.


Stage 3: Qualification Gate

Node 7 - IF Node: Score Threshold Evaluates the score from the scoring agent as a number type. Leads scoring 6 or above proceed to outreach. Leads below 6 are silently dropped — no fallback log or notification exists for them in this build.


Stage 4: AI Outreach Email

Node 8 - AI Agent: Outreach Composer (Groq) Composes and sends a personalized outreach email for each qualifying lead. The agent acts as a professional B2B sales assistant, drafting a short, polite email to schedule a call. It is instructed to use the lead's name, company, and job title from the Apollo enrichment, and to dispatch the email using the connected Gmail tool.

Node 9 - Groq Chat Model Powers the outreach composition agent via the ai_languageModel connection.

Node 10 - Gmail Tool (AI-Controlled) Connected to the outreach agent as an ai_tool. The recipient address is set from the Apollo-enriched email field. Subject line and message body are fully delegated to the model via $fromAI() expressions.


Stage 5: CRM Logging

Node 11 - Structured Output Parser Connected to the outreach agent via ai_outputParser. Present in the pipeline to normalize agent output before the logging step.

Node 12 - Append Row in Google Sheets Appends a row to the "N8N Leads" sheet with six columns per qualified lead: Name, Email, Phone, Job Title, LinkedIn URL, and Organization. Written immediately after the outreach email is dispatched, creating a timestamped record for every contact touched.


Results

  • Enrichment fully automated — job title, company, industry, and employment history are surfaced from Apollo.io without any manual research per lead
  • AI scoring filters unqualified leads before outreach — only leads scoring 6 or above receive any system effort beyond enrichment
  • Personalized first-touch email generated and sent in the same execution — no human drafting step between qualification and outreach
  • Google Sheet updated after each send — the sales team has a running log of every contacted lead with structured enrichment data
  • Flexible intake — form, webhook, and sheet trigger support leads entering from multiple upstream sources through the same pipeline

Stack

LayerTool
Automationn8n (self-hosted)
Triggersn8n Form Trigger · Webhook · Google Sheets Trigger
Lead EnrichmentApollo.io people/match API (header-based auth)
AI ScoringGroq (LangChain agent)
AI OutreachGroq (LangChain agent)
Email DispatchGmail (gmailTool, AI-controlled subject and message)
CRM LoggingGoogle Sheets (append)

My Role

  • Designed the three-trigger intake: public form, webhook endpoint, and Google Sheets polling — covering both manual and programmatic lead sources
  • Configured the Apollo.io HTTP Request with header-based API key auth and all four query parameter mappings from form fields
  • Built the AI scoring agent with a structured two-dimension rubric (industry match + job title match, 5 points each) and a single-digit numeric output instruction
  • Implemented the qualification gate using a strict number-type threshold of 6, with silent drop for leads that do not qualify
  • Configured the outreach composition agent with a B2B sales persona prompt and Gmail tool dispatch instruction
  • Wired the Gmail tool with a static recipient expression from the Apollo enrichment and $fromAI() expressions for subject and body
  • Set up the Google Sheets append node with six column mappings to create a post-outreach lead log