{
  "name": "Logixb2b — Coach IA para closers",
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Webhook call-notes → LLM (objeciones, script, nextStep) → nota CRM + Slack. Revisión humana. Complemento práctico a drills/roleplay de la guía. Incluye Asistente IA (OpenAI) configurable."
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Madrid"
  },
  "active": false,
  "pinData": {},
  "tags": [
    {
      "name": "Logixb2b"
    },
    {
      "name": "recursos"
    },
    {
      "name": "ia"
    },
    {
      "name": "coaching"
    }
  ],
  "nodes": [
    {
      "id": "sticky-instrucciones-logix",
      "name": "INSTRUCCIONES (conectar + VPS)",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        40
      ],
      "parameters": {
        "content": "## INSTRUCCIONES — Coach IA para closers\n\n**Recurso:** `/recursos/closer-ia-coaching`\n**Guía:** /entrenar-equipo-closers-ia-generativa\n**Zona:** Europe/Madrid · `active: false` al importar (tú lo activas).\n\n### 1) Importar\n1. n8n → ⋯ → **Import from File** → este JSON.\n2. El flujo llega **inactive**. No pegues secretos en el lienzo ni en el archivo.\n\n### 2) Credenciales y configuración por nodo\n- **Webhook call-notes** (`webhook`): sin credencial. Tras Active, copia **URL de producción** (HTTPS del VPS/Cloud). El emisor (formulario, CRM, bot) debe POST a esa URL.\n- **Config coaching** (`Set` Config): **no lleva credencial**. Aquí van URLs/placeholders (`REEMPLAZA_*`, `example.com`, `TU-CRM`). Sustituye todos antes de Active.\n- **Notas de llamada** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\n- **Parsear coaching** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\n- **POST nota CRM coaching** (`HTTP Request` CRM): Credentials → **Header Auth** / OAuth del CRM. Sustituye `crm*Url` en el nodo **Config**. Prueba con un Lead de sandbox.\n- **Slack tip al closer** (`HTTP Request` → Slack/Teams): crea Incoming Webhook en Slack (o Adaptive Card URL en Teams). Pega la URL en **Config** o en este nodo. Auth: none (la URL ya es secreta).\n- **Preparar prompt IA** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\n- **Asistente IA** (`AI Agent`): no lleva API key propia; debe estar cableado al nodo **Modelo OpenAI**. Revisa el prompt del sistema y que la salida pase por revisión humana (HITL) antes de escribir al CRM.\n- **Modelo OpenAI** (`OpenAI / LLM`): Credentials → **OpenAI API** (o compatible: base URL + API key). Nunca pegues la key en el JSON. El Asistente IA depende de este nodo.\n- **Aplicar salida IA** (`Set`): sin credencial. Revisa expresiones `={{ }}` y campos de salida.\n\n### 3) Orden recomendado de puesta en marcha\n1. Rellena el nodo **Config** (URLs reales, umbrales, webhooks de Slack).\n2. Crea Credentials en n8n (candado de cada nodo HTTP / Sheets / OpenAI) y **enlázalas**.\n3. Ejecuta **una vez** (Manual / Test URL del Webhook / \"Execute workflow\").\n4. Verifica CRM + Slack/Sheets (y que la IA no escriba en producción sin HITL).\n5. Solo entonces: interruptor **Active**.\n\n### 4) Producción 24/7 en VPS (UE)\nImportar en localhost no basta: webhooks y cron necesitan n8n encendido.\n\n1. VPS en UE (Hetzner/OVH/IONOS…) + Docker Compose + **Postgres** + HTTPS (Caddy/Nginx).\n2. Variables mínimas: `GENERIC_TIMEZONE=Europe/Madrid`, `WEBHOOK_URL=https://n8n.tudominio.com/`, `N8N_ENCRYPTION_KEY`, `N8N_HOST` / `N8N_PROTOCOL=https`.\n3. Firewall: solo 80/443 (+ SSH). Backups del volumen Postgres + export de workflows.\n4. Importa este JSON en la instancia de producción, vuelve a crear Credentials (no se copian solas), actualiza URLs del Config al dominio real.\n5. Pon **Active**. Prueba el Webhook de producción o espera el próximo cron.\n6. Alternativa: **n8n Cloud** (mismo JSON; Credentials en la UI Cloud).\n\n### 5) RGPD + EU AI Act (resumen)\nSi hay nodos IA sois **deployers** (Reglamento UE 2024/1689). Art. 4 alfabetización. **HITL** antes de outreach, scores masivos o pausas de cuenta. Minimiza PII en Slack/logs. Informativo — no es asesoramiento legal. /uso-responsable-de-ia-y-transparencia\n",
        "height": 1500,
        "width": 580,
        "color": 4
      }
    },
    {
      "id": "trigger-webhook",
      "name": "Webhook call-notes",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "call-notes",
      "parameters": {
        "httpMethod": "POST",
        "path": "call-notes",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "id": "set-config",
      "name": "Config coaching",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        300,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "c1",
              "name": "llmUrl",
              "value": "https://api.openai.com/v1/chat/completions",
              "type": "string"
            },
            {
              "id": "c2",
              "name": "apiKey",
              "value": "sustituye-con-tu-clave-del-modelo-ia",
              "type": "string"
            },
            {
              "id": "c3",
              "name": "model",
              "value": "gpt-4o-mini",
              "type": "string"
            },
            {
              "id": "c4",
              "name": "crmNoteUrl",
              "value": "https://TU-CRM.ejemplo/api/notes",
              "type": "string"
            },
            {
              "id": "c5",
              "name": "slackWebhookUrl",
              "value": "https://example.com/aviso-equipo-slack",
              "type": "string"
            },
            {
              "id": "c6",
              "name": "rawBody",
              "value": "={{ $json.body || $json }}",
              "type": "object"
            }
          ]
        }
      }
    },
    {
      "id": "set-notes",
      "name": "Notas de llamada",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        600,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "n1",
              "name": "dealName",
              "value": "={{ String($json.rawBody.dealName || $json.rawBody.deal || 'Lead sin nombre').trim() }}",
              "type": "string"
            },
            {
              "id": "n2",
              "name": "closer",
              "value": "={{ String($json.rawBody.closer || $json.rawBody.owner || 'Closer').trim() }}",
              "type": "string"
            },
            {
              "id": "n3",
              "name": "callNotes",
              "value": "={{ String($json.rawBody.callNotes || $json.rawBody.notes || '').trim() }}",
              "type": "string"
            },
            {
              "id": "n3b",
              "name": "dealId",
              "value": "={{ String($json.rawBody.dealId || $json.rawBody.deal_id || '').trim() }}",
              "type": "string"
            },
            {
              "id": "n3c",
              "name": "contactId",
              "value": "={{ String($json.rawBody.contactId || $json.rawBody.contact_id || '').trim() }}",
              "type": "string"
            },
            {
              "id": "n4",
              "name": "llmUrl",
              "value": "={{ $json.llmUrl }}",
              "type": "string"
            },
            {
              "id": "n5",
              "name": "apiKey",
              "value": "={{ $json.apiKey }}",
              "type": "string"
            },
            {
              "id": "n6",
              "name": "model",
              "value": "={{ $json.model }}",
              "type": "string"
            },
            {
              "id": "n7",
              "name": "crmNoteUrl",
              "value": "={{ $json.crmNoteUrl }}",
              "type": "string"
            },
            {
              "id": "n8",
              "name": "slackWebhookUrl",
              "value": "={{ $json.slackWebhookUrl }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "set-parse",
      "name": "Parsear coaching",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1800,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "p1",
              "name": "objeciones",
              "value": "={{ (() => { try { return (JSON.parse($json.aiOutput).objeciones || []).join(' | '); } catch(e) { return ''; } })() }}",
              "type": "string"
            },
            {
              "id": "p2",
              "name": "script",
              "value": "={{ (() => { try { return JSON.parse($json.aiOutput).script; } catch(e) { return ''; } })() }}",
              "type": "string"
            },
            {
              "id": "p3",
              "name": "nextStep",
              "value": "={{ (() => { try { return JSON.parse($json.aiOutput).nextStep; } catch(e) { return ''; } })() }}",
              "type": "string"
            },
            {
              "id": "p4",
              "name": "dealName",
              "value": "={{ $('Notas de llamada').item.json.dealName }}",
              "type": "string"
            },
            {
              "id": "p5",
              "name": "closer",
              "value": "={{ $('Notas de llamada').item.json.closer }}",
              "type": "string"
            },
            {
              "id": "p5b",
              "name": "dealId",
              "value": "={{ $('Notas de llamada').item.json.dealId }}",
              "type": "string"
            },
            {
              "id": "p5c",
              "name": "contactId",
              "value": "={{ $('Notas de llamada').item.json.contactId }}",
              "type": "string"
            },
            {
              "id": "p6",
              "name": "crmNoteUrl",
              "value": "={{ $('Notas de llamada').item.json.crmNoteUrl }}",
              "type": "string"
            },
            {
              "id": "p7",
              "name": "slackWebhookUrl",
              "value": "={{ $('Notas de llamada').item.json.slackWebhookUrl }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "http-crm",
      "name": "POST nota CRM coaching",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2100,
        40
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $json.crmNoteUrl }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ type: 'closer_coaching', dealName: $json.dealName, dealId: $json.dealId || undefined, contactId: $json.contactId || undefined, needs_human_review: true, body: 'Objeciones: ' + $json.objeciones + '\\nScript: ' + $json.script + '\\nNext step: ' + $json.nextStep }) }}",
        "options": {
          "timeout": 30000
        }
      }
    },
    {
      "id": "http-slack",
      "name": "Slack tip al closer",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2100,
        560
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $('Parsear coaching').item.json.slackWebhookUrl }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: ':microphone: *Coach IA* — ' + $('Parsear coaching').item.json.dealName + ' (' + $('Parsear coaching').item.json.closer + ')\\n*Objeciones:* ' + $('Parsear coaching').item.json.objeciones + '\\n*Script:* ' + $('Parsear coaching').item.json.script + '\\n*Next:* ' + $('Parsear coaching').item.json.nextStep + '\\n_Revisar antes de usarlo con el cliente._' }) }}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "ai-prep-closer-ia-co",
      "name": "Preparar prompt IA",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "includeOtherFields": true,
        "assignments": {
          "assignments": [
            {
              "id": "p1",
              "name": "aiPrompt",
              "value": "={{ \"Eres coach de closers. Con las notas de llamada, responde JSON {objections, script, nextStep} en español.\\n\\nNotas:\\n\" + JSON.stringify($json) + \"\" }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "ai-agent-closer-ia-co",
      "name": "Asistente IA",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        1200,
        300
      ],
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.aiPrompt }}",
        "options": {}
      }
    },
    {
      "id": "ai-model-closer-ia-co",
      "name": "Modelo OpenAI",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        1200,
        580
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      }
    },
    {
      "id": "ai-apply-closer-ia-co",
      "name": "Aplicar salida IA",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1500,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "includeOtherFields": true,
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "aiOutput",
              "value": "={{ $json.output || $json.text || $json.message || JSON.stringify($json) }}",
              "type": "string"
            },
            {
              "id": "a2",
              "name": "slackText",
              "value": "={{ ($json.output || $json.text || '').toString() || 'Revisa el resultado del Asistente IA.' }}",
              "type": "string"
            }
          ]
        }
      }
    }
  ],
  "connections": {
    "Webhook call-notes": {
      "main": [
        [
          {
            "node": "Config coaching",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config coaching": {
      "main": [
        [
          {
            "node": "Notas de llamada",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notas de llamada": {
      "main": [
        [
          {
            "node": "Preparar prompt IA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parsear coaching": {
      "main": [
        [
          {
            "node": "POST nota CRM coaching",
            "type": "main",
            "index": 0
          },
          {
            "node": "Slack tip al closer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Preparar prompt IA": {
      "main": [
        [
          {
            "node": "Asistente IA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Asistente IA": {
      "main": [
        [
          {
            "node": "Aplicar salida IA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Modelo OpenAI": {
      "ai_languageModel": [
        [
          {
            "node": "Asistente IA",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Aplicar salida IA": {
      "main": [
        [
          {
            "node": "Parsear coaching",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
