{
  "name": "XMACNA - Qualificacao de leads com IA",
  "nodes": [
    {
      "parameters": {},
      "id": "a2c3c20d-7856-4c3c-9f39-842100000001",
      "name": "Manual start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [220, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "lead_name",
              "name": "lead.name",
              "type": "string",
              "value": "Maria Silva"
            },
            {
              "id": "lead_company",
              "name": "lead.company",
              "type": "string",
              "value": "Empresa Exemplo"
            },
            {
              "id": "lead_segment",
              "name": "lead.segment",
              "type": "string",
              "value": "educacao"
            },
            {
              "id": "lead_channel",
              "name": "lead.channel",
              "type": "string",
              "value": "whatsapp"
            },
            {
              "id": "pain",
              "name": "input.primary_pain",
              "type": "string",
              "value": "perda de leads por demora no primeiro atendimento"
            },
            {
              "id": "volume",
              "name": "input.monthly_volume",
              "type": "number",
              "value": 450
            },
            {
              "id": "urgency",
              "name": "input.urgency",
              "type": "string",
              "value": "high"
            },
            {
              "id": "crm",
              "name": "input.uses_crm",
              "type": "boolean",
              "value": true
            }
          ]
        },
        "options": {}
      },
      "id": "a2c3c20d-7856-4c3c-9f39-842100000002",
      "name": "Example lead",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [460, 300]
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first().json;\nconst input = item.input || {};\nconst lead = item.lead || {};\nlet score = 0;\nconst pain = String(input.primary_pain || '').trim();\nconst volume = Number(input.monthly_volume || 0);\nconst urgency = String(input.urgency || 'low').toLowerCase();\nconst usesCrm = Boolean(input.uses_crm);\n\nif (pain.length > 12) score += 25;\nif (volume >= 300) score += 25;\nelse if (volume >= 100) score += 15;\nelse if (volume >= 30) score += 8;\nif (urgency === 'high') score += 25;\nelse if (urgency === 'medium') score += 15;\nif (usesCrm) score += 15;\nscore = Math.max(0, Math.min(100, score));\n\nlet recommendedAction = 'nurture';\nlet reason = 'Lead ainda precisa de contexto antes do diagnostico.';\nif (score >= 75) {\n  recommendedAction = 'sales_meeting';\n  reason = 'Fit alto, dor clara, volume relevante e urgencia comercial.';\n} else if (score >= 55) {\n  recommendedAction = 'diagnostico';\n  reason = 'Fit moderado com sinais suficientes para diagnostico.';\n} else if (urgency === 'high' && pain.length > 12) {\n  recommendedAction = 'human_handoff';\n  reason = 'Urgencia alta com dor clara; vale atendimento humano rapido.';\n}\n\nconst roiSignal = score >= 75 ? 'strong' : score >= 55 ? 'moderate' : 'weak';\nconst missingFields = [];\nif (!lead.name) missingFields.push('lead.name');\nif (!lead.company) missingFields.push('lead.company');\nif (!pain) missingFields.push('input.primary_pain');\nif (!volume) missingFields.push('input.monthly_volume');\n\nreturn [{\n  json: {\n    lead: {\n      name: lead.name || '',\n      company: lead.company || '',\n      segment: lead.segment || '',\n      channel: lead.channel || 'other'\n    },\n    qualification: {\n      primary_pain: pain,\n      monthly_volume: volume,\n      urgency,\n      uses_crm: usesCrm,\n      fit_score: score,\n      roi_signal: roiSignal\n    },\n    next_step: {\n      recommended_action: recommendedAction,\n      reason,\n      missing_fields: missingFields\n    },\n    commercial_summary: `${lead.company || 'Empresa'} tem dor em ${pain || 'processo comercial'}, volume mensal de ${volume} contatos e score ${score}/100. Proximo passo recomendado: ${recommendedAction}.`,\n    canonical_links: {\n      xmacna: 'https://xmacna.ai',\n      diagnostico: 'https://xmacna.ai/diagnostico',\n      funcionario_digital: 'https://xmacna.ai/funcionario-digital',\n      sdr_com_ia: 'https://xmacna.ai/sdr-com-ia'\n    }\n  }\n}];"
      },
      "id": "a2c3c20d-7856-4c3c-9f39-842100000003",
      "name": "Score lead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [700, 300]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "recommended_action",
              "leftValue": "={{ $json.next_step.recommended_action }}",
              "rightValue": "nurture",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "a2c3c20d-7856-4c3c-9f39-842100000004",
      "name": "Needs commercial action?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [940, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "status",
              "name": "status",
              "type": "string",
              "value": "ready_for_sales"
            },
            {
              "id": "message",
              "name": "team_message",
              "type": "string",
              "value": "={{ $json.commercial_summary }}"
            }
          ]
        },
        "options": {}
      },
      "id": "a2c3c20d-7856-4c3c-9f39-842100000005",
      "name": "Prepare commercial handoff",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1190, 200]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "status",
              "name": "status",
              "type": "string",
              "value": "nurture"
            },
            {
              "id": "message",
              "name": "nurture_message",
              "type": "string",
              "value": "={{ $json.commercial_summary }}"
            }
          ]
        },
        "options": {}
      },
      "id": "a2c3c20d-7856-4c3c-9f39-842100000006",
      "name": "Prepare nurture path",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1190, 420]
    }
  ],
  "connections": {
    "Manual start": {
      "main": [
        [
          {
            "node": "Example lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Example lead": {
      "main": [
        [
          {
            "node": "Score lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score lead": {
      "main": [
        [
          {
            "node": "Needs commercial action?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Needs commercial action?": {
      "main": [
        [
          {
            "node": "Prepare commercial handoff",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare nurture path",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "name": "XMACNA"
    },
    {
      "name": "Funcionarios Digitais com IA"
    },
    {
      "name": "IA para vendas"
    }
  ],
  "triggerCount": 0,
  "updatedAt": "2026-06-01T00:00:00.000Z",
  "versionId": "xmacna-template-qualificacao-leads-v1"
}
