{
  "name": "Caipher AI - Log Inquiry",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "elevenlabs-webhook/log-inquiry",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        260,
        460
      ],
      "id": "wh-log-inquiry",
      "name": "Log Inquiry 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 inquiry = body.inquiry || body.question || body.message || '';\nconst notes = body.notes || '';\nconst category = body.category || 'General Inquiry';\n\nreturn [{\n  json: {\n    caller_name,\n    caller_phone,\n    caller_email,\n    business_name,\n    inquiry,\n    notes,\n    category,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        460
      ],
      "id": "parse-inquiry",
      "name": "Parse Inquiry 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": "=INQUIRY",
            "last_called": "={{ $json.timestamp }}",
            "notes": "={{ $json.inquiry + ($json.notes ? ' | ' + $json.notes : '') }}",
            "output": "=INBOUND - INQUIRY",
            "leadCategory": "={{ $json.category }}",
            "interestLevel": "=Unknown"
          },
          "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-inquiry",
      "name": "Log Inquiry to Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, message: 'Inquiry logged for ' + $('Parse Inquiry Data').first().json.caller_name, inquiry: $('Parse Inquiry Data').first().json.inquiry }) }}"
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        980,
        460
      ],
      "id": "respond-inquiry",
      "name": "Respond Success"
    }
  ],
  "connections": {
    "Log Inquiry Webhook": {
      "main": [
        [
          {
            "node": "Parse Inquiry Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Inquiry Data": {
      "main": [
        [
          {
            "node": "Log Inquiry to Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Inquiry to Sheets": {
      "main": [
        [
          {
            "node": "Respond Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": []
}