{
  "name": "Inbound Form",
  "nodes": [
    {
      "parameters": {
        "path": "inbound/form",
        "method": "POST"
      },
      "id": "Webhook",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        200,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "const payload = items[0].json;\nreturn [{ json: {\n  email: payload.email || payload.contact_email,\n  name: payload.name || payload.full_name,\n  phone: payload.phone,\n  company: payload.company,\n  country: payload.country,\n  optIn: payload.optIn ?? false,\n  source: payload.source || 'webhook',\n  extras: payload\n} }];"
      },
      "id": "Normalize",
      "name": "Normalize",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        440,
        200
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "http://api:8080/v1/leads?score=true",
        "jsonParameters": true,
        "options": {
          "headers": {
            "X-API-Key": "={{$env.API_DEV_KEY}}",
            "X-Idempotency-Key": "={{$json.email}}-{{$json.source}}"
          }
        },
        "body": "={{$json}}"
      },
      "id": "CreateLead",
      "name": "Create Lead",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        680,
        200
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$json[\"body\"].scoreTotal}}",
              "operation": "largerEqual",
              "value2": 60
            }
          ]
        }
      },
      "id": "CheckScore",
      "name": "Check Score",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        920,
        200
      ]
    },
    {
      "parameters": {
        "channel": "#leads",
        "text": "={{`Novo lead: ${$json.body.email} (score ${$json.body.scoreTotal})`}}"
      },
      "id": "Notify",
      "name": "Notify Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 1,
      "position": [
        1160,
        120
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Normalize",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize": {
      "main": [
        [
          {
            "node": "Create Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Lead": {
      "main": [
        [
          {
            "node": "Check Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Score": {
      "main": [
        [],
        [
          {
            "node": "Notify Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}