{
  "id": "JXSYQeOkAk6s4Mqw",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Explorium Champion Migration & Outreach",
  "tags": [],
  "nodes": [
    {
      "id": "b3101560-3d2b-433e-9d87-86e8a7e1798c",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        0,
        -32
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "b45060df-4c79-4a8e-9f86-07ed713d97c3",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        224,
        64
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "true",
              "lookupColumn": "isChampion"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19_REVVBikiGQaSX0-VYe_9hronkWNBflEXAhac5yDGI/edit#gid=0",
          "cachedResultName": "Champions_CRM"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "19_REVVBikiGQaSX0-VYe_9hronkWNBflEXAhac5yDGI",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19_REVVBikiGQaSX0-VYe_9hronkWNBflEXAhac5yDGI/edit?usp=drivesdk",
          "cachedResultName": "Champion Migration Tracker"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "7bb9b710-51d1-4ce0-8d5c-eb7b7a9e47a9",
      "name": "Check if Champion Has Explorium Prospect ID",
      "type": "n8n-nodes-base.if",
      "position": [
        448,
        64
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a0463715-cb44-4aa6-9f7a-adca054bfbf7",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.explorium_prospect_id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "c448136a-4762-4619-a4aa-9eddb60114f0",
      "name": "Explorium API",
      "type": "@exploriumai/n8n-nodes-explorium-ai.exploriumApiNode",
      "position": [
        704,
        160
      ],
      "parameters": {
        "type": "prospects",
        "operation": "match",
        "prospects_to_match": {
          "prospects_to_match": [
            {
              "email": "={{ $json.email }}",
              "linkedin": "={{ $json.linkedin_url }}",
              "full_name": "={{ $json.name }}",
              "company_name": "={{ $json.company }}"
            }
          ]
        }
      },
      "credentials": {
        "exploriumApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0286321b-7d98-4432-ac53-fddf4fd6ddc7",
      "name": "Write Back Explorium Prospect ID to CRM",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        896,
        144
      ],
      "parameters": {
        "columns": {
          "value": {
            "explorium_prospect_id": "={{ $json.matched_prospects[0].prospect_id }}"
          },
          "schema": [
            {
              "id": "champion_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "champion_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "last_checked_date ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "last_checked_date ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "relationship_strength",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "relationship_strength",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "last_contact_date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "last_contact_date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "deals_influenced",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "deals_influenced",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "relationship_notes ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "relationship_notes ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "isChampion",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "isChampion",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "linkedin_url",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "linkedin_url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "explorium_prospect_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "explorium_prospect_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "response_context",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "response_context",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "total_results",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "total_results",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "total_matches",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "total_matches",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "matched_prospects",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "matched_prospects",
              "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": "autoMapInputData",
          "matchingColumns": [
            "champion_id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19_REVVBikiGQaSX0-VYe_9hronkWNBflEXAhac5yDGI/edit#gid=0",
          "cachedResultName": "Champions_CRM"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "19_REVVBikiGQaSX0-VYe_9hronkWNBflEXAhac5yDGI",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19_REVVBikiGQaSX0-VYe_9hronkWNBflEXAhac5yDGI/edit?usp=drivesdk",
          "cachedResultName": "Champion Migration Tracker"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "86e2f16a-64bc-4417-b832-b9bcbd96c85f",
      "name": "Enrich Champions With Job Change History",
      "type": "@exploriumai/n8n-nodes-explorium-ai.exploriumApiNode",
      "position": [
        1344,
        64
      ],
      "parameters": {
        "type": "prospects",
        "operation": "enrich",
        "enrichment": [
          "contacts",
          "profiles"
        ],
        "prospect_ids": {
          "prospect_ids": [
            {
              "id": "={{ $json.explorium_prospect_id }}"
            }
          ]
        }
      },
      "credentials": {
        "exploriumApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b273a977-d51b-47c8-9eed-0c18324bdb1f",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        1568,
        64
      ],
      "parameters": {
        "jsCode": "// Process each item from the merge\nconst results = [];\n\nfor (const item of $input.all()) {\n  // Get the original CRM data (passed through from earlier nodes)\n  const crmData = item.json;\n  \n  // Extract Explorium data (it's nested in enriched_data array)\n  const exploriumArray = item.json.enriched_data || [];\n  \n  if (exploriumArray.length === 0) {\n    // No Explorium data returned, skip this champion\n    continue;\n  }\n  \n  const exploriumData = exploriumArray[0].data;\n  \n  // Get current company from both sources\n  const crmCompany = (crmData.company || '').toLowerCase().trim();\n  const exploriumCompany = (exploriumData.company_name || '').toLowerCase().trim();\n  \n  // Detect if job changed\n  const jobChanged = crmCompany !== exploriumCompany && exploriumCompany !== '';\n  \n  // Find the primary/current job from experience array\n  const currentJob = exploriumData.experience?.find(exp => exp.is_primary === true) || exploriumData.experience?.[0];\n  \n  results.push({\n    // Original CRM data\n    champion_id: crmData.champion_id,\n    name: crmData.name,\n    email: crmData.email,\n    old_company: crmData.company,\n    old_title: crmData.title,\n    relationship_strength: crmData.relationship_strength,\n    last_contact_date: crmData.last_contact_date,\n    deals_influenced: crmData.deals_influenced,\n    relationship_notes: crmData.relationship_notes,\n    linkedin_url: crmData.linkedin_url,\n    \n    // Explorium current employment data\n    new_company: exploriumData.company_name,\n    new_title: exploriumData.job_title,\n    new_company_website: exploriumData.company_website,\n    new_company_linkedin: exploriumData.company_linkedin,\n    job_department: exploriumData.job_department,\n    job_seniority: exploriumData.job_seniority_level,\n    \n    // Additional Explorium data\n    current_professional_email: exploriumData.professions_email,\n    mobile_phone: exploriumData.mobile_phone,\n    location: `${exploriumData.city}, ${exploriumData.region_name}`,\n    \n    // Job history context (useful for email personalization)\n    experience_summary: currentJob?.summary || '',\n    start_date: currentJob?.start_date || '',\n    \n    // Store prospect_id for future use\n    explorium_prospect_id: exploriumArray[0].prospect_id,\n    \n    // Flag if changed\n    job_changed: jobChanged,\n    \n    // Store full Explorium data for logging (as string)\n    explorium_full_data: JSON.stringify(exploriumData)\n  });\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "62b55847-b07b-44af-bb8b-4fa4f040e568",
      "name": "Code1",
      "type": "n8n-nodes-base.code",
      "position": [
        1120,
        64
      ],
      "parameters": {
        "jsCode": "const allItems = [];\n\n// Get ALL champions from the original sheet read\nconst allChampions = $('Get row(s) in sheet').all();\n\n// Get the prospect IDs that were just created (FALSE branch)\nconst newProspectIds = new Map();\ntry {\n  const matchResults = $('Explorium API').all();\n  for (const item of matchResults) {\n    const data = item.json;\n    if (data.matched_prospects && data.matched_prospects.length > 0) {\n      const match = data.matched_prospects[0];\n      const prospectId = match.prospect_id;\n      const inputEmail = match.input?.email;\n      if (inputEmail && prospectId) {\n        newProspectIds.set(inputEmail, prospectId);\n      }\n    }\n  }\n} catch (e) {\n  console.log('Error getting new prospect IDs:', e);\n}\n\n// Process all champions and add prospect IDs where needed\nfor (const champion of allChampions) {\n  const champData = champion.json;\n  \n  // If they didn't have a prospect_id, check if we just got one\n  if (!champData.explorium_prospect_id && newProspectIds.has(champData.email)) {\n    champData.explorium_prospect_id = newProspectIds.get(champData.email);\n  }\n  \n  allItems.push(champData);\n}\n\nreturn allItems.map(item => ({ json: item }));"
      },
      "typeVersion": 2
    },
    {
      "id": "59dccc71-d029-45dd-8045-8731f48313b7",
      "name": "Did Job Change?",
      "type": "n8n-nodes-base.if",
      "position": [
        1792,
        64
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e09fd978-9bf5-4471-a4ef-9dc5108de83f",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.job_changed }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "67ebefe8-3e60-495f-a840-73897b936d64",
      "name": "Pull Company Records to Check if New Company in CRM",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1792,
        -160
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 84963940,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19_REVVBikiGQaSX0-VYe_9hronkWNBflEXAhac5yDGI/edit#gid=84963940",
          "cachedResultName": "Companies"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "19_REVVBikiGQaSX0-VYe_9hronkWNBflEXAhac5yDGI",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/19_REVVBikiGQaSX0-VYe_9hronkWNBflEXAhac5yDGI/edit?usp=drivesdk",
          "cachedResultName": "Champion Migration Tracker"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "0a54e151-0c93-4233-b9cd-353fcbe730a1",
      "name": "Check if Customer or Prospect",
      "type": "n8n-nodes-base.switch",
      "position": [
        2688,
        -32
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "293b4ef9-b459-4053-b7e4-266e8e21612e",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Check if Exist in CRM').item.json.relationship_type }}",
                    "rightValue": "Customer"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "acf89279-bb7e-47a6-9f12-57055b532412",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Check if Exist in CRM').item.json.relationship_type }}",
                    "rightValue": "Prospect"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "1b5e9449-0bb2-4199-84a3-521e35858199",
      "name": "Match to explorium for Business ID",
      "type": "@exploriumai/n8n-nodes-explorium-ai.exploriumApiNode",
      "position": [
        2240,
        -32
      ],
      "parameters": {
        "operation": "match",
        "businesses_to_match": {
          "businesses_to_match": [
            {
              "name": "={{ $json.new_company }}"
            }
          ]
        }
      },
      "credentials": {
        "exploriumApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "95daeb34-9068-429e-b840-c159d6d3d733",
      "name": "Enrich with Explorium Business Data",
      "type": "@exploriumai/n8n-nodes-explorium-ai.exploriumApiNode",
      "position": [
        2464,
        -32
      ],
      "parameters": {
        "operation": "enrich",
        "enrichment": [
          "firmographics",
          "technographics",
          "financial_metrics",
          "funding_and_acquisitions"
        ],
        "business_ids": {
          "business_ids": [
            {
              "id": "={{ $json.matched_businesses[0].business_id }}"
            }
          ]
        }
      },
      "credentials": {
        "exploriumApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "591c307f-3a67-4aff-b0c6-05da5d9328ff",
      "name": "Check if Exist in CRM",
      "type": "n8n-nodes-base.code",
      "position": [
        2016,
        -32
      ],
      "parameters": {
        "jsCode": "// Get champions explicitly from the IF node\nconst champions = $('Did Job Change?').all();\n\n// Get CRM companies explicitly from Google Sheets\nconst crmCompanies = $('Pull Company Records to Check if New Company in CRM').all();\n\nconsole.log('Champions:', champions.length);\nconsole.log('CRM Companies:', crmCompanies.length);\n\nconst results = [];\n\nfor (const champ of champions) {\n  const champData = champ.json;\n  const newCompanyLower = (champData.new_company || '').toLowerCase().trim();\n  \n  console.log('Matching champion company:', champData.new_company);\n  \n  // Find match by company name only\n  let match = null;\n  \n  for (const crmComp of crmCompanies) {\n    const crmCompData = crmComp.json;\n    const crmCompanyLower = (crmCompData.companyName || '').toLowerCase().trim();\n    \n    console.log('  vs CRM:', crmCompData.companyName);\n    \n    // Match if names contain each other\n    if (newCompanyLower.includes(crmCompanyLower) || crmCompanyLower.includes(newCompanyLower)) {\n      match = crmCompData;\n      console.log('  \u2713 MATCH!');\n      break;\n    }\n  }\n  \n  results.push({\n    ...champData,\n    matched_to_crm: !!match,\n    relationship_type: match?.relationship_type || 'New',\n    crm_company_id: match?.company_ID || null,\n    open_opportunity: match?.open_opportunity || false,\n    opportunity_stage: match?.opportunity_stage || null,\n    account_owner: match?.accountOwner || null,\n    account_owner_email: match?.account_owner_email || null\n  });\n}\n\nconsole.log('Final results:', results.length);\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "91302250-624d-46b2-ae5b-8267161a07a7",
      "name": "Write Email for Customer to Congratulate Champion on New Role",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3360,
        -224
      ],
      "parameters": {
        "url": "https://api.anthropic.com/v1/messages",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"claude-sonnet-4-20250514\",\n  \"max_tokens\": 1000,\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Write a warm, professional congratulations email to {{ $json.name }} on their new role as {{ $json.new_title }} at {{ $json.new_company }}. Mention that we worked together when they were at {{ $json.old_company }} where they influenced {{ $json.deals_influenced }} deals. The tone should be genuine and focus on staying connected. Keep it under 150 words. Return ONLY the email body, no subject line.\"\n    }\n  ]\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "YOUR_ANTHROPIC_API_KEY"
            },
            {
              "name": "anthropic-version",
              "value": "2023-06-01"
            },
            {
              "name": "content-type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "04c4dd3e-de96-44ed-95e7-68937d251069",
      "name": "Score Prospect",
      "type": "n8n-nodes-base.code",
      "position": [
        2912,
        64
      ],
      "parameters": {
        "jsCode": "const results = [];\n\nfor (const item of $input.all()) {\n  const data = item.json;\n  \n  // Extract company data from enrichment response\n  const companyData = data.enrichmentsResponse?.[0]?.response?.data?.[0]?.data || {};\n  \n  // Parse employee count (it's a range like \"201-500\")\n  const employeeRange = companyData.number_of_employees_range || '';\n  let employeeCount = 0;\n  if (employeeRange.includes('-')) {\n    const parts = employeeRange.split('-');\n    employeeCount = parseInt(parts[1]); // Use upper bound\n  }\n  \n  // Get key company data\n  const revenueRange = companyData.yearly_revenue_range || '';\n  const fundingTotal = companyData.known_funding_total_value || 0;\n  const industry = companyData.linkedin_industry_category || '';\n  const techStack = companyData.full_tech_stack || [];\n  const acquiredBy = companyData.acquired_by || null;\n  \n  // === CRM STATUS EXTRACTION ===\n  const accountStatus = data.relationship_type || 'New';\n  const dealStatus = data.open_opportunity ? 'Open' : 'None';\n  const accountOwner = data.account_owner || 'Unassigned';\n  const contractValue = data.contract_value || null;\n  \n  console.log('Processing:', data.name || data.new_company, 'Account Status:', accountStatus);\n  \n  // === ICP SCORING (0-100) ===\n  let icpScore = 0;\n  \n  // 1. Company Size (0-30 points)\n  if (employeeCount >= 200 && employeeCount <= 500) {\n    icpScore += 30;\n  } else if (employeeCount >= 100 && employeeCount < 200) {\n    icpScore += 25;\n  } else if (employeeCount > 500 && employeeCount <= 1000) {\n    icpScore += 20;\n  } else if (employeeCount > 1000) {\n    icpScore += 10;\n  } else {\n    icpScore += 5;\n  }\n  \n  // 2. Funding (0-25 points)\n  if (fundingTotal > 30000000) {\n    icpScore += 25;\n  } else if (fundingTotal > 15000000) {\n    icpScore += 20;\n  } else if (fundingTotal > 5000000) {\n    icpScore += 15;\n  } else {\n    icpScore += 5;\n  }\n  \n  // 3. Revenue (0-20 points)\n  if (revenueRange.includes('M')) {\n    if (revenueRange.includes('10M') || revenueRange.includes('25M') || revenueRange.includes('50M')) {\n      icpScore += 20;\n    } else {\n      icpScore += 10;\n    }\n  }\n  \n  // 4. Tech Stack Match (0-25 points)\n  const relevantTech = ['Salesforce', 'ChurnZero', 'Zendesk', 'Marketo', 'Slack', 'HubSpot', 'Gainsight'];\n  const techMatches = techStack.filter(tech => \n    relevantTech.some(rt => tech.toLowerCase().includes(rt.toLowerCase()))\n  ).length;\n  \n  if (techMatches >= 3) {\n    icpScore += 25;\n  } else if (techMatches >= 1) {\n    icpScore += 15;\n  } else {\n    icpScore += 5;\n  }\n  \n  icpScore = Math.min(icpScore, 100);\n  \n  // === RELATIONSHIP SCORING (0-100) ===\n  const relationshipStrength = data.relationship_strength || 'Cold';\n  const dealsInfluenced = data.deals_influenced || 0;\n  \n  let relationshipScore = 0;\n  \n  // Base relationship strength (0-40 points)\n  if (relationshipStrength === 'Hot') {\n    relationshipScore += 40;\n  } else if (relationshipStrength === 'Warm') {\n    relationshipScore += 25;\n  } else {\n    relationshipScore += 10;\n  }\n  \n  // Deals influenced (0-20 points)\n  relationshipScore += Math.min(dealsInfluenced * 5, 20);\n  \n  // CRM Status Boost (0-40 points)\n  let crmBoost = 0;\n  \n  // Check account status directly\n  if (accountStatus === 'Customer') {\n    crmBoost += 40; // Existing customer - highest priority\n    console.log('\u2713 Customer detected - adding 40 boost');\n  } else if (accountStatus === 'Prospect' && dealStatus === 'Open') {\n    crmBoost += 25; // Already in pipeline\n    console.log('\u2713 Prospect with open deal - adding 25 boost');\n  } else if (accountStatus === 'Prospect') {\n    crmBoost += 15; // Known prospect\n    console.log('\u2713 Prospect - adding 15 boost');\n  } else {\n    crmBoost += 10; // New prospect\n    console.log('\u2713 New prospect - adding 10 boost');\n  }\n  \n  console.log('Relationship Score Before Boost:', relationshipScore);\n  console.log('CRM Boost:', crmBoost);\n  \n  relationshipScore = Math.min(relationshipScore + crmBoost, 100);\n  \n  console.log('Final Relationship Score:', relationshipScore);\n  \n  // === TIMING SCORING (0-100) ===\n  const startDate = data.start_date || '';\n  let daysAtCompany = 0;\n  \n  if (startDate) {\n    const start = new Date(startDate);\n    const now = new Date();\n    daysAtCompany = Math.floor((now - start) / (1000 * 60 * 60 * 24));\n  }\n  \n  let timingScore = 0;\n  \n  if (daysAtCompany >= 90 && daysAtCompany <= 365) {\n    timingScore += 50;\n  } else if (daysAtCompany >= 30 && daysAtCompany < 90) {\n    timingScore += 30;\n  } else if (daysAtCompany > 365 && daysAtCompany <= 730) {\n    timingScore += 40;\n  } else {\n    timingScore += 15;\n  }\n  \n  if (fundingTotal > 20000000) {\n    timingScore += 30;\n  } else if (fundingTotal > 0) {\n    timingScore += 20;\n  }\n  \n  if (acquiredBy) {\n    timingScore += 20;\n  }\n  \n  timingScore = Math.min(timingScore, 100);\n  \n  // === COMBINED OPPORTUNITY SCORE ===\n  const opportunityScore = Math.round(\n    (icpScore * 0.4) +\n    (relationshipScore * 0.4) +\n    (timingScore * 0.2)\n  );\n  \n  let priority;\n  if (opportunityScore >= 75) {\n    priority = 'HOT';\n  } else if (opportunityScore >= 50) {\n    priority = 'WARM';\n  } else {\n    priority = 'COLD';\n  }\n  \n  // Outreach Strategy\n  let outreachStrategy;\n  if (accountStatus === 'Customer') {\n    outreachStrategy = 'Congratulations + New Champion at Account';\n  } else if (dealStatus === 'Open') {\n    outreachStrategy = 'Warm Handoff + Deal Acceleration';\n  } else if (accountStatus === 'Prospect') {\n    outreachStrategy = 'Re-engagement + Champion Credibility';\n  } else {\n    outreachStrategy = 'Cold Outreach + Champion Credibility';\n  }\n  \n  console.log('Final Scores - ICP:', icpScore, 'Relationship:', relationshipScore, 'Timing:', timingScore, 'Overall:', opportunityScore);\n  \n  // Push to results array\n  results.push({\n    json: {\n      ...data,\n      company_employee_count: employeeRange,\n      company_revenue: revenueRange,\n      company_funding_total: fundingTotal,\n      company_industry: industry,\n      company_tech_stack: techStack.slice(0, 10),\n      company_acquired_by: acquiredBy,\n      icp_score: icpScore,\n      relationship_score: relationshipScore,\n      timing_score: timingScore,\n      opportunity_score: opportunityScore,\n      priority: priority,\n      outreach_strategy: outreachStrategy,\n      scoring_breakdown: {\n        icp: icpScore,\n        relationship: relationshipScore,\n        timing: timingScore,\n        days_at_company: daysAtCompany,\n        crm_boost: crmBoost\n      }\n    }\n  });\n}\n\nconsole.log('Total items processed:', results.length);\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "f979f5c6-ba93-4bbb-9e19-450fd2a3b885",
      "name": "Warm/Hot Lead",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3360,
        -32
      ],
      "parameters": {
        "url": "https://api.anthropic.com/v1/messages",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"claude-sonnet-4-20250514\",\n  \"max_tokens\": 1000,\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Write strategic outreach to {{ $json.name }} who became {{ $json.new_title }} at {{ $json.new_company }}. Past: {{ $json.old_company }}, {{ $json.deals_influenced }} deals, {{ $json.relationship_strength }} relationship. Score: {{ $json.opportunity_score }}/7. Warm, reference success, suggest call. 150 words max. Email body only.\"\n    }\n  ]\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "YOUR_ANTHROPIC_API_KEY"
            },
            {
              "name": "anthropic-version",
              "value": "2023-06-01"
            },
            {
              "name": "content-type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "882c0c32-66b6-4c09-8ea3-194224b27423",
      "name": "Check if Lead is Hot/Warm/Cold",
      "type": "n8n-nodes-base.if",
      "position": [
        3136,
        64
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "162bd3ea-d5d5-4f37-bdc0-fa1f4461b4e2",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.priority }}",
              "rightValue": "WARM"
            },
            {
              "id": "70229a0c-f4b2-40bd-814d-8931690d78bb",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.priority }}",
              "rightValue": "HOT"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8d88654e-f856-4516-aa6b-2bd523d9fb09",
      "name": "Cold Lead Email",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3344,
        224
      ],
      "parameters": {
        "url": "https://api.anthropic.com/v1/messages",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"claude-sonnet-4-20250514\",\n  \"max_tokens\": 500,\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"={{ `Write a brief congratulations email to ${$json.name} on their new role as ${$json.new_title} at ${$json.new_company}. We worked together at ${$json.old_company}. Keep under 100 words. Return ONLY email body.` }}\"\n    }\n  ]\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "YOUR_ANTHROPIC_API_KEY"
            },
            {
              "name": "anthropic-version",
              "value": "2023-06-01"
            },
            {
              "name": "content-type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "65adc758-91c1-4e95-84fd-63e29ccb1805",
      "name": "Send a message",
      "type": "n8n-nodes-base.slack",
      "position": [
        3872,
        -32
      ],
      "parameters": {
        "text": "=",
        "user": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "select": "user",
        "blocksUi": "const results = [];\n\nfor (const item of $input.all()) {\n  const data = item.json;\n  \n  // Extract email from Claude response\n  const email = data.content?.[0]?.text || 'Email generated';\n  \n  // Determine action type\n  let actionType = 'Unknown';\n  if (data.relationship_type === 'Customer') {\n    actionType = '\ud83d\udc65 Customer - Congratulations Sent';\n  } else if (data.priority === 'Low') {\n    actionType = '\ud83d\udce7 Cold Outreach - Auto-Sent';\n  } else {\n    actionType = '\ud83d\udd25 Hot Lead - Draft Ready for Review';\n  }\n  \n  // Create fake Slack message\n  const slackMessage = `\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\ud83c\udfaf CHAMPION MIGRATION ALERT\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\nChampion: ${data.name}\nOld Company: ${data.old_company || 'N/A'}\nNew Company: ${data.new_company}\nNew Title: ${data.new_title}\n\nRelationship: ${data.relationship_type || 'New'}\nScore: ${data.opportunity_score || 'N/A'}/7\nPriority: ${data.priority || 'Customer'}\n\n${actionType}\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\ud83d\udce7 GENERATED EMAIL:\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n${email}\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n`;\n\n  results.push({\n    ...data,\n    slack_message: slackMessage,\n    action_type: actionType,\n    email_content: email\n  });\n}\n\nreturn results;",
        "messageType": "block",
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b80e719a-7bd2-45c7-b365-75884fc46446",
      "name": "Merge to Send to Slack",
      "type": "n8n-nodes-base.merge",
      "position": [
        3648,
        -32
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "cb15a6a6-cf0b-48f0-ae05-120c60cbfd8d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        -80
      ],
      "parameters": {
        "width": 336,
        "height": 592,
        "content": "# Try It Out!\n\nThis n8n workflow automatically tracks when your champion contacts change companies and responds with intelligent, personalized AI outreach\u2014preventing revenue leakage and prioritizing high-value opportunities.\n\n## Use Cases\n\nUse this workflow to re-engage champions at new prospect companies, track champions who move to existing customer accounts, or automate relationship building at scale without manual LinkedIn monitoring.\n\n## How it works\n\n* We'll monitor your champion list via CRM or Google Sheets (demo)\n* Explorium detects job changes by enriching person data with current employment\n* When a champion moves, Explorium enriches their new company with firmographics, funding, tech stack, and hiring signals\n* A multi-dimensional scoring engine (0-100) evaluates ICP fit, relationship strength, and timing\n* The workflow routes by priority: Customers get account manager notifications, Hot prospects get strategic drafts for review\n\n## How to use\n\n* The manual trigger node is used as an example but feel free to replace this with automated triggers such as webhook or a scheduled run\n* For production, replace Google Sheets nodes with your actual CRM (Salesforce, HubSpot, Pipedrive)\n* Customize the scoring criteria in the \"Score Company\" node to match your ICP\n* Adjust Claude AI prompts to match your brand voice and outreach strategy\n\n## Requirements\n\n* Explorium API key for person and company enrichment\n* Anthropic API key for Claude AI email generation\n* Google Sheets (demo) or your CRM connection (production)\n\n\n---\n\n# Geo Restrictions!\n\nPlease note: Explorium and Anthropic APIs may have geographic or usage restrictions. Ensure you have appropriate API access and credits before running this workflow at scale."
      },
      "typeVersion": 1
    },
    {
      "id": "4ea608c6-44d6-42e5-9aea-0a4d35cb5de2",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        144,
        240
      ],
      "parameters": {
        "content": "## Modification Recommendation\n\nConnect your CRM here & in all places where Google Sheets is leveraged."
      },
      "typeVersion": 1
    },
    {
      "id": "17afb6c8-083b-4b31-ac0b-95e158768778",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3312,
        384
      ],
      "parameters": {
        "content": "## Modification Recommendation\n\nConsider turning this node into an agent that sends the cold emails automatically!"
      },
      "typeVersion": 1
    },
    {
      "id": "4ea0eb18-dd27-4fb9-bbaf-24c21b4c962e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2832,
        208
      ],
      "parameters": {
        "content": "## Modification Recommendation\n\nWrite a scoring system that matches your business OR use a dynamic scoring system in Claude or similar tools"
      },
      "typeVersion": 1
    },
    {
      "id": "4377d033-20df-4bdd-b4c6-d4d0ac71b3e4",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3296,
        -416
      ],
      "parameters": {
        "content": "## Modification Recommendation\n\nModify the email template prompts to match your brand voice."
      },
      "typeVersion": 1
    },
    {
      "id": "bdbbba3b-052c-429c-ba11-ca8faf5b07d2",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3808,
        -304
      ],
      "parameters": {
        "height": 224,
        "content": "## Modification Recommendation\n\nConsider writing the draft for them directly in their inbox and notify them or another tool that can alert them to send and you can track that it was sent."
      },
      "typeVersion": 1
    },
    {
      "id": "c4cd6764-7466-4f91-afb9-4d202e63a7c3",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2160,
        160
      ],
      "parameters": {
        "content": "## Modification Recommendation\n\nConsider a branch here to only match when it doesn't exist in CRM to save API credits."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6f9be100-aa73-4dc0-8431-5ca64f2dc141",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Did Job Change?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code1": {
      "main": [
        [
          {
            "node": "Enrich Champions With Job Change History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Explorium API": {
      "main": [
        [
          {
            "node": "Write Back Explorium Prospect ID to CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Warm/Hot Lead": {
      "main": [
        [
          {
            "node": "Merge to Send to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score Prospect": {
      "main": [
        [
          {
            "node": "Check if Lead is Hot/Warm/Cold",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cold Lead Email": {
      "main": [
        [
          {
            "node": "Merge to Send to Slack",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Did Job Change?": {
      "main": [
        [
          {
            "node": "Check if Exist in CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "Check if Champion Has Explorium Prospect ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Exist in CRM": {
      "main": [
        [
          {
            "node": "Match to explorium for Business ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge to Send to Slack": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Customer or Prospect": {
      "main": [
        [
          {
            "node": "Write Email for Customer to Congratulate Champion on New Role",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Score Prospect",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Lead is Hot/Warm/Cold": {
      "main": [
        [
          {
            "node": "Warm/Hot Lead",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Cold Lead Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Match to explorium for Business ID": {
      "main": [
        [
          {
            "node": "Enrich with Explorium Business Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich with Explorium Business Data": {
      "main": [
        [
          {
            "node": "Check if Customer or Prospect",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          },
          {
            "node": "Pull Company Records to Check if New Company in CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Back Explorium Prospect ID to CRM": {
      "main": [
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich Champions With Job Change History": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Champion Has Explorium Prospect ID": {
      "main": [
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Explorium API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pull Company Records to Check if New Company in CRM": {
      "main": [
        [
          {
            "node": "Check if Exist in CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Email for Customer to Congratulate Champion on New Role": {
      "main": [
        [
          {
            "node": "Merge to Send to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}