{
  "name": "Pipeline de Ventas Automatizado en Google Sheets",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 1
            }
          ]
        }
      },
      "id": "d4e5f6a7-0004-4a01-b001-ef1234567001",
      "name": "Schedule Trigger - Cada Hora",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [250, 300]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "byName",
          "value": "Pipeline"
        },
        "options": {
          "range": "A:J"
        }
      },
      "id": "d4e5f6a7-0004-4a02-b002-ef1234567002",
      "name": "Google Sheets - Leer Pipeline",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [500, 300],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const now = new Date();\nconst results = [];\n\nfor (const item of items) {\n  const lastActivity = new Date(item.json.ultima_actividad);\n  const daysSinceActivity = Math.floor((now - lastActivity) / (1000 * 60 * 60 * 24));\n  \n  if (daysSinceActivity >= 3) {\n    results.push({\n      json: {\n        ...item.json,\n        daysSinceActivity,\n        needsFollowUp: true\n      }\n    });\n  }\n}\n\nreturn results;"
      },
      "id": "d4e5f6a7-0004-4a03-b003-ef1234567003",
      "name": "Function - Filtrar Inactivos 3+ Días",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [750, 300]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.etapa }}",
              "operation": "equal",
              "value2": "Cotización enviada"
            }
          ]
        }
      },
      "id": "d4e5f6a7-0004-4a04-b004-ef1234567004",
      "name": "IF - Cotización Enviada",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [1000, 300]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.vendedor_email }}",
        "subject": "=⚠️ Seguimiento Pendiente: {{ $json.prospecto }} ({{ $json.daysSinceActivity }} días sin actividad)",
        "emailType": "html",
        "message": "=<h2>Recordatorio de Seguimiento</h2><p>El prospecto <strong>{{ $json.prospecto }}</strong> lleva <strong>{{ $json.daysSinceActivity }} días</strong> sin actividad.</p><p><strong>Etapa:</strong> {{ $json.etapa }}</p><p><strong>Valor del deal:</strong> ${{ $json.valor }}</p><p><strong>Último contacto:</strong> {{ $json.ultima_actividad }}</p><p>Por favor, realiza el seguimiento correspondiente hoy.</p>",
        "options": {}
      },
      "id": "d4e5f6a7-0004-4a05-b005-ef1234567005",
      "name": "Gmail - Recordatorio Vendedor",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2,
      "position": [1250, 200],
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "chatId": "",
        "text": "=📋 *Deals Pendientes del Día*\n\nProspecto: {{ $json.prospecto }}\nEtapa: {{ $json.etapa }}\nValor: ${{ $json.valor }}\nDías sin actividad: {{ $json.daysSinceActivity }}\nVendedor: {{ $json.vendedor }}\n\n⏰ Requiere seguimiento inmediato",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "id": "d4e5f6a7-0004-4a06-b006-ef1234567006",
      "name": "Telegram - Alerta Grupo Ventas",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [1250, 400],
      "credentials": {
        "telegramApi": {
          "id": "",
          "name": "Telegram account"
        }
      }
    }
  ],
  "connections": {
    "Schedule Trigger - Cada Hora": {
      "main": [
        [
          {
            "node": "Google Sheets - Leer Pipeline",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Leer Pipeline": {
      "main": [
        [
          {
            "node": "Function - Filtrar Inactivos 3+ Días",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function - Filtrar Inactivos 3+ Días": {
      "main": [
        [
          {
            "node": "IF - Cotización Enviada",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF - Cotización Enviada": {
      "main": [
        [
          {
            "node": "Gmail - Recordatorio Vendedor",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram - Alerta Grupo Ventas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "name": "sales"
    },
    {
      "name": "pipeline"
    },
    {
      "name": "crm"
    }
  ]
}
