{
  "name": "XMACNA - Follow-up automatico com IA",
  "nodes": [
    {
      "parameters": {},
      "id": "c7c6b4f3-5e10-4b21-b010-842100000011",
      "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_channel",
              "name": "lead.channel",
              "type": "string",
              "value": "whatsapp"
            },
            {
              "id": "stage",
              "name": "cadence.stage",
              "type": "string",
              "value": "D3"
            },
            {
              "id": "days",
              "name": "cadence.days_since_last_response",
              "type": "number",
              "value": 3
            },
            {
              "id": "interest",
              "name": "cadence.interest",
              "type": "string",
              "value": "medium"
            },
            {
              "id": "urgency",
              "name": "cadence.urgency",
              "type": "string",
              "value": "high"
            },
            {
              "id": "pain",
              "name": "cadence.primary_pain",
              "type": "string",
              "value": "lead demonstrou interesse mas ainda nao agendou diagnostico"
            },
            {
              "id": "stop",
              "name": "cadence.asked_to_stop",
              "type": "boolean",
              "value": false
            }
          ]
        },
        "options": {}
      },
      "id": "c7c6b4f3-5e10-4b21-b010-842100000012",
      "name": "Example follow-up state",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [470, 300]
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first().json;\nconst lead = item.lead || {};\nconst cadence = item.cadence || {};\nconst stage = String(cadence.stage || 'D0').toUpperCase();\nconst days = Number(cadence.days_since_last_response || 0);\nconst interest = String(cadence.interest || 'low').toLowerCase();\nconst urgency = String(cadence.urgency || 'low').toLowerCase();\nconst pain = String(cadence.primary_pain || '').trim();\nconst askedToStop = Boolean(cadence.asked_to_stop);\nconst riskFlags = [];\n\nlet recommendedAction = 'send_value_follow_up';\nlet nextStage = 'D1';\nlet reason = 'Lead ainda pode receber um follow-up util e contextual.';\n\nif (askedToStop) {\n  recommendedAction = 'pause';\n  nextStage = 'pause';\n  reason = 'Lead pediu pausa ou encerramento. Nao insistir.';\n  riskFlags.push('stop_requested');\n} else if (interest === 'high' || urgency === 'high') {\n  recommendedAction = 'human_handoff';\n  nextStage = stage;\n  reason = 'Interesse ou urgencia alta justificam contato humano rapido.';\n} else if (stage === 'D0') {\n  recommendedAction = 'reply_now';\n  nextStage = 'D1';\n  reason = 'Primeira resposta deve ser rapida e objetiva.';\n} else if (stage === 'D1') {\n  recommendedAction = 'send_value_follow_up';\n  nextStage = 'D3';\n  reason = 'Enviar lembrete util com contexto da dor.';\n} else if (stage === 'D3') {\n  recommendedAction = 'send_value_follow_up';\n  nextStage = 'D7';\n  reason = 'Ajudar o lead a decidir com criterio pratico.';\n} else if (stage === 'D7' || days >= 7) {\n  recommendedAction = 'close_cycle';\n  nextStage = 'closed';\n  reason = 'Encerrar o ciclo sem insistencia e manter porta aberta.';\n}\n\nif (days > 14) riskFlags.push('old_contact');\nif (!pain) riskFlags.push('missing_pain');\n\nreturn [{\n  json: {\n    lead: {\n      name: lead.name || '',\n      company: lead.company || '',\n      channel: lead.channel || 'other'\n    },\n    cadence: {\n      stage,\n      days_since_last_response: days,\n      interest,\n      urgency,\n      primary_pain: pain,\n      asked_to_stop: askedToStop\n    },\n    decision: {\n      recommended_action: recommendedAction,\n      reason,\n      next_stage: nextStage,\n      risk_flags: riskFlags\n    },\n    commercial_summary: `${lead.company || 'Empresa'} esta no estagio ${stage}, com interesse ${interest}, urgencia ${urgency} e ${days} dias desde a ultima resposta. Acao recomendada: ${recommendedAction}.`,\n    canonical_links: {\n      xmacna: 'https://xmacna.ai',\n      follow_up: 'https://xmacna.ai/follow-up-automatico-com-ia',\n      sdr_com_ia: 'https://xmacna.ai/sdr-com-ia'\n    }\n  }\n}];"
      },
      "id": "c7c6b4f3-5e10-4b21-b010-842100000013",
      "name": "Decide follow-up",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [720, 300]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "needs_human",
              "leftValue": "={{ $json.decision.recommended_action }}",
              "rightValue": "human_handoff",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c7c6b4f3-5e10-4b21-b010-842100000014",
      "name": "Needs human?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [970, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "status",
              "name": "status",
              "type": "string",
              "value": "human_review"
            },
            {
              "id": "summary",
              "name": "team_summary",
              "type": "string",
              "value": "={{ $json.commercial_summary }}"
            }
          ]
        },
        "options": {}
      },
      "id": "c7c6b4f3-5e10-4b21-b010-842100000015",
      "name": "Prepare human review",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1220, 200]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "status",
              "name": "status",
              "type": "string",
              "value": "cadence_decided"
            },
            {
              "id": "summary",
              "name": "cadence_summary",
              "type": "string",
              "value": "={{ $json.commercial_summary }}"
            }
          ]
        },
        "options": {}
      },
      "id": "c7c6b4f3-5e10-4b21-b010-842100000016",
      "name": "Prepare cadence decision",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1220, 420]
    }
  ],
  "connections": {
    "Manual start": {
      "main": [
        [
          {
            "node": "Example follow-up state",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Example follow-up state": {
      "main": [
        [
          {
            "node": "Decide follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decide follow-up": {
      "main": [
        [
          {
            "node": "Needs human?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Needs human?": {
      "main": [
        [
          {
            "node": "Prepare human review",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare cadence decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "name": "XMACNA"
    },
    {
      "name": "Funcionarios Digitais com IA"
    },
    {
      "name": "follow-up automatico com IA"
    }
  ],
  "triggerCount": 0,
  "updatedAt": "2026-06-01T00:00:00.000Z",
  "versionId": "xmacna-template-follow-up-v1"
}
