We architected an end-to-end n8n workflow pipeline combining Google Sheets API, web scraping, Serper Google Search API, and OpenAI gpt-4o-mini. The pipeline executes custom logic: lead processing choice (new leads vs rewrite), bottom-up sheet reversing, website text extraction, Serper search for department needs, and heavily engineered GPT prompts enforcing strict copywriting, tone, credibility, and spam-safety rules.
1. Start & Lead Filtering Strategy
The pipeline launches via a webhook form asking whether to process only new leads or rewrite existing ones (defaulting safely to new leads). It pulls all rows from the Google Sheet, reverses them to process bottom-up (oldest to newest), skips empty rows or leads with existing drafts, and flags incomplete leads as "Skipped - missing data" in the sheet for team completion.
2. Live Web Scraping & Deep Research
For each lead, the workflow visits the target company's website, extracts page content, and executes a Serper API Google search on the organization and department to discover current projects, technical focus areas, and operational needs.
3. AI Copywriting Assembly Line
The extracted research and lead metadata feed into OpenAI gpt-4o-mini with a heavily engineered prompt: generating a 5–6 bullet Lead Summary (3 bullets on client operations/needs, 2–3 on matching NeuroFlares offerings) and a ~120-word spam-safe cold email featuring personalized greetings, domain-matched credibility lines, no marketing jargon or links, and a soft reply-based close.
4. Write-Back & Human-in-the-Loop Safeguards
The summary and draft email write directly back to the lead's row matched by Lead ID, updating Email Status to "Draft Ready". The workflow deliberately stops at draft ready, allowing human team members to review, attach HTML signatures, add project links, and send.