{
  "name": "Nodebuilt – WhatsApp Lead Bot (Twilio + Claude + Airtable)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "whatsapp-inbound",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "11111111-0001-4000-8000-000000000001",
      "name": "WhatsApp message in (Twilio)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "whatsapp-inbound"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "phone",
              "value": "={{ $json.body.From.replace('whatsapp:', '') }}",
              "type": "string"
            },
            {
              "id": "a2",
              "name": "message",
              "value": "={{ $json.body.Body }}",
              "type": "string"
            },
            {
              "id": "a3",
              "name": "name",
              "value": "={{ $json.body.ProfileName || 'there' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "11111111-0001-4000-8000-000000000002",
      "name": "Extract fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.anthropic.com/v1/messages",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "anthropicApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "anthropic-version",
              "value": "2023-06-01"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'claude-haiku-4-5', max_tokens: 100, system: 'Classify the customer WhatsApp message for a small business. Reply ONLY with JSON: {\"intent\": \"pricing\"|\"demo\"|\"support\"|\"unknown\", \"confidence\": 0-1}', messages: [{ role: 'user', content: $json.message }] }) }}",
        "options": {}
      },
      "id": "11111111-0001-4000-8000-000000000003",
      "name": "Claude: classify intent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Robust: if Claude's answer is not valid JSON, fall back to 'unknown' (production tip from the video)\nconst lead = $('Extract fields').first().json;\nlet intent = 'unknown', confidence = 0;\ntry {\n  const text = ($input.first().json.content || [])[0]?.text || '';\n  const r = JSON.parse(text.slice(text.indexOf('{'), text.lastIndexOf('}') + 1));\n  if (['pricing', 'demo', 'support'].includes(r.intent)) { intent = r.intent; confidence = r.confidence ?? 0; }\n} catch (e) {}\nreturn [{ json: { ...lead, intent, confidence, received_at: new Date().toISOString() } }];"
      },
      "id": "11111111-0001-4000-8000-000000000004",
      "name": "Parse intent",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        300
      ]
    },
    {
      "parameters": {
        "operation": "create",
        "base": {
          "__rl": true,
          "mode": "id",
          "value": "appYOURBASEID"
        },
        "table": {
          "__rl": true,
          "mode": "id",
          "value": "tblYOURTABLEID"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Phone": "={{ $json.phone }}",
            "Name": "={{ $json.name }}",
            "Message": "={{ $json.message }}",
            "Intent": "={{ $json.intent }}",
            "Received": "={{ $json.received_at }}"
          },
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "11111111-0001-4000-8000-000000000005",
      "name": "Save lead in Airtable",
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        960,
        300
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "c1",
                    "leftValue": "={{ $('Parse intent').item.json.intent }}",
                    "rightValue": "pricing",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Pricing"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "c2",
                    "leftValue": "={{ $('Parse intent').item.json.intent }}",
                    "rightValue": "demo",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Demo"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "id": "c3",
                    "leftValue": "={{ $('Parse intent').item.json.intent }}",
                    "rightValue": "support",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Support"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Unknown"
        }
      },
      "id": "11111111-0001-4000-8000-000000000006",
      "name": "Route by intent",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        1200,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "r1",
              "name": "reply",
              "value": "=Hi {{ $('Parse intent').item.json.name }}! Our plans start at $29/month. Here is the full price list: https://yourcompany.com/pricing",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "11111111-0001-4000-8000-000000000007",
      "name": "Reply: pricing",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1440,
        60
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "r2",
              "name": "reply",
              "value": "=Hi {{ $('Parse intent').item.json.name }}! Happy to show you a demo. Pick a time here: https://yourcompany.com/book",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "11111111-0001-4000-8000-000000000008",
      "name": "Reply: demo",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1440,
        220
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "r3",
              "name": "reply",
              "value": "=Hi {{ $('Parse intent').item.json.name }}, thanks for reaching out. Our support team will get back to you within one business day.",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "11111111-0001-4000-8000-000000000009",
      "name": "Reply: support",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1440,
        380
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "r4",
              "name": "reply",
              "value": "=Hi {{ $('Parse intent').item.json.name }}! Thanks for your message – a team member will reply shortly.",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "11111111-0001-4000-8000-000000000010",
      "name": "Reply: fallback",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1440,
        540
      ]
    },
    {
      "parameters": {
        "from": "+14155238886",
        "to": "={{ $('Parse intent').item.json.phone }}",
        "toWhatsapp": true,
        "message": "={{ $json.reply }}",
        "options": {}
      },
      "id": "11111111-0001-4000-8000-000000000011",
      "name": "Send WhatsApp reply (Twilio)",
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1700,
        300
      ]
    }
  ],
  "connections": {
    "WhatsApp message in (Twilio)": {
      "main": [
        [
          {
            "node": "Extract fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract fields": {
      "main": [
        [
          {
            "node": "Claude: classify intent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude: classify intent": {
      "main": [
        [
          {
            "node": "Parse intent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse intent": {
      "main": [
        [
          {
            "node": "Save lead in Airtable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save lead in Airtable": {
      "main": [
        [
          {
            "node": "Route by intent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by intent": {
      "main": [
        [
          {
            "node": "Reply: pricing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reply: demo",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reply: support",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reply: fallback",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply: pricing": {
      "main": [
        [
          {
            "node": "Send WhatsApp reply (Twilio)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply: demo": {
      "main": [
        [
          {
            "node": "Send WhatsApp reply (Twilio)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply: support": {
      "main": [
        [
          {
            "node": "Send WhatsApp reply (Twilio)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply: fallback": {
      "main": [
        [
          {
            "node": "Send WhatsApp reply (Twilio)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "https://nodebuilt.com/templates/whatsapp-lead-bot"
  }
}