{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI lead follow-up emails with reply detection",
  "tags": [],
  "nodes": [
    {
      "id": "f75cfa63-5819-4d29-97c1-595e92422c96",
      "name": "New Lead Form Submission",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -368,
        448
      ],
      "parameters": {
        "path": "lead-form",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "275a6593-5ca4-4ca4-b9e2-2ab01a641430",
      "name": "Configure Variables",
      "type": "n8n-nodes-base.set",
      "position": [
        -96,
        448
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "senderName",
              "type": "string",
              "value": "YOUR NAME"
            },
            {
              "id": "2",
              "name": "senderEmail",
              "type": "string",
              "value": "YOUR_SENDER_EMAIL"
            },
            {
              "id": "3",
              "name": "companyName",
              "type": "string",
              "value": "YOUR COMPANY NAME"
            },
            {
              "id": "4",
              "name": "replyDetectionEmail",
              "type": "string",
              "value": "YOUR_REPLY_EMAIL"
            },
            {
              "id": "5",
              "name": "waitTimeBetweenEmails",
              "type": "number",
              "value": 48
            },
            {
              "id": "6",
              "name": "leadName",
              "type": "string",
              "value": "={{ $json.body.name }}"
            },
            {
              "id": "7",
              "name": "leadEmail",
              "type": "string",
              "value": "={{ $json.body.email }}"
            },
            {
              "id": "8",
              "name": "leadCompany",
              "type": "string",
              "value": "={{ $json.body.company }}"
            },
            {
              "id": "9",
              "name": "leadInquiry",
              "type": "string",
              "value": "={{ $json.body.inquiry }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "3ba03f03-6b64-480c-9979-81c0d6e95012",
      "name": "Generate First Follow-Up Email",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        352,
        432
      ],
      "parameters": {
        "text": "=Write a personalized follow-up email for a new lead.\n\nLead Details:\n- Name: {{ $json.leadName }}\n- Email: {{ $json.leadEmail }}\n- Company: {{ $json.leadCompany }}\n- Inquiry: {{ $json.leadInquiry }}\n\nSender Details:\n- Name: {{ $json.senderName }}\n- Company: {{ $json.companyName }}\n\nWrite a warm, professional email that:\n1. Thanks them for their interest\n2. Addresses their specific inquiry\n3. Offers to schedule a call or provide more information\n4. Keeps it concise (3-4 paragraphs)\n\nReturn ONLY the email body text, no subject line.",
        "options": {
          "systemMessage": "You are a professional sales assistant who writes personalized, warm follow-up emails to leads. Write in a friendly but professional tone."
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "49c1a9fd-e393-4a3e-9629-a587dd60a5ca",
      "name": "OpenAI Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        320,
        592
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "d1295ec8-47ab-4e73-9dc3-4a23aa838ed7",
      "name": "Send First Follow-Up Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        688,
        432
      ],
      "parameters": {
        "sendTo": "={{ $(\"Configure Variables\").item.json.leadEmail }}",
        "message": "={{ $json.output }}",
        "options": {
          "senderName": "={{ $(\"Configure Variables\").item.json.senderName }}"
        },
        "subject": "=Re: Your inquiry about {{ $(\"Configure Variables\").item.json.companyName }}",
        "emailType": "text"
      },
      "typeVersion": 2.2
    },
    {
      "id": "6927e43e-483c-43bf-9df4-ab9365763ab9",
      "name": "Wait 48 Hours",
      "type": "n8n-nodes-base.wait",
      "position": [
        1024,
        480
      ],
      "parameters": {
        "unit": "hours",
        "amount": "={{ $(\"Configure Variables\").item.json.waitTimeBetweenEmails }}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "16e907ed-6bf5-4062-8cea-f808c375056d",
      "name": "Notify Team of Reply",
      "type": "n8n-nodes-base.slack",
      "position": [
        2112,
        256
      ],
      "parameters": {
        "text": "=🎉 Lead responded!\n\n*Lead:* {{ $(\"Configure Variables\").item.json.leadName }} ({{ $(\"Configure Variables\").item.json.leadCompany }})\n*Email:* {{ $(\"Configure Variables\").item.json.leadEmail }}\n*Reply:* {{ $json.text }}\n\nCheck your inbox to continue the conversation!",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_SLACK_CHANNEL_ID"
        },
        "otherOptions": {}
      },
      "typeVersion": 2.4
    },
    {
      "id": "8e0240f3-d4d9-4b67-b2e7-26bbd3d4341e",
      "name": "Log Reply Status to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2368,
        256
      ],
      "parameters": {
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "YOUR_SHEET_TAB_NAME"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Lead Name": "={{ $(\"Configure Variables\").item.json.leadName }}",
            "Email": "={{ $(\"Configure Variables\").item.json.leadEmail }}",
            "Reply Status": "Replied",
            "Date": "={{ $now.toISO() }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Lead Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Lead Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Reply Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Reply Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "9ca4ff75-79df-40d2-a696-ddfb130c8fe7",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        736,
        -112
      ],
      "parameters": {
        "color": "#FFF995",
        "width": 768,
        "height": 256,
        "content": "## AI Lead Follow-Up Sequence with Reply Detection\n\n**Who it's for:** teams that answer inbound leads by email.\n\n**What it does:** a form posts to the webhook, an AI model writes a first email that Gmail sends, the workflow waits, Gmail searches for a message from the lead, and then either Slack and Google Sheets record the reply or a second AI-written email is sent.\n\n**Requirements:** Gmail, OpenAI, Slack and Google Sheets credentials. Replace the YOUR_ placeholders before activating."
      },
      "typeVersion": 1
    },
    {
      "id": "59f899cf-cb9a-420d-b788-58dae0b06571",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        304
      ],
      "parameters": {
        "color": "#606060",
        "width": 582,
        "height": 320,
        "content": "## 1. Trigger and Configuration\n\nThe webhook receives the form submission. Fill in Configure Variables before activating. Note: the sender email and reply email values are not used by any node."
      },
      "typeVersion": 1
    },
    {
      "id": "51dec2a6-254b-4ba1-8ea7-8a321694a2fb",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        304
      ],
      "parameters": {
        "color": "#606060",
        "width": 598,
        "height": 416,
        "content": "## 2. AI Email Generation and Send\n\nLead data is passed to OpenAI which writes a personalized first follow-up email based on the inquiry details. Gmail sends it from your connected account."
      },
      "typeVersion": 1
    },
    {
      "id": "cd2d981d-1755-46b4-9865-a810ce3c73df",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        933,
        320
      ],
      "parameters": {
        "color": "#606060",
        "width": 598,
        "height": 320,
        "content": "## 3. Wait and Reply Detection\n\nThe workflow pauses for the number of hours set in Configure Variables. A Gmail node then searches the inbox for messages from the lead received in the last 2 days. It is set to output an empty item when nothing is found, so that the no-reply branch can run."
      },
      "typeVersion": 1
    },
    {
      "id": "af4f39e1-7ee0-43e9-b054-76eeb7b963c5",
      "name": "Send Second Follow-Up Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2400,
        608
      ],
      "parameters": {
        "sendTo": "={{ $(\"Configure Variables\").item.json.leadEmail }}",
        "message": "={{ $json.output }}",
        "options": {
          "senderName": "={{ $(\"Configure Variables\").item.json.senderName }}"
        },
        "subject": "=Quick follow-up: {{ $(\"Configure Variables\").item.json.companyName }}",
        "emailType": "text"
      },
      "typeVersion": 2.2
    },
    {
      "id": "7e0f0778-34fd-4ffa-9c51-fb42994e56a7",
      "name": "Generate Second Follow-Up Email",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2048,
        608
      ],
      "parameters": {
        "text": "=Write a second follow-up email for a lead who has not responded to the first email.\n\nLead Details:\n- Name: {{ $(\"Configure Variables\").item.json.leadName }}\n- Company: {{ $(\"Configure Variables\").item.json.leadCompany }}\n- Original Inquiry: {{ $(\"Configure Variables\").item.json.leadInquiry }}\n\nSender Details:\n- Name: {{ $(\"Configure Variables\").item.json.senderName }}\n- Company: {{ $(\"Configure Variables\").item.json.companyName }}\n\nWrite a brief, friendly follow-up that:\n1. Takes a different angle (e.g., share a relevant case study, offer a resource, or mention a limited-time offer)\n2. Acknowledges they might be busy\n3. Provides clear value or next steps\n4. Keeps it short (2-3 paragraphs)\n\nReturn ONLY the email body text, no subject line.",
        "options": {
          "systemMessage": "You are a professional sales assistant who writes brief, value-focused follow-up emails. Take a different angle from the first email and keep it concise."
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "db9bbb98-66ca-4881-b1aa-45450ce97567",
      "name": "Did Lead Reply?",
      "type": "n8n-nodes-base.if",
      "position": [
        1696,
        448
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "d6c71fc6-8fbf-44c0-b385-d74d9c6f8dfd",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1584,
        320
      ],
      "parameters": {
        "color": "#606060",
        "width": 342,
        "height": 272,
        "content": "## 4. Route by Reply Status\n\nIf node checks whether the lead replied. True routes to the replied branch. False routes to the no reply branch."
      },
      "typeVersion": 1
    },
    {
      "id": "d98befd3-1033-4cd6-b88d-3c03339bf362",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2000,
        112
      ],
      "parameters": {
        "color": "#606060",
        "width": 582,
        "height": 320,
        "content": "## 5. Lead Replied\n\nSlack notifies your team. Google Sheets appends a row with lead name, email, reply status and date. Columns: Lead Name, Email, Reply Status, Date."
      },
      "typeVersion": 1
    },
    {
      "id": "014c08ab-6dd1-4ab9-964c-2b3890586ecf",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2000,
        480
      ],
      "parameters": {
        "color": "#606060",
        "width": 582,
        "height": 320,
        "content": "## 6. No Reply\n\nOpenAI writes a second follow-up email using a different angle than the first. Gmail sends it from your connected account."
      },
      "typeVersion": 1
    },
    {
      "id": "1a842e3f-5389-43b5-ba36-1b68bbef6948",
      "name": "Check for Lead Reply",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1280,
        480
      ],
      "parameters": {
        "limit": 10,
        "filters": {
          "sender": "={{ $(\"Configure Variables\").item.json.leadEmail }}",
          "receivedAfter": "={{ $now.minus(2, \"days\").toISO() }}"
        },
        "operation": "getAll"
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "connections": {
    "OpenAI Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate First Follow-Up Email",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Generate Second Follow-Up Email",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Wait 48 Hours": {
      "main": [
        [
          {
            "node": "Check for Lead Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Did Lead Reply?": {
      "main": [
        [
          {
            "node": "Notify Team of Reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Second Follow-Up Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure Variables": {
      "main": [
        [
          {
            "node": "Generate First Follow-Up Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for Lead Reply": {
      "main": [
        [
          {
            "node": "Did Lead Reply?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify Team of Reply": {
      "main": [
        [
          {
            "node": "Log Reply Status to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New Lead Form Submission": {
      "main": [
        [
          {
            "node": "Configure Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send First Follow-Up Email": {
      "main": [
        [
          {
            "node": "Wait 48 Hours",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate First Follow-Up Email": {
      "main": [
        [
          {
            "node": "Send First Follow-Up Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Second Follow-Up Email": {
      "main": [
        [
          {
            "node": "Send Second Follow-Up Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}