{
  "name": "LEVRYO - Form to AI Lead Score to Google Sheets",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Tell us about your project",
        "formDescription": "We reply within one business day.",
        "formFields": {
          "values": [
            { "fieldLabel": "Name", "requiredField": true },
            { "fieldLabel": "Email", "fieldType": "email", "requiredField": true },
            { "fieldLabel": "Company" },
            { "fieldLabel": "What do you need help with?", "fieldType": "textarea", "requiredField": true },
            {
              "fieldLabel": "Monthly budget",
              "fieldType": "dropdown",
              "fieldOptions": { "values": [{ "option": "Under $500" }, { "option": "$500 to $2,000" }, { "option": "Over $2,000" }] }
            }
          ]
        },
        "options": {}
      },
      "id": "lead-form",
      "name": "Lead Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [0, 0],
      "notes": "n8n hosts this form for you. Copy the production URL from this node and link it from your site, or replace the node with a Webhook if you already have a form."
    },
    {
      "parameters": {
        "modelId": { "__rl": true, "mode": "list", "value": "gpt-4o-mini" },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You score inbound leads for a small business. IDEAL CUSTOMER: a small or mid-sized business that needs automation or AI work done, has a real budget, and describes a concrete problem. Replace this sentence with two or three sentences about who you actually sell to. Reply with JSON only: {\"score\": <1-10>, \"reason\": \"<one short sentence>\"}."
            },
            {
              "content": "=Name: {{ $json.Name }}\nEmail: {{ $json.Email }}\nCompany: {{ $json.Company }}\nBudget: {{ $json['Monthly budget'] }}\nRequest: {{ $json['What do you need help with?'] }}"
            }
          ]
        },
        "jsonOutput": true,
        "options": {}
      },
      "id": "openai-score",
      "name": "AI Lead Score",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [240, 0],
      "notes": "Edit the IDEAL CUSTOMER sentence in the system message. The score is only as good as that description. Works with the Anthropic node too: swap the node and keep the same prompt."
    },
    {
      "parameters": {
        "jsCode": "const raw = $input.first().json;\nlet out = raw.message?.content ?? raw.output ?? raw;\nif (typeof out === 'string') {\n  try { out = JSON.parse(out.replace(/```json|```/g, '').trim()); }\n  catch (e) { out = { score: 0, reason: 'Could not parse model reply' }; }\n}\nconst lead = $('Lead Form').first().json;\nreturn [{ json: {\n  name: lead.Name || '',\n  email: lead.Email || '',\n  company: lead.Company || '',\n  budget: lead['Monthly budget'] || '',\n  request: lead['What do you need help with?'] || '',\n  score: Number(out.score) || 0,\n  reason: String(out.reason || ''),\n  scored_at: new Date().toISOString()\n} }];"
      },
      "id": "parse-score",
      "name": "Parse Score",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [480, 0]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": { "__rl": true, "mode": "list", "value": "" },
        "sheetName": { "__rl": true, "mode": "list", "value": "" },
        "columns": { "mappingMode": "autoMapInputData", "value": {}, "matchingColumns": [], "schema": [] },
        "options": {}
      },
      "id": "sheets-append",
      "name": "Log Lead to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [720, 0],
      "notes": "Create a sheet with these header cells in row 1: name, email, company, budget, request, score, reason, scored_at. Then select the spreadsheet and sheet here."
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 },
          "conditions": [
            { "id": "c1", "leftValue": "={{ $json.score }}", "rightValue": 7, "operator": { "type": "number", "operation": "gte" } }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "if-hot",
      "name": "Score 7 or higher?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [960, 0]
    },
    {
      "parameters": {
        "sendTo": "you@yourcompany.com",
        "subject": "=Hot lead ({{ $json.score }}/10): {{ $json.name }} at {{ $json.company }}",
        "emailType": "text",
        "message": "=Score: {{ $json.score }}/10\nReason: {{ $json.reason }}\n\nName: {{ $json.name }}\nEmail: {{ $json.email }}\nCompany: {{ $json.company }}\nBudget: {{ $json.budget }}\n\nRequest:\n{{ $json.request }}",
        "options": {}
      },
      "id": "gmail-alert",
      "name": "Email the Owner",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [1200, -120],
      "notes": "Change sendTo to the address that should get hot leads."
    }
  ],
  "connections": {
    "Lead Form": { "main": [[{ "node": "AI Lead Score", "type": "main", "index": 0 }]] },
    "AI Lead Score": { "main": [[{ "node": "Parse Score", "type": "main", "index": 0 }]] },
    "Parse Score": { "main": [[{ "node": "Log Lead to Sheet", "type": "main", "index": 0 }]] },
    "Log Lead to Sheet": { "main": [[{ "node": "Score 7 or higher?", "type": "main", "index": 0 }]] },
    "Score 7 or higher?": { "main": [[{ "node": "Email the Owner", "type": "main", "index": 0 }], []] }
  },
  "settings": { "executionOrder": "v1" },
  "meta": { "templateCredsSetupCompleted": false },
  "tags": []
}
