{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "b24f6e3c-007b-4d3b-a5a3-69248af3d85d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -832,
        352
      ],
      "parameters": {
        "color": 5,
        "width": 500,
        "height": 976,
        "content": "## Leadership Hire Enrichment & Automated Outreach\n\n### How it works\n1. A daily schedule trigger loads target accounts (company domains) from a Google Sheet and processes them in batches.\n2. For each company, the workflow retrieves active job openings from PredictLeads and filters for leadership roles (CRO, CMO, VP, Head of, etc.).\n3. In parallel, it detects sales hiring signals (SDR, AE, BDR titles) and checks whether the company has a high volume of open roles (10+), sending Slack alerts for each signal.\n4. When a leadership role is found, the workflow enriches the company profile via PredictLeads, logs the lead signals to Google Sheets, and uses GPT-4o-mini to generate a personalized outreach email referencing the hiring signal.\n5. The email is sent automatically via Gmail, then the workflow loops to the next batch item.\n\n### Setup\n1. Connect your **Google Sheets** credential and point the input node to a sheet with `domain` and `company_name` columns.\n2. Connect your **PredictLeads API** credential (get one at [predictleads.com](https://predictleads.com)).\n3. Connect your **Slack** credential and select the alert channel.\n4. Connect your **Gmail** credential for outreach delivery.\n5. Set the `OPENAI_API_KEY` environment variable in n8n for the GPT email generation step.\n\n### Customization\n- Edit the leadership title regex in the Filter Leadership Roles node to match your target personas.\n- Adjust the hiring volume threshold in the High Hiring Volume? node (default is 10).\n- Modify the AI prompt in the Build AI Prompt node to match your product and tone."
      },
      "typeVersion": 1
    },
    {
      "id": "d24eb37f-b18b-49fb-ab56-6a3ff5191592",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        256,
        704
      ],
      "parameters": {
        "width": 504,
        "height": 360,
        "content": "## Trigger & Input\nRuns daily at 8 AM and loads target company domains from Google Sheets."
      },
      "typeVersion": 1
    },
    {
      "id": "65986f83-9ce9-46c3-bc21-33330d769727",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        704
      ],
      "parameters": {
        "width": 1048,
        "height": 376,
        "content": "## Hiring Data & Leadership Detection\nBatches companies, retrieves job openings from PredictLeads, filters for leadership titles, and routes based on match."
      },
      "typeVersion": 1
    },
    {
      "id": "c2fbd2e7-d346-426a-a288-eb1a778f8071",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1936,
        512
      ],
      "parameters": {
        "width": 764,
        "height": 856,
        "content": "## Sales & Volume Signals\nDetects sales hiring patterns and high job volume in parallel, sending Slack alerts for each signal type."
      },
      "typeVersion": 1
    },
    {
      "id": "18ecf76b-b72a-4e24-b23b-32d92bb86c9b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2736,
        560
      ],
      "parameters": {
        "width": 1052,
        "height": 504,
        "content": "## Company Enrichment & AI Outreach\nEnriches the company profile, logs lead signals, generates a personalized email with GPT, and sends via Gmail."
      },
      "typeVersion": 1
    },
    {
      "id": "a0a7402e-99a6-4388-a9b8-c1e6261baeab",
      "name": "Daily Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        304,
        912
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 8 * * *"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "bcf5d17a-5d67-4fc2-b411-fbe30783dd0c",
      "name": "Load Target Accounts",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        528,
        912
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oKKM8_x41e70cvW4FlZqdd8qWoPcW2gFfx0BofIjR2I/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1oKKM8_x41e70cvW4FlZqdd8qWoPcW2gFfx0BofIjR2I",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oKKM8_x41e70cvW4FlZqdd8qWoPcW2gFfx0BofIjR2I/edit?usp=drivesdk",
          "cachedResultName": "03"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "07401318-9ebf-4997-b20f-ab5cc0dc802e",
      "name": "Split Into Batches",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        816,
        912
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "0506ea26-a4e2-46d5-b730-9951938e06c9",
      "name": "Retrieve Company Job Openings",
      "type": "@predictleads/n8n-nodes-predictleads.predictLeads",
      "position": [
        1056,
        928
      ],
      "parameters": {
        "domain": "={{ $json.domain }}",
        "resource": "jobOpenings",
        "notClosed": true,
        "operation": "retrieveCompanyJobOpenings",
        "activeOnly": true,
        "requestOptions": {}
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "8b48d461-be39-446d-a877-044325859baa",
      "name": "Filter Leadership Roles",
      "type": "n8n-nodes-base.code",
      "position": [
        1504,
        928
      ],
      "parameters": {
        "jsCode": "// Filter job openings for leadership roles\nconst leadershipPattern = /\\b(CRO|CMO|CTO|VP|Vice President|Head of|Chief)\\b/i;\n\nconst items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n  const jobOpenings = item.json.data || [];\n const domain = $('Split Into Batches').first().json.domain || '';\nconst companyName = $('Split Into Batches').first().json.company_name || '';\n  \n  const leadershipRoles = jobOpenings.filter(job => {\n    const title = (job.attributes?.title || job.title || '').toString();\n    return leadershipPattern.test(title);\n  });\n  \n  if (leadershipRoles.length > 0) {\n    results.push({\n      json: {\n        domain: domain,\n        company_name: companyName,\n        leadership_roles: leadershipRoles.map(job => ({\n          title: job.attributes?.title || job.title || 'Unknown',\n          location: job.attributes?.location || job.location || 'Not specified',\n          url: job.attributes?.url || job.url || ''\n        })),\n        leadership_found: true\n      }\n    });\n  } else {\n    results.push({\n      json: {\n        domain: domain,\n        company_name: companyName,\n        leadership_roles: [],\n        leadership_found: false\n      }\n    });\n  }\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "91618b01-3693-42d0-af13-217ed29c41f3",
      "name": "Leadership Role Found?",
      "type": "n8n-nodes-base.if",
      "position": [
        1680,
        928
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "condition-leadership",
              "operator": {
                "type": "boolean",
                "operation": "true"
              },
              "leftValue": "={{ $json.leadership_found }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "2845bbb0-27b2-4ee9-8a06-23f5c0785140",
      "name": "Detect Sales Hiring Signals",
      "type": "n8n-nodes-base.code",
      "position": [
        1984,
        688
      ],
      "parameters": {
        "jsCode": "const salesPattern = /\\b(SDR|Sales|Account Executive|Business Development)\\b/i;\n\nconst items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n  const jobs = item.json.data || [];\n\n  const domain = $('Split Into Batches').first().json.domain || '';\n  const companyName = $('Split Into Batches').first().json.company_name || '';\n\n  const salesRoles = jobs.filter(job => {\n    const title = (job.attributes?.title || '').toString();\n    return salesPattern.test(title);\n  });\n\n  results.push({\n    json: {\n      domain,\n      company_name: companyName,\n      sales_roles: salesRoles.map(j => j.attributes?.title),\n      sales_hiring: salesRoles.length > 0\n    }\n  });\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "4583125e-0833-414b-b38d-7a819952b706",
      "name": "Sales Hiring Detected?",
      "type": "n8n-nodes-base.if",
      "position": [
        2192,
        688
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "af250130-eb2a-4fd8-9ed0-4050be1106e8",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.sales_hiring }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b46fac4c-3a96-419e-a468-2ae657281e58",
      "name": "Send Sales Hiring Alert",
      "type": "n8n-nodes-base.slack",
      "position": [
        2448,
        672
      ],
      "parameters": {
        "text": "=\ud83d\udd25 Sales Hiring Detected!  Company: {{$json.company_name}} Domain: {{$json.domain}}  Roles: {{$json.sales_roles.join(', ')}}  \ud83d\udc49 Potential CRM / sales tool lead",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AEEATQQEP",
          "cachedResultName": "buddieslab-umer"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "typeVersion": 2.4
    },
    {
      "id": "944cf064-c3e6-4042-9ce6-4ac4fd6de97e",
      "name": "Calculate Job Count",
      "type": "n8n-nodes-base.set",
      "position": [
        1984,
        1216
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "94ad73cf-1306-4f53-9abe-72978f506f23",
              "name": "job_count",
              "type": "string",
              "value": "={{ $json.data.length }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ea9adf4a-e05a-4e24-9430-ca34778c1430",
      "name": "High Hiring Volume?",
      "type": "n8n-nodes-base.if",
      "position": [
        2176,
        1216
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8a50bba2-d6a5-419a-adad-2458e0f3b3b5",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.job_count }}",
              "rightValue": 10
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "a26d3d73-449b-46c8-9941-7c4c9d97c9e6",
      "name": "Send Hiring Spike Alert",
      "type": "n8n-nodes-base.slack",
      "position": [
        2432,
        1200
      ],
      "parameters": {
        "text": "=\ud83d\ude80 High Hiring Alert!\n\nCompany: {{ $('Retrieve Company Job Openings').item.json.included[0].attributes.company_name }}\nDomain: {{ $('Retrieve Company Job Openings').item.json.included[0].attributes.domain }}\n\nOpen Roles: {{$json.job_count}}\n\n\ud83d\udc49 This company is scaling fast \u2014 potential high-value lead.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AEEATQQEP",
          "cachedResultName": "buddieslab-umer"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "typeVersion": 2.4
    },
    {
      "id": "73a76559-fbb1-44f1-8866-debf005b9dfe",
      "name": "Retrieve Company",
      "type": "@predictleads/n8n-nodes-predictleads.predictLeads",
      "position": [
        2784,
        912
      ],
      "parameters": {
        "domain": "={{ $json.domain }}",
        "operation": "retrieveCompany",
        "requestOptions": {}
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "2635eddd-45f4-4ac3-b694-7825b840478f",
      "name": "Store Lead Signals",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3008,
        736
      ],
      "parameters": {
        "columns": {
          "value": {
            "domain": "={{ $json.data[0].attributes.domain }}",
            "job_count": "={{ $('Retrieve Company Job Openings').item.json.data.length }}",
            "timestamp": "={{ new Date().toISOString() }}",
            "signal_type": "={{ $json.leadership_found ? \"leadership_hiring\" : \"high_hiring_volume\" }}",
            "company_name": "={{ $json.data[0].attributes.company_name }}",
            "leadership_roles": "={{ $('Filter Leadership Roles').item.json.leadership_roles.map(r => r.title).join(', ') }}"
          },
          "schema": [
            {
              "id": "company_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "company_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "domain",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "domain",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "signal_type",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "signal_type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "leadership_roles",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "leadership_roles",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "job_count",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "job_count",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 508314282,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oKKM8_x41e70cvW4FlZqdd8qWoPcW2gFfx0BofIjR2I/edit#gid=508314282",
          "cachedResultName": "Store Lead Signals"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1oKKM8_x41e70cvW4FlZqdd8qWoPcW2gFfx0BofIjR2I",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oKKM8_x41e70cvW4FlZqdd8qWoPcW2gFfx0BofIjR2I/edit?usp=drivesdk",
          "cachedResultName": "03"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "d2863e02-1a5d-4252-9292-de4fc2bd6606",
      "name": "Build AI Prompt",
      "type": "n8n-nodes-base.code",
      "position": [
        3008,
        912
      ],
      "parameters": {
        "jsCode": "// Build a personalized AI prompt with company + role context\nconst items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n  const companyData = item.json.data?.attributes || item.json.data || {};\n  const domain = item.json.domain || $('Filter Leadership Roles').first().json.domain || '';\n  const companyName = companyData.name || $('Filter Leadership Roles').first().json.company_name || domain;\n  const industry = companyData.industry || 'technology';\n  const employeeCount = companyData.employee_count || 'unknown';\n  const description = companyData.description || '';\n  const location = companyData.location || 'unknown location';\n  \n  const leadershipRoles = $('Filter Leadership Roles').first().json.leadership_roles || [];\n  const rolesList = leadershipRoles.map(r => r.title).join(', ');\n\n  // dynamic signal context\n  let signalContext = \"\";\n\n  if (leadershipRoles.length > 0) {\n    signalContext = `They are hiring for leadership roles: ${rolesList}`;\n  } else if ($('Retrieve Company Job Openings').first().json.data.length >= 10) {\n    signalContext = `They are rapidly scaling with multiple open roles (${$('Retrieve Company Job Openings').first().json.data.length} openings).`;\n  } else {\n    signalContext = `They are actively hiring across different teams.`;\n  }\n  \n  const prompt = `You are a B2B sales development representative writing a personalized cold outreach email.\n\nContext about the target company:\n- Company: ${companyName}\n- Domain: ${domain}\n- Industry: ${industry}\n- Employee count: ${employeeCount}\n- Location: ${location}\n- Description: ${description}\n\n${signalContext}\n\nWrite a concise, personalized outreach email (max 150 words) that:\n1. References the hiring signal\n2. Connects how our solution could help\n3. Offers a brief call to discuss\n4. Has a compelling subject line\n\nFormat your response as:\nSubject: [subject line]\n\n[email body]\n\nKeep the tone professional but conversational. Do not use generic filler phrases.`;\n  \n  results.push({\n    json: {\n      domain: domain,\n      company_name: companyName,\n      leadership_roles: leadershipRoles,\n      roles_list: rolesList,\n      ai_prompt: prompt,\n      recipient_email: `outreach@${domain}`\n    }\n  });\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "bc5cc076-0e86-480b-8e35-a3be8611c3ef",
      "name": "Generate Outreach Email",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3200,
        912
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"gpt-4o-mini\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are a professional B2B sales email writer. Write concise, personalized outreach emails.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": {{ JSON.stringify($json.ai_prompt) }}\n    }\n  ],\n  \"temperature\": 0.7,\n  \"max_tokens\": 500\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{ $env.OPENAI_API_KEY ? 'Bearer ' + $env.OPENAI_API_KEY : '' }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "edbb6feb-821f-441c-a159-c898dc349b27",
      "name": "Send Outreach Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        3536,
        912
      ],
      "parameters": {
        "sendTo": "={{ $json.recipient_email || $('Build AI Prompt').first().json.recipient_email }}",
        "message": "={{ $json.choices[0].message.content.replace(/Subject: .+\\n\\n/, '') }}",
        "options": {},
        "subject": "={{ $json.choices[0].message.content.match(/Subject: (.+)/)?.[1] || 'Leadership Transition - Let\\'s Connect' }}"
      },
      "typeVersion": 2.1
    }
  ],
  "connections": {
    "Daily Schedule": {
      "main": [
        [
          {
            "node": "Load Target Accounts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build AI Prompt": {
      "main": [
        [
          {
            "node": "Generate Outreach Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve Company": {
      "main": [
        [
          {
            "node": "Build AI Prompt",
            "type": "main",
            "index": 0
          },
          {
            "node": "Store Lead Signals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Into Batches": {
      "main": [
        [],
        [
          {
            "node": "Retrieve Company Job Openings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Job Count": {
      "main": [
        [
          {
            "node": "High Hiring Volume?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "High Hiring Volume?": {
      "main": [
        [
          {
            "node": "Send Hiring Spike Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Outreach Email": {
      "main": [
        [
          {
            "node": "Split Into Batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load Target Accounts": {
      "main": [
        [
          {
            "node": "Split Into Batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Leadership Role Found?": {
      "main": [
        [
          {
            "node": "Retrieve Company",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Split Into Batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sales Hiring Detected?": {
      "main": [
        [
          {
            "node": "Send Sales Hiring Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Leadership Roles": {
      "main": [
        [
          {
            "node": "Leadership Role Found?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Outreach Email": {
      "main": [
        [
          {
            "node": "Send Outreach Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Detect Sales Hiring Signals": {
      "main": [
        [
          {
            "node": "Sales Hiring Detected?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve Company Job Openings": {
      "main": [
        [
          {
            "node": "Filter Leadership Roles",
            "type": "main",
            "index": 0
          },
          {
            "node": "Calculate Job Count",
            "type": "main",
            "index": 0
          },
          {
            "node": "Detect Sales Hiring Signals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}