{
  "name": "ALLSoft — Clasificador de correos con IA",
  "nodes": [
    {
      "parameters": {},
      "id": "a1b2c3d4-0001-4000-8000-000000000001",
      "name": "Cuando llegue un correo",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-380, 300],
      "notes": "Reemplázalo por Gmail Trigger o Webhook cuando lo conectes a tu correo real."
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "s1",
              "name": "texto",
              "value": "Buenas tardes, necesito una cotización para 200 unidades del producto A. ¿Me pueden enviar precios y tiempo de entrega?",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0002-4000-8000-000000000002",
      "name": "Correo de ejemplo",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-160, 300],
      "notes": "Datos de prueba. Al conectar tu correo real, mapea aquí el cuerpo del mensaje."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer TU_GROQ_API_KEY"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({\n  model: 'llama-3.3-70b-versatile',\n  temperature: 0,\n  messages: [\n    { role: 'system', content: 'Clasifica el correo en UNA sola palabra: cotizacion, soporte, factura u otro. Responde solo esa palabra, en minusculas, sin punto final.' },\n    { role: 'user', content: $json.texto }\n  ]\n}) }}",
        "options": {}
      },
      "id": "a1b2c3d4-0003-4000-8000-000000000003",
      "name": "Clasificar con IA (Groq)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [80, 300],
      "notes": "Cambia TU_GROQ_API_KEY por tu key de console.groq.com. Es gratis."
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c1",
              "name": "categoria",
              "value": "={{ $json.choices[0].message.content.trim().toLowerCase() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0004-4000-8000-000000000004",
      "name": "Extraer categoría",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [300, 300]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": { "caseSensitive": false, "version": 2 },
                "conditions": [
                  {
                    "leftValue": "={{ $json.categoria }}",
                    "rightValue": "cotizacion",
                    "operator": { "type": "string", "operation": "equals" }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Cotización"
            },
            {
              "conditions": {
                "options": { "caseSensitive": false, "version": 2 },
                "conditions": [
                  {
                    "leftValue": "={{ $json.categoria }}",
                    "rightValue": "soporte",
                    "operator": { "type": "string", "operation": "equals" }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Soporte"
            },
            {
              "conditions": {
                "options": { "caseSensitive": false, "version": 2 },
                "conditions": [
                  {
                    "leftValue": "={{ $json.categoria }}",
                    "rightValue": "factura",
                    "operator": { "type": "string", "operation": "equals" }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Factura"
            }
          ]
        },
        "options": { "fallbackOutput": "extra", "renameFallbackOutput": "Otro" }
      },
      "id": "a1b2c3d4-0005-4000-8000-000000000005",
      "name": "Enrutar según categoría",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [520, 300],
      "notes": "Conecta cada salida a lo que corresponda: Sheets, Slack, tu CRM, etc."
    }
  ],
  "connections": {
    "Cuando llegue un correo": {
      "main": [[{ "node": "Correo de ejemplo", "type": "main", "index": 0 }]]
    },
    "Correo de ejemplo": {
      "main": [[{ "node": "Clasificar con IA (Groq)", "type": "main", "index": 0 }]]
    },
    "Clasificar con IA (Groq)": {
      "main": [[{ "node": "Extraer categoría", "type": "main", "index": 0 }]]
    },
    "Extraer categoría": {
      "main": [[{ "node": "Enrutar según categoría", "type": "main", "index": 0 }]]
    }
  },
  "settings": { "executionOrder": "v1" },
  "pinData": {},
  "meta": {
    "instanceId": "allsoft-academia"
  },
  "tags": []
}
