DEV Community

Cover image for How to automate lead generation with AI: Build a lead-enrichment pipeline that writes your icebreaker
Sam Chen
Sam Chen

Posted on Originally published at getaab.com

How to automate lead generation with AI: Build a lead-enrichment pipeline that writes your icebreaker

How do you automate lead generation with AI? You set up a workflow that scrapes prospect URLs, enriches each record with firmographic data, scores the lead, and finally asks an LLM to write a personalized opening line. The result is a ready-to-export CSV (or direct CRM push) that you can use for outbound outreach without manual research.

What is AI lead generation? AI lead generation is the process of using artificial intelligence to discover, enrich, and qualify prospects automatically.


What you need

Tool Plan / Price* Role
n8n (self-hosted) Community Edition - Free Orchestrates the entire pipeline
OpenAI GPT-4 API Pay-as-you-go (≈ $0.03 / 1 K prompt tokens, $0.06 / 1 K completion tokens) Generates icebreaker text and scoring logic
Browserless.io (headless Chrome) Free tier for low volume, paid plans start at $29/mo for 100 k runs Executes the web-scraping steps
HubSpot CRM (Free) Free Stores enriched leads and syncs with outreach tools
Google Sheets Free Quick view of results during development
Zapier (optional) Free tier for ≤ 100 tasks/mo Pushes scored leads to email outreach platforms

*Pricing is current as of August 2026; check each provider's pricing page for the latest details.

Estimated build time: 6-8 hours for a developer comfortable with n8n and basic API usage.


Step-by-step build

  1. Provision the n8n instance

    • Pull the Docker image: docker run -d --restart unless-stopped -p 5678:5678 n8nio/n8n
    • Open http://localhost:5678 and create a new workflow called Lead Enrichment + Icebreaker.
  2. Add a "HTTP Request" node to fetch a prospect list

    • Set Method to GET.
    • URL: https://api.example.com/prospects?status=active (replace with your source).
    • Enable Pagination if the API returns paged results.
  3. Split the list into individual items

    • Add a "SplitInBatches" node, batch size 1. This feeds each prospect into the downstream nodes one-by-one.
  4. Scrape the company website for extra data

    • Insert a "Browserless" node (provided by the Browserless.io integration).
    • Endpoint: https://chrome.browserless.io/scrape
    • Payload (JSON):
 {
 "url": "{{$json[\"website\"]}}",
 "actions": [
 {
 "type": "click",
 "selector": "a[data-contact]"
 },
 {
 "type": "waitForSelector",
 "selector": ".company-info"
 },
 {
 "type": "extract",
 "selector": ".company-info",
 "property": "innerText",
 "as": "companyInfo"
 }
 ]
 }
Enter fullscreen mode Exit fullscreen mode

What this does: Visits the prospect's website, clicks the contact link, waits for the company info block, and returns the raw text as companyInfo.

  1. Enrich with third-party data (e.g., Clearbit)

    • Add another "HTTP Request" node.
    • Method: GET
    • URL: https://person.clearbit.com/v2/people/find?email={{$json["email"]}}
    • Authentication: API Key header Authorization: Bearer YOUR_CLEARBIT_KEY.
  2. Score the lead

    • Insert a "Set" node called Score.
    • Add a field score with the expression:
 {{
 ($json["companyInfo"]?.includes("Fortune") ? 30 : 0) +
 ($json["clearbit"]["employment"]["title"]?.includes("CTO") ? 20 : 0) +
 ($json["openAiSentiment"]?.positive ? 10 : 0)
 }}
Enter fullscreen mode Exit fullscreen mode

This simple rule adds points for Fortune-500 mentions, a C-level title, and a positive sentiment from the icebreaker draft (computed later).

  1. Generate a personalized icebreaker
    • Add an "OpenAI" node (built-in in n8n).
    • Model: gpt-4
    • Prompt (copy-paste exact):
 You are a sales writer. Write a one-sentence icebreaker for a cold email to {{ $json["firstName"] }} {{ $json["lastName"] }} at {{ $json["company"] }}. Use the following context: {{ $json["companyInfo"] }}. Keep it under 20 words and include a reference to a recent news item or product launch if possible.
Enter fullscreen mode Exit fullscreen mode

What this does: Sends the prospect's enriched data to GPT-4, which returns a concise, context-aware opening line.

  1. Store results in Google Sheets (optional for review)

    • Add a "Google Sheets" node, connect to a sheet named Leads.
    • Map columns: First Name, Last Name, Email, Company, Score, Icebreaker.
  2. Push qualified leads to HubSpot

    • Insert a "HubSpot" node, set Operation to Create/Update Contact.
    • Map the same fields plus a custom property lead_score.
    • Enable a filter: only contacts with score >= 50 are sent.
  3. Activate the workflow

    • Set a cron trigger to run daily at 02:00 UTC.
    • Turn the workflow Active.

Your pipeline now automates lead generation with AI, delivering enriched, scored contacts and a ready-to-send icebreaker without any manual copy-pasting.


Where this breaks

Failure mode Symptoms Mitigation
Browserless rate limit Scrape nodes start returning HTTP 429 or empty companyInfo. Upgrade to a paid plan or add a "Throttle" node limiting calls to 10 req/min.
OpenAI token quota exceeded "Insufficient quota" error from the OpenAI node. Monitor usage via the OpenAI dashboard; set a daily cap in the workflow or switch to a lower-cost model (e.g., gpt-3.5-turbo).
Clearbit API key expiry 401 Unauthorized responses. Rotate the API key monthly; store the key in n8n's Credentials and enable automatic secret rotation if your vault supports it.
HubSpot field mismatch Leads are not created, error "Property does not exist". Verify custom properties (lead_score) exist in HubSpot before activation; use HubSpot's schema API to create missing fields programmatically.
Data quality gaps Empty companyInfo leads to low scores. Add a fallback "If/Else" branch: if companyInfo missing, assign a default low score and flag for manual review.
Cost blow-up Monthly spend spikes unexpectedly. Enable n8n's built-in Execution History alerts; set a budget alarm in OpenAI and Browserless dashboards.

For a deeper technical reference, see n8n's documentation.

FAQ

How can I replace Browserless with a cheaper scraper?

You can swap the Browserless node for a simple "HTTP Request" + Cheerio transformation node if the target sites expose data in static HTML. For JavaScript-heavy pages, a headless service is still the most reliable choice.

Do I need a paid OpenAI plan to generate icebreakers?

The free trial provides limited credits; for production use you'll need a pay-as-you-go plan. The cost per icebreaker is typically under $0.001 when using gpt-3.5-turbo.

What if my prospect list is larger than 10 k rows per month?

n8n can handle arbitrarily large batches, but you'll need to watch API limits for each vendor. Split the list into daily chunks and use the "Cron" node to stagger execution.

Can I push leads directly to an email-automation tool instead of HubSpot?

Yes. Replace the HubSpot node with a Zapier or Make.com webhook that targets Mailshake, Lemlist, or any tool that accepts JSON payloads.

How do I keep the icebreaker tone consistent across languages?

Add a language code to the prospect record and modify the OpenAI prompt: Write the icebreaker in {{ $json["language"] }}. GPT-4 handles dozens of languages with similar quality.


Ready to see the full workflow in action? Check out the Lead Enrichment Machine for a downloadable template and detailed walkthrough: https://getaab.com/vault/lead-enrichment-machine

Grab the free guide to scale this pipeline across multiple markets: https://getaab.com/free

Related reading

Top comments (0)