{
  "name": "Frame System \u2014 04 Follow-up e Retorno",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "frame-followup",
        "responseMode": "immediately",
        "responseCode": 200,
        "options": {}
      },
      "id": "trigger-followup",
      "name": "Recebe Follow-up ou Retorno",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "mode": "rules",
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "leftValue": "={{ $json.event }}",
                    "rightValue": "followup_due",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "Follow-up"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "leftValue": "={{ $json.event }}",
                    "rightValue": "retorno_due",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "Retorno"
            }
          ]
        }
      },
      "id": "switch-event",
      "name": "Tipo de evento",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Recebe Follow-up ou Retorno').item.json.evolution_api_url }}/message/sendText/{{ $('Recebe Follow-up ou Retorno').item.json.instance_name }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Recebe Follow-up ou Retorno').item.json.evolution_api_key }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $('Recebe Follow-up ou Retorno').item.json.client_phone }}"
            },
            {
              "name": "text",
              "value": "={{ $('Recebe Follow-up ou Retorno').item.json.message }}"
            }
          ]
        },
        "options": {}
      },
      "id": "send-followup",
      "name": "Envia follow-up",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        180
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Recebe Follow-up ou Retorno').item.json.evolution_api_url }}/message/sendText/{{ $('Recebe Follow-up ou Retorno').item.json.instance_name }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $('Recebe Follow-up ou Retorno').item.json.evolution_api_key }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $('Recebe Follow-up ou Retorno').item.json.client_phone }}"
            },
            {
              "name": "text",
              "value": "={{ $('Recebe Follow-up ou Retorno').item.json.message }}"
            }
          ]
        },
        "options": {}
      },
      "id": "send-retorno",
      "name": "Envia mensagem de retorno",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        420
      ]
    }
  ],
  "connections": {
    "Recebe Follow-up ou Retorno": {
      "main": [
        [
          {
            "node": "Tipo de evento",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tipo de evento": {
      "main": [
        [
          {
            "node": "Envia follow-up",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Envia mensagem de retorno",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateId": "frame-system-followup-v2",
    "description": "Recebe followup_due (etapa de follow-up sem resposta) e retorno_due (paciente sem agendamento ap\u00f3s X dias). Em ambos os casos a mensagem j\u00e1 vem pronta no campo 'message'. Payload flat na raiz do JSON."
  }
}