{
  "nodes": [
    {
      "id": "bf8e54e6-3ea5-41d1-8870-deb3493e4b26",
      "name": "Form Trigger",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -3040,
        16
      ],
      "parameters": {
        "path": "auto-connect-commenters",
        "options": {},
        "formTitle": "\ud83d\udd17 LinkedIn Post Engagement Automation",
        "formFields": {
          "values": [
            {
              "fieldLabel": "LinkedIn Post URL",
              "requiredField": true
            }
          ]
        },
        "formDescription": "Enter your LinkedIn post URL below to automatically send personalized connection requests to commenters"
      },
      "typeVersion": 2
    },
    {
      "id": "7203c1f6-bc1a-4966-8334-d3daf6decce9",
      "name": "Split Commenters",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -2480,
        16
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "comments"
      },
      "typeVersion": 1
    },
    {
      "id": "c3ccc9da-3af2-420a-a6f2-93ff979a3c0b",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -2256,
        16
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "020ec569-c6f8-4fdd-9f72-aef8deba38d3",
      "name": "Should Send?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1664,
        -80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "condition1",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.connected }}",
              "rightValue": false
            },
            {
              "id": "condition2",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.invitationSent }}",
              "rightValue": false
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "b115ff85-bd9b-4669-803d-dbd17dc82acd",
      "name": "Generate Message",
      "type": "n8n-nodes-base.code",
      "position": [
        -1328,
        -96
      ],
      "parameters": {
        "jsCode": "// Spin text template - customize with your name and style\nconst spinTextTemplate = `{Thanks for|Really appreciate|Awesome to see|Loved seeing|Grateful for} {your|you taking a moment to|you recently} {comment on|engaging with|reaction to|thoughts on|feedback on} {my|our|the} {post|recent post|latest update|content|recent article}.\n\n{Would love to|Happy to|Let's definitely|Open to|Excited to} connect {and|so we can|to} {exchange ideas|share insights|continue the conversation|explore synergies|stay in touch}. {Always enjoy connecting with|Always excited to meet|Love meeting|Great connecting with} {like-minded professionals|people in the space|others exploring similar topics|fellow thought leaders}.\n\n{Cheers|Best regards|Thanks again|Looking forward|Talk soon},\nAmaan sarfaraz`;\n\n// Parse spin text to generate unique variations\nfunction parseSpinText(text) {\n  return text.replace(/\\{([^}]+)\\}/g, (match, options) => {\n    const choices = options.split('|');\n    return choices[Math.floor(Math.random() * choices.length)];\n  });\n}\n\nconst generatedMessage = parseSpinText(spinTextTemplate);\nconst commenterData = $('Loop Over Items').item.json;\nconst commenterName = commenterData.author?.firstName || 'there';\nconst finalMessage = `Hi ${commenterName},\\n\\n${generatedMessage}`;\n\n// Keep under LinkedIn's 300 character limit\nconst trimmedMessage = finalMessage.length > 300 \n  ? finalMessage.substring(0, 297) + '...'\n  : finalMessage;\n\nreturn {\n  generatedMessage: trimmedMessage,\n  commenterName: commenterName,\n  commenterProfileId: commenterData.author?.publicIdentifier,\n  commentText: commenterData.commentText\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "4d1d6b90-c134-4ebc-a147-a65bce3ba57f",
      "name": "Wait 1-2 Hours",
      "type": "n8n-nodes-base.wait",
      "position": [
        -800,
        -96
      ],
      "parameters": {
        "unit": "hours",
        "amount": 1
      },
      "typeVersion": 1.1
    },
    {
      "id": "ecacadcc-730e-470d-b740-a9e3ce04692d",
      "name": "Log Success",
      "type": "n8n-nodes-base.code",
      "position": [
        -544,
        -96
      ],
      "parameters": {
        "jsCode": "const commenterData = $('Loop Over Items').item.json;\nconst message = $('Generate Message').first().json;\n\nreturn {\n  success: true,\n  commenterName: message.commenterName,\n  commenterProfileId: message.commenterProfileId,\n  messageSent: message.generatedMessage,\n  timestamp: new Date().toISOString(),\n  commentText: message.commentText\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "c01eaab7-af5f-4ea5-bf20-116370465b40",
      "name": "Log Skipped",
      "type": "n8n-nodes-base.code",
      "position": [
        -656,
        400
      ],
      "parameters": {
        "jsCode": "const relationshipData = $('Check Relationship').first().json;\nconst commenterData = $('Loop Over Items').item.json;\n\nreturn {\n  skipped: true,\n  reason: relationshipData.isConnected ? 'Already connected' : 'Pending invitation',\n  commenterName: commenterData.author?.firstName || 'Unknown',\n  commenterProfileId: commenterData.author?.publicIdentifier,\n  isConnected: relationshipData.isConnected,\n  invitationSent: relationshipData.invitationSent,\n  timestamp: new Date().toISOString()\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "ac686743-19b1-4bf9-a64a-4ad237adcf4d",
      "name": "Merge Results",
      "type": "n8n-nodes-base.merge",
      "position": [
        -224,
        16
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "mergeByFields": {
          "values": [
            {}
          ]
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "b79bff65-d269-40b8-bcaf-93308e0179ee",
      "name": "Generate Summary",
      "type": "n8n-nodes-base.code",
      "position": [
        0,
        16
      ],
      "parameters": {
        "jsCode": "const allItems = $input.all();\nconst successfulRequests = allItems.filter(item => item.json.success === true);\nconst skippedRequests = allItems.filter(item => item.json.skipped === true);\n\nconst summary = {\n  totalCommenters: allItems.length,\n  connectionRequestsSent: successfulRequests.length,\n  skippedConnections: skippedRequests.length,\n  skippedReasons: {\n    alreadyConnected: skippedRequests.filter(item => item.json.reason === 'Already connected').length,\n    pendingInvitation: skippedRequests.filter(item => item.json.reason === 'Pending invitation').length\n  },\n  processedAt: new Date().toISOString(),\n  successRate: allItems.length > 0 \n    ? ((successfulRequests.length / allItems.length) * 100).toFixed(2) + '%'\n    : '0%'\n};\n\nreturn {\n  summary,\n  successfulRequests: successfulRequests.map(item => ({\n    name: item.json.commenterName,\n    profileId: item.json.commenterProfileId,\n    messageSent: item.json.messageSent\n  })),\n  skippedRequests: skippedRequests.map(item => ({\n    name: item.json.commenterName,\n    profileId: item.json.commenterProfileId,\n    reason: item.json.reason\n  }))\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "d2edcbd9-0524-40ad-bf09-34f79abda698",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3744,
        -720
      ],
      "parameters": {
        "width": 584,
        "height": 753,
        "content": "## Auto-Connect with LinkedIn Post Commenters\n\n**What it does:**\nAutomatically sends personalized connection requests to people who comment on your LinkedIn posts. Turns post engagement into meaningful professional connections.\n\n**How it works:**\n1. Paste your LinkedIn post URL into the form\n2. Fetches all commenters from that post\n3. Checks if you're already connected to each person\n4. Generates unique, personalized messages using spin text\n5. Sends connection requests with 1-2 hour delays for safety\n6. Provides a summary report of sent vs. skipped requests\n\n**Key features:**\n- Smart filtering: Never sends duplicates or spams existing connections\n- Personalized messages: Each request uses unique variations\n- Account safety: Built-in rate limiting protects your LinkedIn account\n- Detailed tracking: Know exactly who received requests and who was skipped\n\n**Setup required:**\n1. Install n8n-nodes-connectsafely-ai community node\n2. Add your ConnectSafely.AI API credentials\n3. Customize the message template with your name\n4. Adjust wait time based on your account age (new accounts: 2-3 hours, established: 1 hour)\n\n**Perfect for:** Content creators, founders, sales professionals, and anyone building their LinkedIn network through authentic engagement.\n\n**Important:** Start with small tests (5-10 commenters) and never exceed 30-40 requests per day."
      },
      "typeVersion": 1
    },
    {
      "id": "9aecd70a-a71f-4dee-9907-e00e5a6e1a53",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2928,
        -256
      ],
      "parameters": {
        "color": 5,
        "width": 272.5857281975757,
        "height": 172.6366186489118,
        "content": "## Data Collection\nCapture the post URL and fetch all commenters from that LinkedIn post."
      },
      "typeVersion": 1
    },
    {
      "id": "e16d1a46-9473-4631-b9c1-a7338089dbb7",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2384,
        -256
      ],
      "parameters": {
        "color": 5,
        "width": 272.85714285714283,
        "height": 176.66336134453746,
        "content": "## Process Loop\nHandle each commenter one by one. The loop continues until all commenters are processed, then moves to final reporting."
      },
      "typeVersion": 1
    },
    {
      "id": "3b6e08e0-6701-444f-a8da-1da9fc7e684f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2064,
        336
      ],
      "parameters": {
        "color": 5,
        "width": 468.4285714285714,
        "height": 174.54677419354834,
        "content": "## Smart Filtering\nCheck relationship status and skip anyone you're already connected with or have a pending invitation to."
      },
      "typeVersion": 1
    },
    {
      "id": "1dfb56f0-f40b-4af9-9cbf-e8be46b1f580",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1232,
        -352
      ],
      "parameters": {
        "color": 5,
        "width": 396,
        "height": 165,
        "content": "## Send Requests\nGenerate personalized messages and send connection requests with rate limiting to protect your account."
      },
      "typeVersion": 1
    },
    {
      "id": "1ff07abd-8ac3-4a90-94fc-4d0f810591f6",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1776,
        -304
      ],
      "parameters": {
        "color": 5,
        "width": 273.109243697479,
        "height": 158.9915966386554,
        "content": "## Tracking\nLog skipped connections (already connected or pending) to avoid duplicate requests."
      },
      "typeVersion": 1
    },
    {
      "id": "153e6d43-f278-41f8-94a4-44094d4f215d",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -672,
        -352
      ],
      "parameters": {
        "color": 5,
        "width": 456.42857142857144,
        "height": 172.6366186489118,
        "content": "## Final Report\nCombine all results and generate a summary showing total commenters, requests sent, and skip reasons."
      },
      "typeVersion": 1
    },
    {
      "id": "80330cc3-ccad-4dc8-9867-8aaadd1a0753",
      "name": "ConnectSafely LinkedIn",
      "type": "n8n-nodes-connectsafely-ai.connectSafelyLinkedIn",
      "position": [
        -2784,
        16
      ],
      "parameters": {
        "postUrl": "={{ $json['LinkedIn Post URL'] }}",
        "accountId": "68ecc8f6ae3fb53989597a55",
        "operation": "getAllPostComments"
      },
      "credentials": {
        "connectSafelyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1692038c-026e-455b-902b-100dbaadff04",
      "name": "ConnectSafely LinkedIn1",
      "type": "n8n-nodes-connectsafely-ai.connectSafelyLinkedIn",
      "position": [
        -1936,
        160
      ],
      "parameters": {
        "accountId": "68ecc8f6ae3fb53989597a55",
        "operation": "checkRelationship",
        "profileId": "={{ $json.publicIdentifier }}"
      },
      "credentials": {
        "connectSafelyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c9619764-7402-4dba-88ce-b2bbbe0dca9c",
      "name": "ConnectSafely LinkedIn2",
      "type": "n8n-nodes-connectsafely-ai.connectSafelyLinkedIn",
      "position": [
        -1072,
        -96
      ],
      "parameters": {
        "accountId": "68ecc8f6ae3fb53989597a55",
        "operation": "sendConnectionRequest",
        "profileId": "={{ $('Should Send?').item.json.accountId }}",
        "profileUrn": "={{ $('Should Send?').item.json.profileUrn }}",
        "customMessage": "={{ $json.generatedMessage }}"
      },
      "credentials": {
        "connectSafelyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "386331a1-5e1e-4d7e-84b8-3d2a65f34d0b",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3072,
        -16
      ],
      "parameters": {
        "color": 7,
        "width": 720,
        "height": 208,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "6a0c1977-077a-4f50-89f3-9fba9997f7b2",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1696,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 784,
        "height": 192,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "44173815-1c82-4a5a-9174-94efbc25e5e7",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2288,
        -16
      ],
      "parameters": {
        "color": 7,
        "width": 576,
        "height": 320,
        "content": ""
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Log Skipped": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Results",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Log Success": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Form Trigger": {
      "main": [
        [
          {
            "node": "ConnectSafely LinkedIn",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Should Send?": {
      "main": [
        [
          {
            "node": "Generate Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Skipped",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Results": {
      "main": [
        [
          {
            "node": "Generate Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 1-2 Hours": {
      "main": [
        [
          {
            "node": "Log Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Should Send?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "ConnectSafely LinkedIn1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Message": {
      "main": [
        [
          {
            "node": "ConnectSafely LinkedIn2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Commenters": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ConnectSafely LinkedIn": {
      "main": [
        [
          {
            "node": "Split Commenters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ConnectSafely LinkedIn1": {
      "main": [
        [
          {
            "node": "Should Send?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ConnectSafely LinkedIn2": {
      "main": [
        [
          {
            "node": "Wait 1-2 Hours",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}