{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "63f3ae8a-c85d-4203-a323-69effe6b4031",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3792,
        3312
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "your-sheet-url",
          "cachedResultName": "your-sheet-name"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "your-document-id",
          "cachedResultUrl": "your-sheet-url",
          "cachedResultName": "your-sheet-name"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "c8c9b20d-3378-40da-947c-917ccd76b266",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        3584,
        3312
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "ec4681fe-1cad-434c-8936-fd0e3a08a013",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        4448,
        3376
      ],
      "parameters": {
        "jsCode": "return items.map(item => {\n  const data = item.json;\n\n  return {\n    json: {\n      ...data,\n      Email: data[\"Work Email\"] || data[\"Personal Email\"] || '',\n      Phone: data[\"Work Number\"] || data[\"Personal Number\"] || '',\n      Company: data[\"Provider Name\"] || '',\n      Person: data[\"First Name\"] || '',\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "9ca1eba8-d2d9-4a2e-acc4-8f5833777c32",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        4016,
        3312
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "016cc438-5954-440f-a9df-057e6b478c4a",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{$json.Status}}",
              "rightValue": "="
            },
            {
              "id": "247f743e-8389-4aaf-841f-22b5eeff337b",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{$json.NextActionDate}}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "5aeacd57-5b47-4a28-af73-8a4ea6c7c02e",
      "name": "Parse AI",
      "type": "n8n-nodes-base.code",
      "position": [
        5408,
        3392
      ],
      "parameters": {
        "jsCode": "return items.map(item => {\n  const data = item.json;\n\n  // Safely extract AI text\n  const content =\n    data.output?.[0]?.content?.find(c => c.type === \"output_text\")?.text ||\n    data.output?.[0]?.content?.[0]?.text ||\n    \"{}\";\n\n  let parsed = {};\n  try {\n    parsed = JSON.parse(content);\n  } catch (e) {\n    parsed = {};\n  }\n\n  return {\n    json: {\n      ...data,\n\n      AI_Category: parsed.category || \"\",\n      AI_LeadScore: parsed.lead_score || \"\",\n      AI_Priority: parsed.priority || \"\",\n      Channel: parsed.recommended_channel || \"Email\",\n      AI_Reason: parsed.reason || \"\",\n\n      // fallback safety\n      AI_Status: parsed.category ? \"parsed\" : \"fallback\"\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "921325b2-e393-4eb2-8bd7-4de8472426b0",
      "name": "Save Message",
      "type": "n8n-nodes-base.code",
      "position": [
        6416,
        3136
      ],
      "parameters": {
        "jsCode": "return items.map(item => {\n  const content =\n    item.json.output?.[0]?.content?.find(c => c.type === \"output_text\")?.text ||\n    item.json.output?.[0]?.content?.[0]?.text ||\n    \"\";\n\n  return {\n    json: {\n      ...item.json,\n      AI_FirstMessage: content || `Hi ${item.json.Person}, quick question regarding ${item.json.Company}`\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "e941f7e1-f4d9-4f0b-a7cf-2faf81f03dec",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        6640,
        3136
      ],
      "parameters": {
        "sendTo": "={{$json.Email}}",
        "message": "={{$json.AI_FirstMessage}}",
        "options": {},
        "subject": "\"Quick question\""
      },
      "typeVersion": 2.2
    },
    {
      "id": "803d5adc-264f-4375-872b-2ebf179f1e9b",
      "name": "Update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        6896,
        3136
      ],
      "parameters": {
        "columns": {
          "value": {
            "#": "={{ $('Get row(s) in sheet').item.json['#'] }}",
            "Step": "1",
            "Status": "Contacted",
            "Channel": "={{$json.Channel}}",
            "AI_Category": "={{$json.AI_Category}}",
            "AI_Priority": "={{$json.AI_Priority}}",
            "AI_LeadScore": "={{$json.AI_LeadScore}}",
            "LastContacted": "={{new Date().toISOString()}}",
            "NextActionDate": "={{new Date(Date.now() + 2*24*60*60*1000).toISOString()}}",
            "AI_FirstMessage": "={{$json.AI_FirstMessage}}"
          },
          "schema": [
            {
              "id": "#",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "#",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Provider Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Provider Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Address",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "City/Town",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "City/Town",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Country",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Country",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Website",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company LinkedIn",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Company LinkedIn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Contact Person LinkedIn",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Contact Person LinkedIn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "First Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "First Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Last Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Last Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Title",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Headline",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Headline",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Personal Email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Personal Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Work Email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Work Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Personal Number ",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Personal Number ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Work Number",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Work Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Step",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Step",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "LastContacted",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "LastContacted",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "NextActionDate",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "NextActionDate",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Channel",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Channel",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_Category",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "AI_Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_LeadScore",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "AI_LeadScore",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_Priority",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "AI_Priority",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_FirstMessage",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "AI_FirstMessage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_FollowupMessage",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AI_FollowupMessage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Response",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Response",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "#"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "your-sheet-url",
          "cachedResultName": "your-sheet-name"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "your-document-id",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "c735bc31-f6f2-4ec6-87b9-8d0dbd0ac520",
      "name": "AI-Follow-up",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        6160,
        3728
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "GPT-4.1-MINI"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "=Write a short follow-up email.\n\nContext:\n- Company: {{$json.Company}}\n\nRules:\n- Friendly tone\n- Not pushy\n- Max 2 lines\n- Sound natural\n\nOutput ONLY the email."
            }
          ]
        },
        "builtInTools": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "8efb5838-fe40-4b52-9fd7-95b14457dd86",
      "name": "Parse Follow-up",
      "type": "n8n-nodes-base.code",
      "position": [
        6576,
        3728
      ],
      "parameters": {
        "jsCode": "return items.map(item => {\n  const content =\n    item.json.output?.[0]?.content?.find(c => c.type === \"output_text\")?.text ||\n    item.json.output?.[0]?.content?.[0]?.text ||\n    \"\";\n\n  return {\n    json: {\n      ...item.json,\n      AI_FollowupMessage: content || \"Just following up on my previous message \ud83d\ude42\"\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "8179a28f-d1aa-45b3-8b4f-fd3bf87e1c41",
      "name": "Send a message1",
      "type": "n8n-nodes-base.gmail",
      "position": [
        6832,
        3728
      ],
      "parameters": {
        "sendTo": "={{$json.Email}}",
        "message": "={{$json.AI_FollowupMessage}}",
        "options": {},
        "subject": "Follow-up: \"Quick question\""
      },
      "typeVersion": 2.2
    },
    {
      "id": "f52f324e-1426-4ec7-a564-bc25c346d396",
      "name": "Update row in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        7040,
        3728
      ],
      "parameters": {
        "columns": {
          "value": {
            "#": "={{ $('Get row(s) in sheet').item.json['#'] }}",
            "Step": "2",
            "Status": "Follow-up",
            "LastContacted": "={{new Date().toISOString()}}",
            "NextActionDate": "={{new Date(Date.now() + 3*24*60*60*1000).toISOString()}}",
            "AI_FollowupMessage": "={{$json.AI_FollowupMessage}}"
          },
          "schema": [
            {
              "id": "#",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "#",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Provider Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Provider Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Address",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "City/Town",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "City/Town",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Country",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Country",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Website",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company LinkedIn",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Company LinkedIn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Contact Person LinkedIn",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Contact Person LinkedIn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "First Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "First Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Last Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Last Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Title",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Headline",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Headline",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Personal Email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Personal Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Work Email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Work Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Personal Number ",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Personal Number ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Work Number",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Work Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Step",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Step",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "LastContacted",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "LastContacted",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "NextActionDate",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "NextActionDate",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Channel",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Channel",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_Category",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AI_Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_LeadScore",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AI_LeadScore",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_Priority",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AI_Priority",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_FirstMessage",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AI_FirstMessage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_FollowupMessage",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "AI_FollowupMessage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Response",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Response",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "#"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "your-sheet-url",
          "cachedResultName": "your-sheet-name"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "your-document-id",
          "cachedResultUrl": "your-document-url",
          "cachedResultName": "your-document-name"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "7f8cf390-a465-4038-b9e9-1a67a5f8bc71",
      "name": "AI-Lead-Analysis",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        5072,
        3392
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "GPT-4.1-MINI"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "=Analyze this lead:\n\nCompany: {{$json.Company}}\nWebsite: {{$json.Website}}\nRole: {{$json.Title}}\nCountry: {{$json.Country}}\n\nReturn JSON:\n{\n  \"category\": \"\",\n  \"lead_score\": \"Hot/Warm/Cold\",\n  \"priority\": \"High/Medium/Low\",\n  \"recommended_channel\": \"Email/Phone\",\n  \"reason\": \"\"\n}\n"
            },
            {
              "role": "system",
              "content": "You are a senior B2B sales strategist.\n\nYour job is to evaluate leads for outbound sales.\n\nEvaluation criteria:\n- Decision-making authority (CEO, Founder, Director preferred)\n- Company presence (website, LinkedIn)\n- Contact availability (email > phone)\n- Market relevance\n\nBe strict and realistic.\n\nReturn ONLY JSON.\n\n"
            }
          ]
        },
        "builtInTools": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "20d28269-194f-40db-8640-798db0bf150a",
      "name": "First AI mail",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        6080,
        3136
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "GPT-4.1-MINI"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "content": "=Write a highly personalized cold email.\n\nContext:\n- Company: {{$json.Company}}\n- Contact: {{$json.Person}}\n- Role: {{$json.Title}}\n\nRules:\n- Max 2 lines\n- No fluff, no AI tone\n- Make it feel human\n- Focus on a clear benefit\n\nAvoid:\n- \"I hope you're doing well\"\n- Generic intros\n\nOutput ONLY the email body."
            }
          ]
        },
        "builtInTools": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "58abc29d-35e6-422a-bc8a-dcaeecd75d1d",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        4688,
        3376
      ],
      "parameters": {
        "options": {},
        "batchSize": 5
      },
      "typeVersion": 3
    },
    {
      "id": "ae6ab323-256e-41f5-8e0b-bb09457acb0c",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        5680,
        3376
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c758441d-b857-47dc-87de-539b96497783",
                    "operator": {
                      "type": "number",
                      "operation": "empty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $('Loop Over Items').item.json.Status }}",
                    "rightValue": ""
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d01ce9f0-6869-4c65-a330-d11aa4fc3b81",
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Loop Over Items').item.json.Step }}",
                    "rightValue": 1
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "b07303ca-7ba1-4dc2-a1c8-0b7fd58aa912",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5984,
        3424
      ],
      "parameters": {
        "color": 7,
        "width": 1888,
        "height": 608,
        "content": "## Step 5 \u2013 Follow-up and pipeline completion\n\nCreates and sends follow-up emails, updates CRM progression, and marks leads as closed once the outreach sequence is complete.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "63a5a026-3835-49a4-88ac-87f0fd9feceb",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "position": [
        7440,
        3728
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "956b9d48-0b03-4585-ae37-dfab19d27cbb",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $('Loop Over Items').item.json.Response }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "c473aba9-b1ce-478d-b669-1f9b085116cb",
      "name": "Update row in sheet2",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        7664,
        3712
      ],
      "parameters": {
        "columns": {
          "value": {
            "#": "={{ $('Get row(s) in sheet').item.json['#'] }}",
            "Step": "3",
            "Status": "Closed",
            "Response": "No replies from the lead till now. So the lead has been closed."
          },
          "schema": [
            {
              "id": "#",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "#",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Provider Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Provider Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Address",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "City/Town",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "City/Town",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Country",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Country",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Website",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company LinkedIn",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Company LinkedIn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Contact Person LinkedIn",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Contact Person LinkedIn",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "First Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "First Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Last Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Last Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Title",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Headline",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Headline",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Personal Email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Personal Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Work Email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Work Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Personal Number ",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Personal Number ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Work Number",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Work Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Step",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Step",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "LastContacted",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "LastContacted",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "NextActionDate",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "NextActionDate",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Channel",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Channel",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_Category",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AI_Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_LeadScore",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AI_LeadScore",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_Priority",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AI_Priority",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_FirstMessage",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AI_FirstMessage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI_FollowupMessage",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AI_FollowupMessage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Response",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Response",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "#"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "d260f58c-3eae-48fa-9fa2-c90f248eeb6b",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2880,
        2880
      ],
      "parameters": {
        "width": 512,
        "height": 1152,
        "content": "### AI lead nurturing and cold email automation with Google Sheets and OpenAI\n\nAutomate lead qualification, personalized outreach, and follow-ups using AI and a Google Sheets CRM.\n\n**What it does**\n\u2022 Reads leads from Google Sheets  \n\u2022 Uses AI to score and prioritize leads  \n\u2022 Sends personalized cold emails  \n\u2022 Generates follow-up messages automatically  \n\u2022 Tracks outreach status and next steps  \n\u2022 Updates CRM in real-time  \n\n**Who it\u2019s for**\n\u2022 B2B sales teams  \n\u2022 Agencies and freelancers  \n\u2022 Founders scaling outbound outreach  \n\n**Setup**\n\u2022 Connect Google Sheets, OpenAI, Gmail  \n\u2022 Ensure columns: Email, Name, Company, Status, Step  \n\u2022 Do not hardcode credentials  \n\n**Tip**\nUse Step + NextActionDate to control multi-step outreach sequences."
      },
      "typeVersion": 1
    },
    {
      "id": "9f86540d-d1c5-44cf-9045-690582fae9de",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3408,
        2880
      ],
      "parameters": {
        "color": 7,
        "width": 832,
        "height": 1152,
        "content": "## Step 1 \u2013 Trigger and lead intake\n\nRuns on a schedule, fetches leads from Google Sheets, and filters only records that need outreach based on Status or NextActionDate.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "de49b9e8-2d9d-41d4-99c3-f691e63aae17",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5008,
        2880
      ],
      "parameters": {
        "color": 7,
        "width": 880,
        "height": 1152,
        "content": "## Step 3 \u2013 AI lead scoring and routing\n\nAnalyzes each lead using OpenAI to assign score, priority, and channel, then routes leads based on outreach step (new, follow-up, closed).\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ade06f21-816a-4df9-b618-1749fcaf7cb9",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4272,
        2880
      ],
      "parameters": {
        "color": 7,
        "width": 704,
        "height": 1152,
        "content": "## Step 2 \u2013 Data preparation and batching\n\nNormalizes lead fields (email, phone, company, person) and processes leads in batches to ensure scalability and avoid rate limits.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "59f85b03-59ba-4e3f-8869-b2b2aa24a266",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5984,
        2880
      ],
      "parameters": {
        "color": 7,
        "width": 1872,
        "height": 512,
        "content": "## Step 4 \u2013 First outreach automation\n\nGenerates and sends a personalized cold email, then updates CRM with Step, Status, AI insights, and next action date.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2e76fa5c-1572-4cef-9e17-c1aeddfddd6d",
      "name": "Wait1",
      "type": "n8n-nodes-base.wait",
      "position": [
        7232,
        3728
      ],
      "parameters": {
        "unit": "days",
        "amount": 2
      },
      "typeVersion": 1.1
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Update row in sheet2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait1": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "First AI mail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI-Follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI-Follow-up": {
      "main": [
        [
          {
            "node": "Parse Follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Message": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "First AI mail": {
      "main": [
        [
          {
            "node": "Save Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message": {
      "main": [
        [
          {
            "node": "Update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "AI-Lead-Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Follow-up": {
      "main": [
        [
          {
            "node": "Send a message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message1": {
      "main": [
        [
          {
            "node": "Update row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI-Lead-Analysis": {
      "main": [
        [
          {
            "node": "Parse AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update row in sheet": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update row in sheet1": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update row in sheet2": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}