{
  "name": "FlowPantry - AI lead qualifier that scores and routes form leads",
  "nodes": [
    {
      "id": "d4408941-f5f8-4290-899f-eca81a61de4e",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "qualify-lead",
        "responseMode": "onReceived",
        "options": {}
      },
      "webhookId": "8877643f-2021-4fd6-bbee-eba282aaa05f"
    },
    {
      "id": "4a1abcc6-a46e-4d6e-a55e-38f9b8878f9b",
      "name": "AI score",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({model:'gpt-4o-mini', messages:[{role:'user', content: 'Score this lead 1-10 for fit with: '+$env.IDEAL_CUSTOMER+'. Respond ONLY JSON {\"score\":n,\"reason\":\"...\"}. Lead: '+JSON.stringify($json.body||$json)}]}) }}",
        "options": {}
      }
    },
    {
      "id": "1ff8983b-2700-4a59-b6f4-f70959b4cd55",
      "name": "Parse and route",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "return $input.all().map((i,idx)=>{let r={score:0,reason:'parse error'};try{r=JSON.parse(i.json.choices[0].message.content)}catch(e){};const lead=$('Webhook').all()[idx].json.body||{};return {json:{...r,lead,hot:r.score>=7}}});"
      }
    },
    {
      "id": "829d471d-b326-47ee-8abb-80e5b15cfbd1",
      "name": "Post to Slack",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $json.hot ? $env.SLACK_HOT_URL : $env.SLACK_OTHER_URL }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({text: ($json.hot?'<!here> HOT ':'')+'Lead '+$json.score+'/10: '+($json.lead.name||'')+' '+($json.lead.phone||'')+' - '+$json.reason}) }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "AI score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI score": {
      "main": [
        [
          {
            "node": "Parse and route",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse and route": {
      "main": [
        [
          {
            "node": "Post to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}