{
  "name": "LinkedIn Lead Deep Personalisation Engine",
  "nodes": [
    {
      "parameters": {
        "multipleMethods": true,
        "httpMethod": [
          "POST"
        ],
        "path": "3ee3792a-1f6b-47b2-82f4-9b0fefade5cf",
        "options": {
          "rawBody": true
        }
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -40,
        0
      ],
      "id": "ed4dca5c-a953-48ef-9e0b-cc654462466b",
      "name": "Webhook",
      "webhookId": "763b038e-491f-461e-bb22-d4b80e2605d2"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1760,
        0
      ],
      "id": "2574297b-793e-4e62-9a73-aec7c89caeba",
      "name": "Wait",
      "webhookId": "3b7d67fd-1157-423b-9806-fbb3935116b7",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        560,
        0
      ],
      "id": "8be2bf53-5481-4cf4-b4c0-98014972876f",
      "name": "Loop Over Items"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.leadmagic.io/profile-search",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "X-API-Key",
              "value": "YOUR_LEADMAGIC_API_KEY"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "profile_url",
              "value": "={{ $json.linkedin_url }}"
            }
          ]
        },
        "options": {
          "redirect": {
            "redirect": {}
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1040,
        0
      ],
      "id": "57d66ffb-f0d3-4768-8733-dab387b42fa3",
      "name": "Request LinkedIn Profile",
      "executeOnce": false
    },
    {
      "parameters": {
        "url": "=https://api.apify.com/v2/datasets/{{ $json.body.resource.defaultDatasetId }}/items",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "Bearer YOUR_APIFY_API_TOKEN"
            }
          ]
        },
        "options": {
          "redirect": {
            "redirect": {}
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        160,
        0
      ],
      "id": "35b13c58-b850-468a-b8bf-42c8303eb825",
      "name": "Get Dataset Items",
      "executeOnce": false
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "profileUrl": "={{ $('Request LinkedIn Profile').item.json.profileUrl }}",
            "firstName": "={{ $('Request LinkedIn Profile').item.json.firstName }}",
            "lastName": "={{ $('Request LinkedIn Profile').item.json.lastName }}",
            "fullName": "={{ $('Request LinkedIn Profile').item.json.fullName }}",
            "publicIdentifier": "={{ $('Request LinkedIn Profile').item.json.publicIdentifier }}",
            "headline": "={{ $('Request LinkedIn Profile').item.json.headline }}",
            "userSkills": "={{ $('Request LinkedIn Profile').item.json.userSkills }}",
            "company_name": "={{ $('Request LinkedIn Profile').item.json.company_name }}",
            "company_size": "={{ $('Request LinkedIn Profile').item.json.company_size }}",
            "company_industry": "={{ $('Request LinkedIn Profile').item.json.company_industry }}",
            "company_linkedin_url": "={{ $('Request LinkedIn Profile').item.json.company_linkedin_url }}",
            "company_website": "={{ $('Request LinkedIn Profile').item.json.company_website }}",
            "connections": "={{ $('Request LinkedIn Profile').item.json.connections }}",
            "followers": "={{ $('Request LinkedIn Profile').item.json.followers }}",
            "urn": "={{ $('Request LinkedIn Profile').item.json.urn }}",
            "country": "={{ $('Request LinkedIn Profile').item.json.country }}",
            "location": "={{ $('Request LinkedIn Profile').item.json.location }}",
            "profilePic": "={{ $('Request LinkedIn Profile').item.json.profilePic }}",
            "about": "={{ $('Request LinkedIn Profile').item.json.about }}",
            "subject": "={{ $json.message.content.subjectLine }}",
            "icebreaker": "={{ $json.message.content.icebreaker }}",
            "elevatorPitch": "={{ $json.message.content.elevatorPitch }}",
            "callToAction": "={{ $json.message.content.callToAction }}",
            "ps": "={{ $json.message.content.ps }}",
            "emailAddress": "={{ $('Loop Over Items').item.json.email}}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "profileUrl",
              "displayName": "profileUrl",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "firstName",
              "displayName": "firstName",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "lastName",
              "displayName": "lastName",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "fullName",
              "displayName": "fullName",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "publicIdentifier",
              "displayName": "publicIdentifier",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "headline",
              "displayName": "headline",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "userSkills",
              "displayName": "userSkills",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "company_name",
              "displayName": "company_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "company_size",
              "displayName": "company_size",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "company_industry",
              "displayName": "company_industry",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "company_linkedin_url",
              "displayName": "company_linkedin_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "company_website",
              "displayName": "company_website",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "connections",
              "displayName": "connections",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "followers",
              "displayName": "followers",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "urn",
              "displayName": "urn",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "country",
              "displayName": "country",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "location",
              "displayName": "location",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "profilePic",
              "displayName": "profilePic",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "about",
              "displayName": "about",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "subject",
              "displayName": "subject",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "icebreaker",
              "displayName": "icebreaker",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "elevatorPitch",
              "displayName": "elevatorPitch",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "callToAction",
              "displayName": "callToAction",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "ps",
              "displayName": "ps",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "emailAddress",
              "displayName": "emailAddress",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {
          "useAppend": true
        }
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1560,
        0
      ],
      "id": "36a407ac-accb-4d53-bacc-e09624e7af5c",
      "name": "Add Row",
      "executeOnce": false
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list",
          "cachedResultName": "GPT-4O"
        },
        "messages": {
          "values": [
            {
              "content": "You're a helpful, intelligent writing assistant.",
              "role": "system"
            },
            {
              "content": "Your task is to personalize an email.\n\nYou'll do this by taking, as input, a prospect LinkedIn profile, and then editing 5 templates for different sections of the email: subject line, icebreaker, elevator pitch, call to action, and a PS field.\n\nYour templates are below.\n\nSubject Line: \"hey {name}, think I have something for you re: {thingAboutThem}\"\nIcebreaker: \"I know you're doing {thing} and I've been following {relatedThing} for a while so I figured it made sense to chat\"\nElevator Pitch: \"The TLDR: I think I can add ~$5K/mo to {theirParaphrasedBusiness} with a few automated systems\"\nCall to Action: \"I just did this for a very similar {industry} company and we hit $28,350 in a few months—they do {relatedThing}—so am very confident I can duplicate this at minimum. Would be 100% risk-free, I'd guarantee at least 20 appts booked or you wouldn't pay.\"\nPS: \"even if we just chat I'd love to hear about what you're doing with {thing}\"\n\nGuidelines:\n1. Your tone of voice should be \"casual bar conversation\" and very spartan. No fancy language. \n2. Look for plausible (but vague) connections wherever possible.\n3. Do not just repeat data from the LinkedIn profile verbatim. Paraphrase, so they think a human wrote it.\n4. Make sure the subject line is non-capitalized, even if it's grammatically incorrect. This makes the email seem human.\n5. Respond in JSON using this format:\n\n{\"subjectLine\":\"\",\"icebreaker\":\"\",\"elevatorPitch\":\"\",\"callToAction\":\"\",\"ps\":\"\"}"
            },
            {
              "content": "={{ $json.toJsonString() }}"
            }
          ]
        },
        "jsonOutput": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.6,
      "position": [
        1220,
        0
      ],
      "id": "c5236a40-838c-41ad-a422-26021f4a4cc3",
      "name": "5 Column Personalization"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "22b5a816-26b6-42bf-8544-1afc7a78c95a",
              "leftValue": "={{ $('Loop Over Items').item.json.email }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        800,
        0
      ],
      "id": "69634b33-c14b-44bb-8339-8468ba1c8860",
      "name": "If"
    },
    {
      "parameters": {
        "maxItems": 3
      },
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        340,
        0
      ],
      "id": "c20f13ae-a2ac-4f6c-9302-868f108d3526",
      "name": "Limit"
    }
  ],
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Get Dataset Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Request LinkedIn Profile": {
      "main": [
        [
          {
            "node": "5 Column Personalization",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Dataset Items": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          },
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Row": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5 Column Personalization": {
      "main": [
        [
          {
            "node": "Add Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Request LinkedIn Profile",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Request LinkedIn Profile",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}
