AutomationFlowsAI & RAG › Capture and Enrich Leads with Gpt-4o, Postgres, Slack, Gmail and Your CRM

Capture and Enrich Leads with Gpt-4o, Postgres, Slack, Gmail and Your CRM

ByResilNext @rnair1996 on n8n.io

This workflow captures incoming leads from a webhook, enriches them using AI, and automates the entire sales pipeline. It validates data, scores leads as hot, warm, or cold, assigns them to sales reps, syncs with CRM systems, and triggers notifications and follow-ups.

Webhook trigger★★★★☆ complexityAI-powered25 nodesAgentOpenAI ChatOutput Parser StructuredPostgresHTTP RequestGmailSlackSalesforce
AI & RAG Trigger: Webhook Nodes: 25 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #14687 — we link there as the canonical source.

This workflow follows the Agent → Gmail recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "id": "d1c26f48-e01d-4d00-bd51-afb4d61e84c7",
      "name": "Lead Form Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1840,
        176
      ],
      "parameters": {
        "path": "lead-capture",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "lastNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "011d06ed-536d-4cde-975b-747e797c5886",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -1600,
        176
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "crmApiUrl",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__CRM API endpoint URL (HubSpot or GoHighLevel)__>"
            },
            {
              "id": "id-2",
              "name": "slackChannel",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Slack channel ID for notifications__>"
            },
            {
              "id": "id-3",
              "name": "salesReps",
              "type": "array",
              "value": "[\"user@example.com\", \"user@example.com\", \"user@example.com\"]"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "6fb5634a-f990-47d7-af8d-41a0e9b08af2",
      "name": "Validate Required Fields",
      "type": "n8n-nodes-base.if",
      "position": [
        -1248,
        176
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.body.name }}"
            },
            {
              "id": "id-2",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.body.email }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "e64c14e8-1008-4e15-8cc5-07363c0a8fc3",
      "name": "Normalize Lead Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -944,
        80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "name",
              "type": "string",
              "value": "={{ $json.body.name }}"
            },
            {
              "id": "id-2",
              "name": "email",
              "type": "string",
              "value": "={{ $json.body.email }}"
            },
            {
              "id": "id-3",
              "name": "phone",
              "type": "string",
              "value": "={{ $json.body.phone || '' }}"
            },
            {
              "id": "id-4",
              "name": "company",
              "type": "string",
              "value": "={{ $json.body.company || '' }}"
            },
            {
              "id": "id-5",
              "name": "message",
              "type": "string",
              "value": "={{ $json.body.message || '' }}"
            },
            {
              "id": "id-6",
              "name": "timestamp",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "58284cd4-9785-41cb-9750-f265006a3428",
      "name": "AI Lead Enrichment & Scoring",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -608,
        80
      ],
      "parameters": {
        "text": "=Lead Information:\nName: {{ $json.name }}\nEmail: {{ $json.email }}\nPhone: {{ $json.phone }}\nCompany: {{ $json.company }}\nMessage: {{ $json.message }}",
        "options": {
          "systemMessage": "You are a lead qualification and enrichment AI assistant.\n\nYour task is to:\n1. Classify the lead as hot, warm, or cold based on the provided information\n2. Analyze the lead quality and intent\n3. Provide enrichment insights about the company and potential value\n\nClassification criteria:\n- HOT: Clear buying intent, decision-maker role, established company, specific needs mentioned\n- WARM: Some interest shown, relevant company, but needs nurturing\n- COLD: Generic inquiry, unclear intent, or low-quality information\n\nReturn your analysis in the structured format defined by the output parser."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "6a7534c2-290e-4446-b738-4c132b7aaf34",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -656,
        304
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "6f42447a-229d-472c-a5b7-ab51ef5dd383",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -432,
        272
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"leadScore\": {\n      \"type\": \"string\",\n      \"enum\": [\"hot\", \"warm\", \"cold\"],\n      \"description\": \"Lead classification\"\n    },\n    \"scoreReason\": {\n      \"type\": \"string\",\n      \"description\": \"Explanation for the score\"\n    },\n    \"estimatedValue\": {\n      \"type\": \"number\",\n      \"description\": \"Estimated deal value in USD\"\n    },\n    \"companyInsights\": {\n      \"type\": \"string\",\n      \"description\": \"Insights about the company\"\n    },\n    \"recommendedAction\": {\n      \"type\": \"string\",\n      \"description\": \"Next steps for sales team\"\n    }\n  },\n  \"required\": [\"leadScore\", \"scoreReason\", \"estimatedValue\", \"recommendedAction\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "be718e66-97aa-43cc-ba95-949a165f63f5",
      "name": "Store Lead in Database",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -240,
        80
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "leads"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "name": "={{ $json.name }}",
            "email": "={{ $json.email }}",
            "phone": "={{ $json.phone }}",
            "company": "={{ $json.company }}",
            "message": "={{ $json.message }}",
            "created_at": "={{ $json.timestamp }}",
            "lead_score": "={{ $json.output.leadScore }}",
            "score_reason": "={{ $json.output.scoreReason }}",
            "estimated_value": "={{ $json.output.estimatedValue }}",
            "company_insights": "={{ $json.output.companyInsights }}",
            "recommended_action": "={{ $json.output.recommendedAction }}"
          },
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": []
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "1565a0c0-c8e5-4904-b485-48f028b4a5b2",
      "name": "Round-Robin Sales Assignment",
      "type": "n8n-nodes-base.code",
      "position": [
        -64,
        80
      ],
      "parameters": {
        "jsCode": "// Round-robin sales rep assignment\nconst salesReps = $('Workflow Configuration').first().json.salesReps;\nconst currentIndex = $execution.customData.get('salesRepIndex') || 0;\nconst assignedRep = salesReps[currentIndex % salesReps.length];\n\n// Update index for next execution\n$execution.customData.set('salesRepIndex', currentIndex + 1);\n\nreturn {\n  ...items[0].json,\n  assignedSalesRep: assignedRep\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "5fcfd48c-dfda-4be9-b925-b1f5ede0614d",
      "name": "Send to CRM",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        400,
        80
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').first().json.crmApiUrl }}",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"properties\": {\n    \"email\": \"{{ $json.email }}\",\n    \"firstname\": \"{{ $json.name.split(' ')[0] }}\",\n    \"lastname\": \"{{ $json.name.split(' ').slice(1).join(' ') }}\",\n    \"phone\": \"{{ $json.phone }}\",\n    \"company\": \"{{ $json.company }}\",\n    \"lead_score\": \"{{ $json.output.leadScore }}\",\n    \"estimated_value\": \"{{ $json.output.estimatedValue }}\",\n    \"hubspot_owner_id\": \"{{ $json.assignedSalesRep }}\"\n  }\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "<__PLACEHOLDER_VALUE__CRM API key or Bearer YOUR_TOKEN_HERE>"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "72cef10f-6f62-49e9-84ad-510c32fd7eae",
      "name": "Send Welcome Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        800,
        80
      ],
      "parameters": {
        "sendTo": "={{ $json.email }}",
        "message": "=<html>\n<body>\n<h2>Thank you for reaching out!</h2>\n<p>Hi {{ $json.name }},</p>\n<p>We've received your inquiry and our team is reviewing it. Based on your information, we've assigned {{ $json.assignedSalesRep }} to assist you.</p>\n<p>You can expect to hear from us within 24 hours.</p>\n<p>Best regards,<br>Sales Team</p>\n</body>\n</html>",
        "options": {},
        "subject": "Welcome! We received your inquiry"
      },
      "typeVersion": 2.2
    },
    {
      "id": "a818c1ee-b6b4-4cb3-abce-ed2f24af8f4e",
      "name": "Notify Sales Team",
      "type": "n8n-nodes-base.slack",
      "position": [
        1120,
        80
      ],
      "parameters": {
        "text": "=\ud83c\udfaf *New Lead Alert - {{ $json.output.leadScore.toUpperCase() }}*\n\n*Lead Details:*\n\u2022 Name: {{ $json.name }}\n\u2022 Email: {{ $json.email }}\n\u2022 Company: {{ $json.company }}\n\u2022 Phone: {{ $json.phone }}\n\n*AI Analysis:*\n\u2022 Score: {{ $json.output.leadScore }}\n\u2022 Estimated Value: ${{ $json.output.estimatedValue }}\n\u2022 Reason: {{ $json.output.scoreReason }}\n\n*Assignment:*\n\u2022 Assigned to: {{ $json.assignedSalesRep }}\n\u2022 Action: {{ $json.output.recommendedAction }}\n\n*Company Insights:*\n{{ $json.output.companyInsights }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Workflow Configuration').first().json.slackChannel }}"
        },
        "otherOptions": {}
      },
      "typeVersion": 2.4
    },
    {
      "id": "174d8228-368e-451f-a7e0-0fa35d6a1ad0",
      "name": "Log Activity",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1328,
        80
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "activity_log"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "timestamp": "={{ $now.toISO() }}",
            "crm_synced": true,
            "email_sent": true,
            "lead_email": "={{ $json.email }}",
            "lead_score": "={{ $json.output.leadScore }}",
            "assigned_rep": "={{ $json.assignedSalesRep }}",
            "activity_type": "lead_processed",
            "slack_notified": true
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "e79e2e68-364b-48c6-98fc-ca7ba4a053ca",
      "name": "Handle Validation Error",
      "type": "n8n-nodes-base.set",
      "position": [
        -992,
        608
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "error",
              "type": "string",
              "value": "Missing required fields: name or email"
            },
            {
              "id": "id-2",
              "name": "status",
              "type": "string",
              "value": "validation_failed"
            },
            {
              "id": "id-3",
              "name": "timestamp",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "75d7c6be-82d7-46bf-9ba1-b9a442929bfc",
      "name": "Create Salesforce Lead",
      "type": "n8n-nodes-base.salesforce",
      "position": [
        160,
        0
      ],
      "parameters": {
        "company": "={{ $json.company || 'Unknown' }}",
        "lastname": "={{ $json.name.split(' ').slice(1).join(' ') || $json.name }}",
        "additionalFields": {
          "email": "={{ $json.email }}",
          "owner": "={{ $json.assignedSalesRep }}",
          "phone": "={{ $json.phone }}",
          "rating": "={{ $json.output.leadScore === 'hot' ? 'Hot' : ($json.output.leadScore === 'warm' ? 'Warm' : 'Cold') }}",
          "status": "={{ $json.output.leadScore === 'hot' ? 'Working - Contacted' : ($json.output.leadScore === 'warm' ? 'Open - Not Contacted' : 'Unqualified') }}",
          "firstname": "={{ $json.name.split(' ')[0] }}",
          "leadSource": "Web Form",
          "description": "={{ $json.message }}"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "64d63540-4172-4563-974a-4977e03fe5cb",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2624,
        -32
      ],
      "parameters": {
        "width": 496,
        "height": 512,
        "content": "## How it works\nThis workflow captures incoming leads via a webhook and processes them through validation, enrichment, and automated routing.\n\nAfter validating required fields, the lead data is normalized and analyzed by an AI agent to classify it as hot, warm, or cold. The workflow enriches the lead with insights, estimated deal value, and recommended actions.\n\nLeads are stored in a database, assigned to sales reps using round-robin logic, and synced with CRM systems. The workflow sends a welcome email to the lead and notifies the sales team via Slack.\n\nAll activities are logged for tracking and analytics.\n\n## Setup steps\n- Configure webhook endpoint for lead capture\n- Add OpenAI API credentials\n- Set CRM API or Salesforce credentials\n- Configure Slack and Gmail integrations\n- Add Postgres database connection\n- Define sales reps for assignment logic"
      },
      "typeVersion": 1
    },
    {
      "id": "4a4c04e7-5abf-4f86-89de-317798794b3a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1920,
        96
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 256,
        "content": "## Input Layer\nCapture leads from webhook form submission"
      },
      "typeVersion": 1
    },
    {
      "id": "b754dd26-fbe2-4db6-86e7-4c7049fa074e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1312,
        64
      ],
      "parameters": {
        "color": 7,
        "height": 320,
        "content": "## Validation\nEnsure required fields like name and email"
      },
      "typeVersion": 1
    },
    {
      "id": "0a119ece-f30a-4e88-9be5-8843af7f1f07",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1024,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 240,
        "content": "## Data Preparation\nNormalize and structure lead information"
      },
      "typeVersion": 1
    },
    {
      "id": "8c4b67c4-0a63-420f-8ec5-30c0b7ec8b07",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1040,
        528
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 240,
        "content": "## send error report"
      },
      "typeVersion": 1
    },
    {
      "id": "63f7160f-78a4-4a8d-bcb3-a5f902bd2da9",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        -80
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 336,
        "content": "## AI Enrichment\nScore lead and generate insights"
      },
      "typeVersion": 1
    },
    {
      "id": "c74b1265-9df7-4c17-8df6-6efd5f580cf9",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -272,
        -80
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 320,
        "content": "## Data Storage and  Assignment Logic\nDistribute leads via round-robin system\nStore enriched lead in database"
      },
      "typeVersion": 1
    },
    {
      "id": "ab234f64-e006-486d-a03c-7a3a9b2fb2a0",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 352,
        "content": "## CRM Sync\nPush lead data to CRM or Salesforce"
      },
      "typeVersion": 1
    },
    {
      "id": "25dd43e8-c456-43a7-a615-c82c4b824a47",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -64
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 304,
        "content": "## Email Automation\nSend welcome email to the lead"
      },
      "typeVersion": 1
    },
    {
      "id": "5c6c5445-f97a-434d-86a3-be7c53656bc3",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        -64
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 304,
        "content": "## Team Notification and Logging\nNotify sales team via Slack  and \nTrack all actions for audit and analytics"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Send to CRM": {
      "main": [
        [
          {
            "node": "Send Welcome Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Form Webhook": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify Sales Team": {
      "main": [
        [
          {
            "node": "Log Activity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Lead Enrichment & Scoring",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Send Welcome Email": {
      "main": [
        [
          {
            "node": "Notify Sales Team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Lead Data": {
      "main": [
        [
          {
            "node": "AI Lead Enrichment & Scoring",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Salesforce Lead": {
      "main": [
        [
          {
            "node": "Send to CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store Lead in Database": {
      "main": [
        [
          {
            "node": "Round-Robin Sales Assignment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Validate Required Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Lead Enrichment & Scoring",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Validate Required Fields": {
      "main": [
        [
          {
            "node": "Normalize Lead Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Validation Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Lead Enrichment & Scoring": {
      "main": [
        [
          {
            "node": "Store Lead in Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Round-Robin Sales Assignment": {
      "main": [
        [
          {
            "node": "Send to CRM",
            "type": "main",
            "index": 0
          },
          {
            "node": "Create Salesforce Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow captures incoming leads from a webhook, enriches them using AI, and automates the entire sales pipeline. It validates data, scores leads as hot, warm, or cold, assigns them to sales reps, syncs with CRM systems, and triggers notifications and follow-ups.

Source: https://n8n.io/workflows/14687/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This workflow automates customer feedback processing by analyzing sentiment, identifying key issues, generating personalized responses, and escalating critical cases to support teams when required. De

Redis, Postgres, Agent +7
AI & RAG

This workflow automates veterinary clinic operations and client communications for animal hospitals and veterinary practices managing appointments, inventory, and patient care. It solves the dual chal

HTTP Request, Agent, OpenAI Chat +4
AI & RAG

🧾 Short Description

Agent, OpenAI Chat, Output Parser Structured +4
AI & RAG

This workflow automates the entire process of taking a raw user-submitted script, rewriting it into a polished HeyGen-ready narration, generating a full avatar video, handling all processing checks, r

HTTP Request, Agent, Memory Buffer Window +6
AI & RAG

This workflow automates end-to-end concert ticket booking validation and fan experience management using two coordinated AI agents. It is designed for ticketing platforms, event operators, and venue o

OpenAI Chat, Output Parser Structured, Agent +4