{
  "name": "Appointment Leads & Follow-up",
  "nodes": [
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000001",
      "name": "Webhook (Lead Intake)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [-480, 300],
      "parameters": { "path": "lead-intake" },
      "webhookId": "wh-lead-intake-001"
    },
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000002",
      "name": "Format Lead Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-280, 300],
      "parameters": {
        "values": {
          "string": [
            { "name": "name", "value": "={{$json.body.name || $json.body.fullName}}" },
            { "name": "email", "value": "={{$json.body.email}}" },
            { "name": "phone", "value": "={{$json.body.phone}}" },
            { "name": "company", "value": "={{$json.body.company || ''}}" },
            { "name": "interest", "value": "={{$json.body.interest || $json.body.message || ''}}" }
          ]
        }
      }
    },
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000003",
      "name": "AI Lead Qualification",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [-80, 300],
      "parameters": {
        "options": { "model": "gpt-4o-mini", "temperature": 0.2 },
        "messages": {
          "values": [
            { "role": "system", "message": "Analyze the lead data. Return JSON: { qualified: boolean, score: 1-100, reason: string, suggestedAction: 'schedule'|'nurture'|'discard' }" },
            { "role": "user", "message": "Name: {{$json.name}}\nCompany: {{$json.company}}\nInterest: {{$json.interest}}" }
          ]
        }
      },
      "credentials": { "openAiApi": { "id": null, "name": "OpenAI API" } }
    },
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000004",
      "name": "Parse AI Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [120, 300],
      "parameters": {
        "jsCode": "const raw = $input.first().json;\nconst output = raw.output || raw.text || '{}';\nlet parsed;\ntry { parsed = JSON.parse(output); } catch (e) { parsed = { qualified: true, score: 50, reason: 'fallback', suggestedAction: 'nurture' }; }\nreturn [{ json: { ...$node['Format Lead Data'].json, aiScore: parsed.score, aiQualified: parsed.qualified, suggestedAction: parsed.suggestedAction } }];"
      }
    },
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000005",
      "name": "IF Qualified?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [320, 300],
      "parameters": {
        "conditions": { "string": [{ "value1": "={{$json.suggestedAction}}", "operation": "equal", "value2": "schedule" }] }
      }
    },
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000006",
      "name": "Cal.com Create Event",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [540, 200],
      "parameters": {
        "url": "https://api.cal.com/v1/bookings",
        "method": "POST",
        "sendBody": true,
        "bodyParameters": { "parameters": [
          { "name": "email", "value": "={{$json.email}}" },
          { "name": "name", "value": "={{$json.name}}" },
          { "name": "eventTypeId", "value": "123456" }
        ]}
      },
      "credentials": { "httpQueryAuth": { "id": null, "name": "Cal.com API Key" } }
    },
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000007",
      "name": "Twilio SMS",
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [740, 200],
      "parameters": { "resource": "message", "operation": "create", "to": "={{$node['Format Lead Data'].json.phone}}" },
      "credentials": { "twilioApi": { "id": null, "name": "Twilio API" } }
    },
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000008",
      "name": "Google Sheets (Hot)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [940, 200],
      "parameters": { "operation": "appendOrUpdate", "resource": "sheet", "sheetName": "Hot Leads" },
      "credentials": { "googleSheetsOAuth2Api": { "id": null, "name": "Google Sheets OAuth2" } }
    },
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000009",
      "name": "Slack Alert",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [1140, 200],
      "parameters": { "operation": "post", "resource": "message", "channel": "C0XXXXXXX" },
      "credentials": { "slackApi": { "id": null, "name": "Slack API" } }
    },
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000010",
      "name": "Google Sheets (Nurture)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [540, 480],
      "parameters": { "operation": "appendOrUpdate", "resource": "sheet", "sheetName": "Nurture List" },
      "credentials": { "googleSheetsOAuth2Api": { "id": null, "name": "Google Sheets OAuth2" } }
    },
    {
      "id": "c3d4e5f6-3333-4000-8000-000000000011",
      "name": "Webhook Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [1360, 300],
      "parameters": { "respondWith": "json", "responseBody": "={ message: 'Lead received' }" }
    }
  ],
  "connections": {
    "Webhook (Lead Intake)": { "main": [[{ "node": "Format Lead Data", "type": "main", "index": 0 }]] },
    "Format Lead Data": { "main": [[{ "node": "AI Lead Qualification", "type": "main", "index": 0 }]] },
    "AI Lead Qualification": { "main": [[{ "node": "Parse AI Response", "type": "main", "index": 0 }]] },
    "Parse AI Response": { "main": [[{ "node": "IF Qualified?", "type": "main", "index": 0 }]] },
    "IF Qualified?": {
      "main": [
        [{ "node": "Cal.com Create Event", "type": "main", "index": 0 }],
        [{ "node": "Google Sheets (Nurture)", "type": "main", "index": 0 }]
      ]
    },
    "Cal.com Create Event": { "main": [[{ "node": "Twilio SMS", "type": "main", "index": 0 }]] },
    "Twilio SMS": { "main": [[{ "node": "Google Sheets (Hot)", "type": "main", "index": 0 }]] },
    "Google Sheets (Hot)": { "main": [[{ "node": "Slack Alert", "type": "main", "index": 0 }]] },
    "Slack Alert": { "main": [[{ "node": "Webhook Response", "type": "main", "index": 0 }]] },
    "Google Sheets (Nurture)": { "main": [[{ "node": "Webhook Response", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "staticData": null,
  "pinData": {},
  "triggerCount": 1,
  "meta": { "templateCredsSetupCompleted": true }
}
