{
  "meta": {
    "instanceId": "bc8ca75c203589705ae2e446cad7181d6f2a7cc1766f958ef9f34810e53b8cb2"
  },
  "nodes": [
    {
      "id": "42d8a3f9-abdf-405c-83f0-d0e8d9751e5e",
      "name": "Receive User Message via Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        64,
        -16
      ],
      "webhookId": "ff8b6142-d902-41ca-a666-a9e734e8ef14",
      "parameters": {
        "path": "ff8b6142-d902-41ca-a666-a9e734e8ef14",
        "options": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "f097a9a1-0232-453c-95e8-43ee1e71d018",
      "name": "Conversational Lead Collection Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        384,
        -16
      ],
      "parameters": {
        "text": "=## User Message\n{{ $json.query.message }}",
        "options": {
          "systemMessage": "=You are a conversational booking assistant for Spark Writers' Retreat.\n\nYour responsibility is to chat naturally with the user and collect these four details:\n1. Name\n2. Phone number\n3. Email address\n4. User message / requirement\n\nConversation rules:\n- Ask only ONE question at a time.\n- Never ask for information that is already collected.\n- If the user gives unclear or invalid input, politely ask again.\n- Keep replies short and friendly.\n- Do not sound like a form or bot.\n\nFlow logic:\n- If Name is missing → ask for name.\n- If Phone number is missing → ask for phone number.\n- If Email is missing → ask for email address.\n- If Message is missing → ask how you can help.\n\nTool usage (VERY IMPORTANT):\n- Only use the Google Sheets tool AFTER all four details are confidently collected.\n- Do NOT write to the sheet if any field is missing.\n- Write exactly ONE row per user conversation.\n\nData mapping:\n- Name → Name\n- Phone number → Phone_No_\n- Email → Email\n- User message → Message\n\nAfter successfully writing to the Google Sheet:\n- Thank the user politely.\n- Confirm that the team will contact them shortly.\n\nDo NOT:\n- Mention Google Sheets, tools, backend, webhook, or automation.\n- Save partial or guessed data.\n- Repeat questions unnecessarily.\n\nFinal user message:\n\"Thank you! 🙏 We’ve received your details and our team will get back to you shortly.\""
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "92930286-b494-45fe-bddf-7a44891423a1",
      "name": "OpenAI GPT-4.1 Mini Language Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        304,
        208
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "u1QSiOsEr33tUNn7",
          "name": "testing"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "7513a489-35e7-4423-bae9-f0c668ec7c29",
      "name": "Session Memory with Timestamp",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        480,
        208
      ],
      "parameters": {
        "sessionKey": "={{ $('Receive User Message via Webhook').item.json.query.timestamp }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "79705264-3171-4180-8a3c-a29e95cb93e2",
      "name": "Save Lead to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        784,
        -16
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={{ $('Receive User Message via Webhook').item.json.query.name }}",
            "Email": "={{ $('Receive User Message via Webhook').item.json.query.email }}",
            "Message": "={{ $('Receive User Message via Webhook').item.json.query.message }}",
            "Phone No.": "={{ $('Receive User Message via Webhook').item.json.query.phone }}",
            "Timestamp": "={{ $('Receive User Message via Webhook').item.json.query.timestamp }}"
          },
          "schema": [
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone No.",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Phone No.",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Timestamp"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 768094711,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1L709LroC9hYWF1EI4snFgTEzlSVT7aFwTb5mdGNO8NQ/edit#gid=768094711",
          "cachedResultName": "Session Leads"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1L709LroC9hYWF1EI4snFgTEzlSVT7aFwTb5mdGNO8NQ",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1L709LroC9hYWF1EI4snFgTEzlSVT7aFwTb5mdGNO8NQ/edit?usp=drivesdk",
          "cachedResultName": "Sparkwritersretreat.com - Leads Tracking"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "RlWUh53UsWGmpb06",
          "name": "Google Sheets - Krishna"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "5d7a2403-d11b-4b85-bcc9-fa631795efe5",
      "name": "Send AI Reply to User",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1088,
        -16
      ],
      "parameters": {
        "options": {},
        "respondWith": "allIncomingItems"
      },
      "typeVersion": 1.5
    },
    {
      "id": "01b09ab4-a6ea-4e29-a9c1-cdf5ed7162ae",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        -256
      ],
      "parameters": {
        "width": 432,
        "height": 752,
        "content": "## AI Booking Chatbot with Lead Collection\n\nThis workflow creates a conversational AI chatbot that naturally\ncollects lead information (Name, Phone, Email, Message) one\nquestion at a time—without feeling like a form. The AI remembers\nthe conversation context using session-based memory, asks only\nfor missing details, and saves complete leads to Google Sheets.\nPerfect for booking systems, contact forms, or any lead capture\nthat needs a human-like conversation experience.\n\n## How it works\n1. User sends a message through webhook integration.\n2. AI checks which details are already collected vs. missing.\n3. Asks ONE question at a time in natural, friendly language.\n4. Session memory tracks the conversation using timestamp ID.\n5. Once all 4 fields collected, AI saves lead to Google Sheets.\n6. Sends confirmation message and AI reply back to user.\n\n## Setup steps\n1. Connect Google Sheets OAuth credentials.\n2. Add OpenAI API key for GPT-4.1-mini model.\n3. Update Google Sheet URL and sheet name in save node.\n4. Copy webhook URL and integrate with your website/app.\n5. Test by sending messages with query parameters."
      },
      "typeVersion": 1
    },
    {
      "id": "c565861e-a63a-4ece-8665-2b5f1810b7a7",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        64,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 208,
        "content": "## Message Receive & AI Processing\n\nReceives user messages via webhook, processes\nthem through the conversational AI agent that\nintelligently asks for missing lead information."
      },
      "typeVersion": 1
    },
    {
      "id": "678385ae-f5da-4e9f-9abc-43664dff705a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 320,
        "height": 208,
        "content": "##  Lead Storage\n\nOnce all 4 details are collected (Name, Phone,\nEmail, Message), the AI saves the complete\nlead data to Google Sheets using timestamp."
      },
      "typeVersion": 1
    },
    {
      "id": "9942d548-022d-4132-ab6e-2b90e33b4299",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        976,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 208,
        "content": "## Response Delivery\n\nSends the AI's conversational reply back\nto the user via webhook, continuing the\nnatural conversation flow."
      },
      "typeVersion": 1
    }
  ],
  "pinData": {
    "Receive User Message via Webhook": [
      {
        "body": {},
        "query": {
          "name": "xyz",
          "email": "text@gmail.com",
          "phone": "6756453432",
          "source": "weekly_session",
          "message": "cgdtrttf",
          "timestamp": "2026-01-28T14:38:23.720Z"
        },
        "params": {},
        "headers": {
          "host": "shivgupta01.app.n8n.cloud",
          "accept": "*/*",
          "cf-ray": "9c513c2022e78af8-DEL",
          "referer": "https://preview--story-mountain-forge.lovable.app/",
          "cdn-loop": "cloudflare; loops=1; subreqs=1",
          "priority": "u=1, i",
          "cf-ew-via": "15",
          "cf-worker": "n8n.cloud",
          "sec-ch-ua": "\"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"144\", \"Google Chrome\";v=\"144\"",
          "x-real-ip": "150.242.66.73",
          "cf-visitor": "{\"scheme\":\"https\"}",
          "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
          "cf-ipcountry": "IN",
          "x-is-trusted": "yes",
          "sec-fetch-dest": "empty",
          "sec-fetch-mode": "no-cors",
          "sec-fetch-site": "cross-site",
          "accept-encoding": "gzip, br",
          "accept-language": "en-US,en;q=0.9",
          "x-forwarded-for": "150.242.66.73, 104.23.216.135",
          "cf-connecting-ip": "150.242.66.73",
          "sec-ch-ua-mobile": "?0",
          "x-forwarded-host": "shivgupta01.app.n8n.cloud",
          "x-forwarded-port": "443",
          "x-forwarded-proto": "https",
          "sec-ch-ua-platform": "\"Windows\"",
          "x-forwarded-server": "traefik-prod-users-gwc-11-cb7f6dc87-bk27x"
        },
        "webhookUrl": "https://shivgupta01.app.n8n.cloud/webhook/ff8b6142-d902-41ca-a666-a9e734e8ef14",
        "executionMode": "production"
      }
    ]
  },
  "connections": {
    "Save Lead to Google Sheets": {
      "main": [
        [
          {
            "node": "Send AI Reply to User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Session Memory with Timestamp": {
      "ai_memory": [
        [
          {
            "node": "Conversational Lead Collection Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Receive User Message via Webhook": {
      "main": [
        [
          {
            "node": "Conversational Lead Collection Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4.1 Mini Language Model": {
      "ai_languageModel": [
        [
          {
            "node": "Conversational Lead Collection Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Conversational Lead Collection Agent": {
      "main": [
        [
          {
            "node": "Save Lead to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}