{
  "id": "jZOj3g0o8NYvxmW3",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Speed To Lead + Reply Handling V1",
  "tags": [],
  "nodes": [
    {
      "id": "f9c9b74a-665e-44d2-8fb6-1074865d9cfe",
      "name": "Webhook - Lead Form Trigger",
      "type": "n8n-nodes-base.webhook",
      "position": [
        544,
        432
      ],
      "parameters": {
        "path": "real-estate-lead",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "8c00ee3c-6971-4c9e-9047-79297ccd0399",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        768,
        336
      ],
      "parameters": {
        "options": {},
        "respondWith": "text",
        "responseBody": "Thank you! We have received your enquiry and will be in touch shortly."
      },
      "typeVersion": 1
    },
    {
      "id": "16351954-409e-4b7d-a1df-4e5adbf380d0",
      "name": "Google Sheets - Log Lead",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        768,
        528
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={{ $json.body.name }}",
            "Interest": "={{ $json.body.interest }}",
            "Phone Number": "={{ $json.body.phone }}"
          },
          "schema": [
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone Number",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Phone Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Interest",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Interest",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email Address",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/198LSp7vjwAmoYUHAA-Er8Sq_8BQtUJpnttEtUQez6rc/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "198LSp7vjwAmoYUHAA-Er8Sq_8BQtUJpnttEtUQez6rc",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/198LSp7vjwAmoYUHAA-Er8Sq_8BQtUJpnttEtUQez6rc/edit?usp=drivesdk",
          "cachedResultName": "Real Estate Leads"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "0361ab27-dd29-41a8-81dc-8b31d4648684",
      "name": "OpenAI - Generate Personalized SMS",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        992,
        528
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "GPT-4.1"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "=You are a friendly, professional real estate assistant. \n\nA new lead has just submitted an enquiry form. Your job is to write a warm, personalized SMS message that gets sent to them instantly.\n\nHere are the lead's details:\n- Name: {{ $('Webhook - Lead Form Trigger').item.json.body.name }}\n- Property Type they are interested in: {{ $('Webhook - Lead Form Trigger').item.json.body.interest }}\n\nRules you must follow:\n1. Keep the message under 160 characters if possible, never exceed 320 characters\n2. Address the lead by their first name only\n3. Mention their specific property type and location so it feels personal\n4. End with exactly one question to encourage a reply\n5. Sound like a real human texting from their phone \u2014 warm, casual, not corporate\n6. Never use emojis excessively \u2014 one at most\n7. Never use words like \"greetings\", \"dear\", or \"valued customer\"\n8. Sign off with the agent's first name only\n\nOutput only the SMS message text. Nothing else. No labels, no explanations, no quotation marks."
            },
            {
              "content": "=Lead details:\nName: {{ $('Webhook - Lead Form Trigger').item.json.body.name }}\nProperty Type: {{ $('Webhook - Lead Form Trigger').item.json.body.property_type }}\nLocation: {{ $('Webhook - Lead Form Trigger').item.json.body.location }}\nBudget: {{ $('Webhook - Lead Form Trigger').item.json.body.budget }}\nEnquiry: {{ $('Webhook - Lead Form Trigger').item.json.body.enquiry_details }}\n\nWrite a personalized first SMS to this lead.\n\nExample: Hey {{ $('Webhook - Lead Form Trigger').item.json.body.name }}, thanks for reaching out about {{ $('Webhook - Lead Form Trigger').item.json.body.interest }} We would love to help. Are you looking to buy or sell, and what's your timeline looking like?"
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "51351101-c6b5-471e-832a-40a3d82c6471",
      "name": "Twilio - Send First SMS",
      "type": "n8n-nodes-base.twilio",
      "position": [
        1344,
        528
      ],
      "parameters": {
        "to": "={{ $('Webhook - Lead Form Trigger').item.json.body.phone }}",
        "from": "+1234567890",
        "message": "={{ $json.message.content }}",
        "options": {}
      },
      "credentials": {
        "twilioApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "19d8de66-ad5b-46ac-ac00-1b90ca17e22b",
      "name": "Wait - 2 Hours",
      "type": "n8n-nodes-base.wait",
      "position": [
        1568,
        528
      ],
      "parameters": {
        "amount": 2
      },
      "typeVersion": 1
    },
    {
      "id": "b85273fa-733b-4b69-89fc-14b61541f855",
      "name": "Google Sheets - Check Reply Status",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1792,
        528
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "No Reply",
              "lookupColumn": "Status"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/198LSp7vjwAmoYUHAA-Er8Sq_8BQtUJpnttEtUQez6rc/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "198LSp7vjwAmoYUHAA-Er8Sq_8BQtUJpnttEtUQez6rc",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/198LSp7vjwAmoYUHAA-Er8Sq_8BQtUJpnttEtUQez6rc/edit?usp=drivesdk",
          "cachedResultName": "Real Estate Leads"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "5d4bd359-f83b-463c-ac64-bf8eaa61641b",
      "name": "IF - Has Lead Replied?",
      "type": "n8n-nodes-base.if",
      "position": [
        2016,
        528
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "condition-replied",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.replied }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "1fb32012-a1a9-4396-b521-adee52136563",
      "name": "OpenAI - Generate Follow-Up SMS",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        2240,
        624
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "GPT-4.1"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "=You are a friendly, professional real estate assistant.\n\nA lead submitted an enquiry 48 hours ago and has not replied to the first message. Your job is to write a gentle, non-pushy follow-up SMS to re-engage them.\n\nHere are the lead's details:\n- Name:{{ $('Webhook - Lead Form Trigger').item.json.body.name }}\n- Property Type they are interested in: {{ $('Webhook - Lead Form Trigger').item.json.body.interest }}\n\nRules you must follow:\n1. Keep the message under 320 characters\n2. Acknowledge that you are following up without making them feel guilty for not replying\n3. Briefly mention their property interest to keep it personal\n4. Offer a simple low-commitment action \u2014 like replying YES for a quick call\n5. Sound human and warm, not automated\n6. Never say \"this is a follow-up message\" or \"as per my previous message\"\n7. Sign off with the agent's first name only\n\nOutput only the SMS message text. Nothing else. No labels, no explanations, no quotation marks."
            },
            {
              "content": "=Lead details:\nName: {{ $('Webhook - Lead Form Trigger').item.json.body.name }}\nProperty Type: {{ $('Webhook - Lead Form Trigger').item.json.body.property_type }}\nLocation: {{ $('Webhook - Lead Form Trigger').item.json.body.location }}\nBudget: {{ $('Webhook - Lead Form Trigger').item.json.body.budget }}\n\nWrite a gentle follow-up SMS since they have not replied to the first message."
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "0549d6fc-8c0b-48d2-8087-4a68a4ed64d8",
      "name": "Twilio - Send Follow-Up SMS",
      "type": "n8n-nodes-base.twilio",
      "position": [
        2592,
        624
      ],
      "parameters": {
        "to": "={{ $('Webhook - Lead Form Trigger').item.json.body.phone }}",
        "from": "+1234567890",
        "message": "={{ $json.message.content }}",
        "options": {}
      },
      "credentials": {
        "twilioApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "daf58129-233e-44cd-9a29-5cd390b6fc20",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2304,
        432
      ],
      "parameters": {
        "sendTo": "s",
        "message": "s",
        "options": {},
        "subject": "s"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "0b25b220-57f6-47fb-b7c7-b6c0f5bf17ac",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        352
      ],
      "parameters": {
        "color": 6,
        "width": 160,
        "height": 240,
        "content": "## Customer enquiry"
      },
      "typeVersion": 1
    },
    {
      "id": "5c5a6c89-da60-4b9b-9709-4bdcb1714977",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        240
      ],
      "parameters": {
        "color": 6,
        "width": 192,
        "height": 448,
        "content": "## Respond and update CRM"
      },
      "typeVersion": 1
    },
    {
      "id": "8ea34826-05c6-4e6f-bf81-e88f4e9da73f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        960,
        400
      ],
      "parameters": {
        "color": 6,
        "width": 528,
        "height": 288,
        "content": "## Send initial message"
      },
      "typeVersion": 1
    },
    {
      "id": "de3912e3-ec34-4627-98c0-dd3899b675de",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1728,
        352
      ],
      "parameters": {
        "color": 6,
        "width": 1024,
        "height": 432,
        "content": "## Check the reply status and take next steps accordingly"
      },
      "typeVersion": 1
    },
    {
      "id": "0d0dfa2d-5065-40bd-912c-1a2550efe96e",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -544,
        -384
      ],
      "parameters": {
        "width": 800,
        "height": 1616,
        "content": "# \ud83e\udd16 AI Lead Follow-Up Automation\n\nAutomatically respond to website enquiries, log leads, send AI-personalised SMS messages, and follow up \u2014 all without lifting a finger.\n\n---\n\n## \u2699\ufe0f How It Works\n\n1. A lead submits your **website contact form**, triggering the webhook\n2. The lead is **logged to Google Sheets** (`Name`, `Phone`, `Email`, `Interest`)\n3. **GPT-4.1** generates a personalised initial SMS based on the lead's details\n4. **Twilio** sends the first SMS to the lead\n5. The workflow **waits 2 hours**\n6. **Google Sheets** is checked \u2014 has the `Replied` column been marked `Yes`?\n7. **If YES** \u2192 A **Gmail notification** is sent to you (the agent/owner)\n8. **If NO** \u2192 **GPT-4.1** generates a follow-up SMS and **Twilio** sends it\n\n---\n\n## \ud83d\udee0\ufe0f Setup Checklist\n\n**Webhook**\n- [ ] Copy the webhook URL and paste it as the POST endpoint in your website contact form\n- [ ] Ensure your form sends: `name`, `phone`, `email`, `interest`\n\n**Google Sheets**\n- [ ] Create a sheet with columns: `Name` | `Phone` | `Email` | `Interest` | `Replied`\n- [ ] Connect your Google account in the Google Sheets nodes\n- [ ] Update the sheet ID in both Google Sheets nodes to match your sheet\n- [ ] Manually update the `Replied` column to `Yes` when a lead responds\n\n**OpenAI**\n- [ ] Add your **OpenAI API key** in both OpenAI nodes\n- [ ] Model is set to `gpt-4.1` \u2014 change if needed\n- [ ] Customise the system prompts in both nodes to match your business tone and offer\n\n**Twilio**\n- [ ] Add your **Twilio Account SID** and **Auth Token** in both Twilio nodes\n- [ ] Set your **Twilio phone number** as the sender in both SMS nodes\n- [ ] Ensure the `phone` field from your form includes the country code (e.g. `+91...`)\n\n**Gmail**\n- [ ] Connect your **Gmail account** in the Gmail node\n- [ ] Update the recipient email to your own address for lead reply notifications\n\n---\n\n## \u26a0\ufe0f Important Notes\n\n> The `Replied` status is **manually updated** in Google Sheets. For a fully automated reply-detection system, consider integrating a Twilio inbound webhook.\n\n> The **2-hour wait** uses n8n's built-in Wait node. Adjust the duration based on your follow-up strategy.\n\n> Make sure your n8n instance is on a **paid or self-hosted plan** to support long waits and webhook triggers in production.\n\n---\n\n## \ud83d\udd11 API Keys Required\n\n| Service | Where to Get It |\n|---|---|\n| OpenAI | [platform.openai.com](https://platform.openai.com) |\n| Twilio | [console.twilio.com](https://console.twilio.com) |\n| Google Sheets |   Via Google OAuth in n8n credentials |\n| Gmail | Via Google OAuth in n8n credentials |"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "48e3ac26-a4d5-42bb-8bae-81a2a793b108",
  "connections": {
    "Wait - 2 Hours": {
      "main": [
        [
          {
            "node": "Google Sheets - Check Reply Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF - Has Lead Replied?": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "OpenAI - Generate Follow-Up SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Twilio - Send First SMS": {
      "main": [
        [
          {
            "node": "Wait - 2 Hours",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Log Lead": {
      "main": [
        [
          {
            "node": "OpenAI - Generate Personalized SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook - Lead Form Trigger": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          },
          {
            "node": "Google Sheets - Log Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Generate Follow-Up SMS": {
      "main": [
        [
          {
            "node": "Twilio - Send Follow-Up SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Check Reply Status": {
      "main": [
        [
          {
            "node": "IF - Has Lead Replied?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Generate Personalized SMS": {
      "main": [
        [
          {
            "node": "Twilio - Send First SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}