{
  "name": "WAIA Connect — Notificar a un CRM o planilla",
  "nodes": [
    {
      "parameters": {
        "content": "## Notificar a un CRM o planilla\n\nCuando llega un mensaje, empujás los datos a tu CRM / planilla.\n\n1. **Webhook (POST)** → *Authentication: Header Auth* (Name=`X-Connect-Token`, Value=tu `wct_…`).\n2. **Mapear** arma un objeto plano con lo que tu CRM necesita (usa `externalId` para casar al cliente final).\n3. **Enviar al CRM** es un nodo HTTP genérico: reemplazá la URL por tu endpoint (o cambialo por el nodo nativo de Google Sheets / HubSpot / Airtable).\n\n⚠ Webhook en **POST**. El sobre entero llega en `$json.body`; `body.connection.externalId` es TU id del número en tu sistema.",
        "height": 300,
        "width": 440
      },
      "id": "crm-sticky",
      "name": "Notificar a un CRM — leeme",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [-560, 120]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "waia-connect-notify-crm",
        "authentication": "headerAuth",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "crm-webhook",
      "name": "Webhook (POST)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [-40, 300],
      "webhookId": "waia-connect-notify-crm",
      "notes": "POST + Header Auth."
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            { "id": "m-event", "name": "event", "type": "string", "value": "={{ $json.body.type }}" },
            { "id": "m-number", "name": "numberExternalId", "type": "string", "value": "={{ $json.body.connection.externalId }}" },
            { "id": "m-from", "name": "from", "type": "string", "value": "={{ $json.body.data.message ? $json.body.data.message.from : '' }}" },
            { "id": "m-name", "name": "contactName", "type": "string", "value": "={{ $json.body.data.contacts ? $json.body.data.contacts[0].profile.name : '' }}" },
            { "id": "m-text", "name": "text", "type": "string", "value": "={{ $json.body.data.message && $json.body.data.message.text ? $json.body.data.message.text.body : '' }}" },
            { "id": "m-at", "name": "receivedAt", "type": "string", "value": "={{ $json.body.createdAt }}" }
          ]
        },
        "options": {}
      },
      "id": "crm-map",
      "name": "Mapear",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [260, 300],
      "notes": "Ajustá los campos a lo que pide tu CRM."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://TU-CRM.example.com/api/leads",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Content-Type", "value": "application/json" },
            { "name": "Authorization", "value": "Bearer TU_TOKEN_DEL_CRM" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}",
        "options": {}
      },
      "id": "crm-send",
      "name": "Enviar al CRM (HTTP genérico)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [560, 300],
      "notes": "Reemplazá la URL y la auth por las de tu CRM, o cambiá este nodo por Google Sheets / HubSpot / Airtable."
    }
  ],
  "connections": {
    "Webhook (POST)": { "main": [ [ { "node": "Mapear", "type": "main", "index": 0 } ] ] },
    "Mapear": { "main": [ [ { "node": "Enviar al CRM (HTTP genérico)", "type": "main", "index": 0 } ] ] }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "pinData": {},
  "meta": { "templateCredsSetupCompleted": false }
}
