{
  "name": "Newsletter Semanal con Contenido Curado por IA",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [5],
              "triggerAtHour": 10
            }
          ]
        }
      },
      "id": "e7f8a9b0-0017-4a01-b001-ef1234567001",
      "name": "Schedule Trigger - Viernes 10AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [250, 300]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.rss2json.com/v1/api.json?rss_url=FEED_URL_1",
        "options": {}
      },
      "id": "e7f8a9b0-0017-4a02-b002-ef1234567002",
      "name": "HTTP Request - Feed Noticias 1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [500, 150]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.rss2json.com/v1/api.json?rss_url=FEED_URL_2",
        "options": {}
      },
      "id": "e7f8a9b0-0017-4a03-b003-ef1234567003",
      "name": "HTTP Request - Feed Noticias 2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [500, 350]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.rss2json.com/v1/api.json?rss_url=FEED_SRI",
        "options": {}
      },
      "id": "e7f8a9b0-0017-4a04-b004-ef1234567004",
      "name": "HTTP Request - Feed SRI",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [500, 550]
    },
    {
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": "gpt-3.5-turbo",
        "messages": {
          "values": [
            {
              "content": "=Eres un editor de newsletter para emprendedores ecuatorianos. A continuación tienes varias noticias y artículos. Para cada uno, genera:\n1. Un resumen de 2-3 oraciones\n2. Un comentario editorial breve y relevante para emprendedores de Ecuador\n3. Un consejo de la semana para emprendedores\n\nNoticias:\n{{ JSON.stringify(items.map(i => ({ titulo: i.json.title, contenido: i.json.description })).slice(0, 5)) }}\n\nFormato de salida: HTML con estilos inline para email."
            }
          ]
        },
        "options": {
          "temperature": 0.7,
          "maxTokens": 1500
        }
      },
      "id": "e7f8a9b0-0017-4a05-b005-ef1234567005",
      "name": "OpenAI - Curar y Resumir",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [750, 350],
      "credentials": {
        "openAiApi": {
          "id": "",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "newsletterHtml",
              "value": "=<div style='font-family:Arial,sans-serif;max-width:600px;margin:0 auto;'><div style='background:linear-gradient(135deg,#1a73e8,#0d47a1);color:white;padding:30px;text-align:center;border-radius:8px 8px 0 0;'><h1 style='margin:0;'>📰 Newsletter Semanal</h1><p style='margin:8px 0 0;opacity:0.9;'>Noticias y consejos para emprendedores ecuatorianos</p><p style='margin:4px 0 0;font-size:12px;opacity:0.7;'>{{ $now.format('dd MMMM yyyy') }}</p></div><div style='padding:20px;background:#ffffff;'>{{ $json.message.content }}</div><div style='background:#f8f9fa;padding:20px;text-align:center;border-radius:0 0 8px 8px;'><p style='color:#666;font-size:12px;'>Recibiste este correo porque te suscribiste a nuestro newsletter.</p><a href='ENLACE_BAJA' style='color:#999;font-size:12px;'>Cancelar suscripción</a></div></div>"
            }
          ]
        },
        "options": {}
      },
      "id": "e7f8a9b0-0017-4a06-b006-ef1234567006",
      "name": "Set - Construir Newsletter HTML",
      "type": "n8n-nodes-base.set",
      "typeVersion": 2,
      "position": [1000, 350]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "byName",
          "value": "Suscriptores"
        },
        "filters": {
          "column": "estado",
          "value": "Activo"
        },
        "options": {}
      },
      "id": "e7f8a9b0-0017-4a07-b007-ef1234567007",
      "name": "Google Sheets - Lista Suscriptores",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [1250, 350],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "={{ $json.correo }}",
        "subject": "=📰 Tu newsletter semanal, {{ $json.nombre }} — Lo más relevante para emprendedores",
        "emailType": "html",
        "message": "={{ $json.newsletterHtml }}",
        "options": {}
      },
      "id": "e7f8a9b0-0017-4a08-b008-ef1234567008",
      "name": "Gmail - Enviar Newsletter",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2,
      "position": [1500, 350],
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "Gmail account"
        }
      }
    }
  ],
  "connections": {
    "Schedule Trigger - Viernes 10AM": {
      "main": [
        [
          {
            "node": "HTTP Request - Feed Noticias 1",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP Request - Feed Noticias 2",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP Request - Feed SRI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request - Feed Noticias 1": {
      "main": [
        [
          {
            "node": "OpenAI - Curar y Resumir",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request - Feed Noticias 2": {
      "main": [
        [
          {
            "node": "OpenAI - Curar y Resumir",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request - Feed SRI": {
      "main": [
        [
          {
            "node": "OpenAI - Curar y Resumir",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Curar y Resumir": {
      "main": [
        [
          {
            "node": "Set - Construir Newsletter HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set - Construir Newsletter HTML": {
      "main": [
        [
          {
            "node": "Google Sheets - Lista Suscriptores",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Lista Suscriptores": {
      "main": [
        [
          {
            "node": "Gmail - Enviar Newsletter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "name": "email-marketing"
    },
    {
      "name": "newsletter"
    },
    {
      "name": "ia"
    }
  ]
}
