{
  "name": "Caipher AI - Create Lead",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "elevenlabs-webhook/create-lead",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        260,
        460
      ],
      "id": "wh-create-lead",
      "name": "Create Lead Webhook"
    },
    {
      "parameters": {
        "jsCode": "const body = $input.all()[0].json.body || $input.all()[0].json;\n\nconst caller_name = body.caller_name || body.name || 'Unknown';\nconst caller_phone = body.caller_phone || body.phone || body.phone_number || '';\nconst caller_email = body.caller_email || body.email || '';\nconst business_name = body.business_name || body.company || '';\nconst industry = body.industry || '';\nconst interest = body.interest || body.reason || '';\nconst notes = body.notes || '';\n\nreturn [{\n  json: {\n    caller_name,\n    caller_phone,\n    caller_email,\n    business_name,\n    industry,\n    interest,\n    notes,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        460
      ],
      "id": "parse-lead",
      "name": "Parse Lead Data"
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "1KFnP0q_oY91rUX3KHzEOCuukxc4C3opkPLhOQMXBvzU",
          "mode": "list",
          "cachedResultName": "lead_template",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1KFnP0q_oY91rUX3KHzEOCuukxc4C3opkPLhOQMXBvzU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1KFnP0q_oY91rUX3KHzEOCuukxc4C3opkPLhOQMXBvzU/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "name": "={{ $json.caller_name }}",
            "phone_number": "={{ $json.caller_phone }}",
            "email": "={{ $json.caller_email }}",
            "business_name": "={{ $json.business_name }}",
            "status": "=NEW_LEAD",
            "last_called": "={{ $json.timestamp }}",
            "notes": "={{ $json.notes || $json.interest }}",
            "output": "=INBOUND - NEW_LEAD",
            "leadCategory": "=Inbound Lead",
            "interestLevel": "=Warm"
          },
          "matchingColumns": [
            "phone_number"
          ],
          "schema": [
            {
              "id": "name",
              "displayName": "name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "business_name",
              "displayName": "business_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "phone_number",
              "displayName": "phone_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "displayName": "email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "last_called",
              "displayName": "last_called",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "notes",
              "displayName": "notes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "output",
              "displayName": "output",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "leadCategory",
              "displayName": "leadCategory",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "interestLevel",
              "displayName": "interestLevel",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        740,
        460
      ],
      "id": "save-lead",
      "name": "Save Lead to Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, message: 'Lead created for ' + $('Parse Lead Data').first().json.caller_name, lead_name: $('Parse Lead Data').first().json.caller_name, lead_phone: $('Parse Lead Data').first().json.caller_phone }) }}"
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        980,
        460
      ],
      "id": "respond-lead",
      "name": "Respond Success"
    }
  ],
  "connections": {
    "Create Lead Webhook": {
      "main": [
        [
          {
            "node": "Parse Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Lead Data": {
      "main": [
        [
          {
            "node": "Save Lead to Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Lead to Sheets": {
      "main": [
        [
          {
            "node": "Respond Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": []
}