{
  "name": "KALELE_DERIVAR_ENCARGADA",
  "nodes": [
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        0,
        0
      ],
      "id": "trg-der-001",
      "name": "When Executed by Another Workflow"
    },
    {
      "parameters": {
        "jsCode": "// Normaliza la entrada: subscriber_id puede venir como n\u00famero o string,\n// si no viene lo dejamos en 0 (solo para que el JSON sea v\u00e1lido en pruebas).\nconst trg = $input.first().json || {};\nreturn [{\n  json: {\n    subscriber_id: trg.subscriber_id ? String(trg.subscriber_id) : '0',\n    motivo: trg.motivo || 'derivaci\u00f3n general',\n    resumen: trg.resumen || 'sin resumen'\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ],
      "id": "code-norm-001",
      "name": "Normalizar input"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/subscriber/addTag",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "keypair",
        "bodyParameters": {
          "parameters": [
            {
              "name": "subscriber_id",
              "value": "={{ Number($json.subscriber_id) }}"
            },
            {
              "name": "tag_name",
              "value": "ATENCION_HUMANA"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          },
          "timeout": 15000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        0
      ],
      "id": "http-der-001",
      "name": "Etiquetar en ManyChat",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "der-out-1",
              "name": "respuesta",
              "value": "Clienta derivada a encargada. Tag ATENCION_HUMANA aplicado en ManyChat. Revisar inbox para atender personalmente.",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        700,
        0
      ],
      "id": "set-der-001",
      "name": "Edit Fields"
    }
  ],
  "connections": {
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Normalizar input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalizar input": {
      "main": [
        [
          {
            "node": "Etiquetar en ManyChat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Etiquetar en ManyChat": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}