AutomationFlowsAI & RAG › Lead Gen Agent with Google Maps, Openai and Serpai

Lead Gen Agent with Google Maps, Openai and Serpai

Lead Gen Agent with Google Maps, OpenAI and SerpAI. Uses chatTrigger, agent, lmChatOpenAi, memoryBufferWindow. Chat trigger; 10 nodes.

Chat trigger trigger★★★★☆ complexityAI-powered10 nodesChat TriggerAgentOpenAI ChatMemory Buffer WindowTool Serp ApiOutput Parser StructuredGoogle Sheets
AI & RAG Trigger: Chat trigger Nodes: 10 Complexity: ★★★★☆ AI nodes: yes Added:

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

This workflow follows the Agent → Chat Trigger 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
{
  "name": "Lead Gen Agent with Google Maps, OpenAI and SerpAI",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "id": "d61793a8-91d5-49bf-a707-49e6dfa68d39",
      "name": "Trigger - When User Sends Message",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        760,
        380
      ],
      "typeVersion": 1.1
    },
    {
      "parameters": {
        "hasOutputParser": true,
        "options": {
          "systemMessage": "=' UNIFIED AND OPTIMIZED PROMPT FOR DATA EXTRACTION VIA GOOGLE MAPS SCRAPER\n\n' --- 1. Task ---\n' - Collect high-quality professional leads from Google Maps, including:\n'   - Business name\n'   - Address\n'   - Phone number\n'   - Website\n'   - Email\n'   - Other relevant contact details\n' - Deliver organized, accurate, and actionable data.\n\n' --- 2. Context & Collaboration ---\n' - Tools & Sources:\n'   * Google Maps Scraper: Extracts data based on location, business type, and country code \n'     (ISO 3166 Alpha-2 in lowercase).\n'   * Website Scraper: Extracts data from provided URLs (the URL must be passed exactly as received, without quotation marks).\n'   * Google Sheets: Stores and retrieves previously extracted data.\n'   * Internet Search: Provides additional information if the scraping results are incomplete.\n' - Priorities: Accuracy and efficiency, avoiding unnecessary searches.\n\n' --- 3. Ethical Guidelines ---\n' - Only extract publicly accessible professional data.\n' - Do not collect or store personal/sensitive data.\n' - Adhere to scraping policies and data protection regulations.\n' - Error Handling:\n'   * In case of failure or incomplete results, suggest a retry, adjusted search parameters, or an alternative source.\n'   * If Google Sheets is unavailable, notify the user and propose workarounds.\n\n' --- 4. Constraints ---\n' - Country codes must follow the ISO 3166 Alpha-2 format in lowercase (e.g., \"fr\" for France).\n' - When using the Website Scraper, pass the URL exactly as provided, without quotation marks or modifications.\n' - Validate and correctly format all data (no duplicates or errors).\n' - Store results in Google Sheets in an organized and accessible manner.\n\n' --- 5. Final Requirements & Quality Checks ---\n' - Verification: Ensure the country code is always passed in lowercase to the Google Maps Scraper.\n' - URL: If a URL is provided, forward it directly to the Website Scraper without adding quotation marks.\n' - Existing Data: Check Google Sheets to see if the data is already available before performing new scraping.\n' - Supplementary: In case of partial results, propose using Internet Search to complete the information.\n\n' --- 6. Interaction ---\n' - If data already exists in Google Sheets, retrieve and present it to the user instead of launching a new scrape.\n' - If scraping fails or returns incomplete results, suggest alternative actions (e.g., web search, verifying the country code).\n\n' --- 7. Examples ---\n' BAD Example (Google Maps Scraper)\n'   User: \"Find coffee shops in Paris, France.\"\n'   AI: \"Extracting coffee shop data from Google Maps in France.\"\n'   > Issue: The country code \"fr\" was not provided.\n'\n' GOOD Example (Google Maps Scraper)\n'   User: \"Find coffee shops in Paris, France.\"\n'   AI:\n'     - \"Extracting coffee shop data from Google Maps in fr (France).\"\n'     - \"Scraped 50 businesses with names, addresses, phone numbers, and websites.\"\n'     - \"Storing results in Google Sheets under Lead_Generation_Paris_FR.\"\n'\n' BAD Example (Website Scraper)\n'   User: \"Scrape data from https://www.example.com/\"\n'   AI: \"Forwarding 'https://www.example.com/' to the Website Scraper.\"\n'   > Issue: Unnecessary quotation marks around the URL.\n'\n' GOOD Example (Website Scraper)\n'   User: \"Scrape data from https://www.example.com/\"\n'   AI:\n'     - \"Forwarding https://www.example.com to the Website Scraper.\"\n'     - \"Processing data extraction and storing results in Google Sheets.\"\n\n' --- 8. Output Format ---\n' - Responses should be concise and informative.\n' - Present data in a structured manner (e.g., business name, address, phone, website, etc.).\n' - If data already exists, clearly display the retrieved information from Google Sheets.\n\n' --- Additional Context & Details ---\n'\n' You interact with scraping APIs and databases to retrieve, update, and manage lead information.\n' Always pass country information using lowercase ISO 3166 Alpha-2 format when using the Google Maps Scraper.\n' If a URL is provided, it must be passed exactly as received, without quotation marks, to the Website Scraper.\n'\n' Known details:\n' You extract business names, addresses, phone numbers, websites, emails, and other relevant contact information.\n'\n' The URL must be passed exactly as provided (e.g., https://www.example.com/) without quotation marks or formatting changes.\n' Google Maps Scraper requires location, business type, and ISO 3166 Alpha-2 country codes to extract business listings.\n'\n' Context:\n' - System environment:\n'   You have direct integration with scraping tools, Internet search capabilities, and Google Sheets.\n'   You interact with scraping APIs and databases to retrieve, update, and manage lead information.\n'\n' Role:\n' You are a Lead Generation & Web Scraping Agent.\n' Your primary responsibility is to identify, collect, and organize relevant business leads by scraping websites, Google Maps, and performing Internet searches.\n' Ensure all extracted data is structured, accurate, and stored properly for easy access and analysis.\n' You have access to two scraping tools:\n'   1. Website Scraper \u2013 Requires only the raw URL to extract data from a specific website.\n'      - The URL must be passed exactly as provided (e.g., https://www.example.com/) without quotation marks or formatting changes.\n'   2. Google Maps Scraper \u2013 Requires location, business type, and ISO 3166 Alpha-2 country codes to extract business listings.\n\n' --- FINAL INSTRUCTIONS ---\n' 1. Adhere to all the directives and constraints above when extracting data from Google Maps (or other sources).\n' 2. Systematically check if data already exists in Google Sheets.\n' 3. In case of failure or partial results, propose an adjustment to the query or resort to Internet search.\n' 4. Ensure ethical compliance: only collect public data and do not store sensitive information.\n'\n' This prompt will guide the AI agent to efficiently extract and manage business data using Google Maps Scraper (and other mentioned tools)\n' while adhering to the structure, ISO country code standards, and ethical handling of information.\n"
        }
      },
      "id": "9ee9f551-d0a1-4bb1-9afe-f306e46bd0d5",
      "name": "AI Agent - Lead Collection",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        960,
        380
      ],
      "typeVersion": 1.8
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "id": "81834c63-5539-41ea-89b6-8e3e6a6de20f",
      "name": "GPT-4o - Generate & Process Requests",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        800,
        600
      ],
      "typeVersion": 1.2,
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "contextWindowLength": 50
      },
      "id": "19827e2a-0ba1-463c-ac24-7309ff6a1908",
      "name": "Memory - Track Recent Context",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        980,
        600
      ],
      "typeVersion": 1.3
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "34cce24a-63b5-4d88-94b7-0b7755b83cca",
      "name": "Fallback - Enrich with Google Search",
      "type": "@n8n/n8n-nodes-langchain.toolSerpApi",
      "position": [
        1140,
        600
      ],
      "typeVersion": 1,
      "credentials": {
        "serpApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "# AI-Powered Lead Generation Workflow\n\nThis workflow extracts business data from Google Maps and associated websites using an AI agent.\n\n## Dependencies\n- **OpenAI API**\n- **Google Sheets API**\n- **Apify Actors**: Google Maps Scraper \n- **Apify Actors**: Website Content Crawler\n- **SerpAPI**: Used as a fallback to enrich data\n\n## External Setup Guide\n**Notion** : [Guide](https://automatisation.notion.site/GOOGLE-MAPS-SCRAPER-1cc3d6550fd98005a99cea02986e7b05)\n",
        "height": 540,
        "width": 1300
      },
      "id": "946a9524-91e9-4ebb-970b-39665bdcfa05",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        380,
        240
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "jsonSchemaExample": "[\n  {\n    \"Name\": \"Vann Studio Salon\",\n    \"Type\": \"Beauty Salon\",\n    \"Address\": \"Seattle, WA\",\n    \"Phone\": \"(206) 441-5511\",\n    \"Website\": \"vann.studio\",\n    \"Rating\": \"4.8\",\n    \"Reviews\": \"733\",\n    \"Hours\": \"Open \u22c5 Closes 9 PM\",\n    \"Date_Collected\": \"2025-05-22\"\n  },\n  {\n    \"Name\": \"Salon XYZ\",\n    \"Type\": \"Hair Salon\",\n    \"Address\": \"Bellevue, WA\",\n    \"Phone\": \"(425) 123-4567\",\n    \"Website\": \"salonxyz.com\",\n    \"Rating\": \"4.5\",\n    \"Reviews\": \"210\",\n    \"Hours\": \"Open \u22c5 Closes 8 PM\",\n    \"Date_Collected\": \"2025-05-22\"\n  },\n  {\n    \"Name\": \"Urban Chic Spa\",\n    \"Type\": \"Spa\",\n    \"Address\": \"Redmond, WA\",\n    \"Phone\": \"(425) 765-4321\",\n    \"Website\": \"urbanchicspa.com\",\n    \"Rating\": \"4.7\",\n    \"Reviews\": \"156\",\n    \"Hours\": \"Open \u22c5 Closes 7 PM\",\n    \"Date_Collected\": \"2025-05-22\"\n  }\n]\n"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        1300,
        600
      ],
      "id": "e49c277d-42a4-4c69-871d-a1ba9f4b6381",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "1RRaU0h28iOlaRXlHoLNLuVpj7o3eglOz1x0dMukd-FQ",
          "mode": "list",
          "cachedResultName": "Lead_generation_n8n_agent_serpai",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RRaU0h28iOlaRXlHoLNLuVpj7o3eglOz1x0dMukd-FQ/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 740989378,
          "mode": "list",
          "cachedResultName": "Sheet2",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RRaU0h28iOlaRXlHoLNLuVpj7o3eglOz1x0dMukd-FQ/edit#gid=740989378"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Name": "={{ $json.Name }}",
            "Type": "={{ $json.Type }}",
            "Address": "={{ $json.Address }}",
            "Phone": "={{ $json.Phone }}",
            "Website": "={{ $json.Website }}",
            "Rating": "={{ $json.Rating }}",
            "Reviews": "={{ $json.Reviews }}",
            "Hours": "={{ $json.Hours }}",
            "Date_Collected": "={{ $json.Date_Collected }}"
          },
          "matchingColumns": [
            "Name"
          ],
          "schema": [
            {
              "id": "Name",
              "displayName": "Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Type",
              "displayName": "Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Address",
              "displayName": "Address",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone",
              "displayName": "Phone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Website",
              "displayName": "Website",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Rating",
              "displayName": "Rating",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Reviews",
              "displayName": "Reviews",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Hours",
              "displayName": "Hours",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Date_Collected",
              "displayName": "Date_Collected",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1560,
        380
      ],
      "id": "8a09cd11-50e4-49c3-bc72-d07d2af4ef06",
      "name": "Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "fieldToSplitOut": "output",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        1280,
        380
      ],
      "id": "cc443aeb-9cc9-4d52-b0a2-9406ddfe1898",
      "name": "Split Out"
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $json.Phone }}",
        "options": {
          "historySize": 100
        }
      },
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        1420,
        380
      ],
      "id": "66070b64-0a8e-47b9-b89d-6f30f23eb02b",
      "name": "Remove Duplicates"
    }
  ],
  "connections": {
    "Memory - Track Recent Context": {
      "ai_memory": [
        [
          {
            "node": "AI Agent - Lead Collection",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Trigger - When User Sends Message": {
      "main": [
        [
          {
            "node": "AI Agent - Lead Collection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fallback - Enrich with Google Search": {
      "ai_tool": [
        [
          {
            "node": "AI Agent - Lead Collection",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "GPT-4o - Generate & Process Requests": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent - Lead Collection",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent - Lead Collection",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Remove Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent - Lead Collection": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "versionId": "7846e892-cb1c-4324-9a8c-b7fdbeda9f3c",
  "meta": {
    "templateId": "3443",
    "templateCredsSetupCompleted": true
  },
  "id": "dhVSw2Bj8KAT6OxZ",
  "tags": [
    {
      "createdAt": "2025-05-22T20:33:42.851Z",
      "updatedAt": "2025-05-22T20:33:42.851Z",
      "id": "PfHfa1i7qdzf7Xph",
      "name": "leadgen"
    },
    {
      "createdAt": "2025-05-22T20:33:48.454Z",
      "updatedAt": "2025-05-22T20:33:48.454Z",
      "id": "x5boLy1Mxhllvwnu",
      "name": "lead generation"
    },
    {
      "createdAt": "2025-05-22T20:33:56.789Z",
      "updatedAt": "2025-05-22T20:33:56.789Z",
      "id": "MD0GzbsxKIPlvjLA",
      "name": "sales agent"
    }
  ]
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

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

About this workflow

Lead Gen Agent with Google Maps, OpenAI and SerpAI. Uses chatTrigger, agent, lmChatOpenAi, memoryBufferWindow. Chat trigger; 10 nodes.

Source: https://github.com/tenzinngodup/n8n_youtube_templates/blob/7194ebf6c211ac91dcc771f9faaa58282b412373/Lead_Gen_Agent_with_Google_Maps__OpenAI_and_SerpAI.json — 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

HDW Lead Geländewagen. Uses chatTrigger, lmChatOpenAi, memoryBufferWindow, outputParserStructured. Chat trigger; 92 nodes.

Chat Trigger, OpenAI Chat, Memory Buffer Window +5
AI & RAG

Who is this workflow for? This workflow is designed for SEO analysts, content creators, marketing agencies, and developers who need to index a website and then interact with its content as if it were

Agent, OpenAI Chat, Memory Buffer Window +10
AI & RAG

This project is an automation workflow that generates a personalized resume and cover letter for each job listing. Generates an HTML resume from your data. Hosts it live on GitHub Pages. Converts it t

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

This powerful workflow can take hours of difficult research attempting to identify the perfect product to buy and condense it into a few short minutes. Simply typing the name of an item you wish to pu

Chat Trigger, OpenAI Chat, Memory Buffer Window +3
AI & RAG

This powerful workflow can take hours of difficult research attempting to identify the perfect online tool to aid you with your business and condenses it into a few short seconds. Simply typing the na

Chat Trigger, OpenAI Chat, Memory Buffer Window +3