{
  "name": "scraping_flow_cabichui",
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1d426a44-0683-40cd-98a2-8cf60f0f1b3f",
              "name": "search",
              "value": "={{ $json.search }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1712,
        -912
      ],
      "id": "5eb67aef-b1ad-4f44-8390-d755c9503b0c",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "url": "https://www.ultimahora.com/nacionales",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2336,
        -912
      ],
      "id": "5b0eb4cf-6fb5-470b-9109-856e92a1a200",
      "name": "HTTP Ultima Hora"
    },
    {
      "parameters": {
        "content": "# Actualidad",
        "height": 992,
        "width": 2832
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2688,
        -1184
      ],
      "typeVersion": 1,
      "id": "9d771352-d8f5-4efe-9a42-f86e4b060dad",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1d426a44-0683-40cd-98a2-8cf60f0f1b3f",
              "name": "search",
              "value": "={{ $json.search }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1712,
        -720
      ],
      "id": "97d306c6-067e-4a62-a44d-59e51bbfe0e2",
      "name": "Edit Fields15"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-5-mini",
          "mode": "list",
          "cachedResultName": "gpt-5-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -1248,
        -544
      ],
      "id": "4a21f040-8d9c-413f-85da-1ff39e54cdf9",
      "name": "OpenAI Chat Model6",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1d426a44-0683-40cd-98a2-8cf60f0f1b3f",
              "name": "search",
              "value": "={{ $json.search }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1712,
        -528
      ],
      "id": "80c7bc1c-700e-456c-89f3-b1f4ac5f18ec",
      "name": "Edit Fields17"
    },
    {
      "parameters": {
        "url": "https://www.abc.com.py/nacionales/",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2336,
        -528
      ],
      "id": "6360447b-4efd-4244-876c-52fc4de632ea",
      "name": "HTTP ABC"
    },
    {
      "parameters": {
        "url": "https://www.lanacion.com.py/category/pais/",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2336,
        -720
      ],
      "id": "9aa0a596-3621-4313-8bfd-590d8f3be612",
      "name": "HTTP LA NACI\u00d3N"
    },
    {
      "parameters": {
        "numberInputs": 3
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        -1456,
        -736
      ],
      "id": "66381d30-c877-47e6-b575-b2f67dc56f32",
      "name": "Merge"
    },
    {
      "parameters": {
        "jsCode": "// --- CONFIGURACI\u00d3N ---\nconst ID_CATEGORIA = 1; // Ajusta seg\u00fan corresponda (ej: 3 para far\u00e1ndula)\nconst NOTA_DEFAULT = null;\nconst BASE_URL_ABC = \"https://www.abc.com.py\";\n\n// --- FUNCIONES ---\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  return str\n    .replace(/\\uFFFD/g, \"\u00f1\")\n    .replace(/\u00c3\u00a1/g, \"\u00e1\")\n    .replace(/\u00c3\u00a9/g, \"\u00e9\")\n    .replace(/\u00c3\u00ad/g, \"\u00ed\")\n    .replace(/\u00c3\u00b3/g, \"\u00f3\")\n    .replace(/\u00c3\u00ba/g, \"\u00fa\")\n    .replace(/\u00c3\u00b1/g, \"\u00f1\")\n    .replace(/\\s+/g, \" \")\n    .trim();\n}\n\n// Lista temporal para guardar todo\nconst listaParaEnviar = [];\n\n// Recorremos todos los diarios\nfor (const item of $input.all()) {\n  let output = item.json.output;\n\n  if (typeof output === 'string') {\n    try {\n      const cleanJson = output.replace(/```json/g, \"\").replace(/```/g, \"\").trim();\n      output = JSON.parse(cleanJson);\n    } catch (e) {\n      output = [];\n    }\n  }\n\n  if (Array.isArray(output)) {\n    for (const news of output) {\n      let finalLink = news.link || \"\";\n      if (finalLink.startsWith(\"/\")) {\n        finalLink = BASE_URL_ABC + finalLink;\n      }\n\n      // Agregamos a la lista temporal\n      listaParaEnviar.push({\n        medio: news.medio || \"Desconocido\",\n        titulo: fixEncoding(news.title),\n        link: finalLink,\n        id_categoria: ID_CATEGORIA,\n        nota: \"No\"\n      });\n    }\n  }\n}\n\n// IMPORTANTE: Devolvemos UN solo \u00edtem que contiene la lista completa\nreturn [\n  {\n    json: {\n      paquete_noticias: listaParaEnviar\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -704,
        -720
      ],
      "id": "6230b16a-6858-4622-97ae-f4b155d7db54",
      "name": "Limpieza_caracteres",
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "3a7a9669-4922-4c4e-8109-5640fe4888ce",
              "name": "output",
              "value": "={{ $json.output }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -896,
        -720
      ],
      "id": "ad9e21ea-29db-4489-a495-31bc6e2a904f",
      "name": "Normalizar_noticias"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": ".PageList-items-item .PagePromo-content .PagePromo-title a",
              "returnArray": true
            },
            {
              "key": "link",
              "cssSelector": ".PageList-items-item .PagePromo-content .PagePromo-title a",
              "returnValue": "attribute",
              "attribute": "href",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        -2128,
        -912
      ],
      "id": "465546d1-ea2e-4329-814d-8082667147c9",
      "name": "HTML Recuperar_noticias_ULTIMA_HORA"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": ".clnc.ws-ln .tc > a",
              "returnArray": true
            },
            {
              "key": "link",
              "cssSelector": "div.cln.ccp div.tc > a[href^=\"/pais/\"]",
              "returnValue": "attribute",
              "attribute": "href",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        -2128,
        -720
      ],
      "id": "a17fff28-d284-4c87-89b9-076eac2dc07b",
      "name": "HTML Recuperar_noticias_LA_NACION"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": ".article-title span",
              "returnArray": true
            },
            {
              "key": "link",
              "cssSelector": ".article-info > a",
              "returnValue": "attribute",
              "attribute": "href",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        -2128,
        -528
      ],
      "id": "9be6b3a1-359c-4641-a156-bb9291f2e23b",
      "name": "HTML Recuperar_noticias_ABC"
    },
    {
      "parameters": {
        "jsCode": "// Convierte cadenas mal codificadas (ISO-8859-1 \u2192 UTF-8)\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  try {\n    return Buffer.from(str, \"latin1\").toString(\"utf8\")\n      .replace(/\\s+/g, \" \") // limpia saltos de l\u00ednea extra\n      .trim();\n  } catch (e) {\n    return str;\n  }\n}\n\nconst titles = items[0].json.title || [];\nconst links = items[0].json.link || [];\n\nconst search = [];\n\nfor (let i = 0; i < titles.length; i++) {\nsearch.push({\n  title: fixEncoding(titles[i]),\n  link: links[i] || null,\n  medio: \"ULTIMA HORA\" // <--- Agrega esto\n});\n}\n\nreturn [\n  {\n    json: {\n      search\n    }\n  }\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1920,
        -912
      ],
      "id": "4fa0bd3c-aeee-452c-b53e-e01649ca6263",
      "name": "Apilar_noticias_ultima_hora"
    },
    {
      "parameters": {
        "jsCode": "// Convierte cadenas mal codificadas (ISO-8859-1 \u2192 UTF-8)\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  try {\n    return Buffer.from(str, \"latin1\")\n      .toString(\"utf8\")\n      .replace(/\\s+/g, \" \") // limpia saltos de l\u00ednea extra\n      .trim();\n  } catch (e) {\n    return str;\n  }\n}\n\nconst BASE_URL = \"https://www.lanacion.com.py\";\n\nconst titles = items[0].json.title || [];\nconst links = items[0].json.link || [];\n\nconst search = [];\n\nfor (let i = 0; i < titles.length; i++) {\n  const cleanLink = links[i]\n    ? `${BASE_URL}${links[i]}`\n    : null;\n\nsearch.push({\n  title: fixEncoding(titles[i]),\n  link: links[i] || null,\n  medio: \"LA NACI\u00d3N\"\n});\n}\n\nreturn [\n  {\n    json: {\n      search,\n    },\n  },\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1920,
        -720
      ],
      "id": "cc63c163-ef30-4355-a0ce-f438d96ff13f",
      "name": "Apilar_noticias_la_nacion"
    },
    {
      "parameters": {
        "jsCode": "// Convierte cadenas mal codificadas (ISO-8859-1 \u2192 UTF-8)\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  try {\n    return Buffer.from(str, \"latin1\")\n      .toString(\"utf8\")\n      .replace(/\\s+/g, \" \") // limpia saltos de l\u00ednea extra\n      .trim();\n  } catch (e) {\n    return str;\n  }\n}\n\nconst BASE_URL = \"https://www.abc.com.py\";\n\nconst titles = items[0].json.title || [];\nconst links = items[0].json.link || [];\n\nconst search = [];\n\nfor (let i = 0; i < titles.length; i++) {\n  // Calculamos la URL completa y la guardamos en cleanLink\n  const cleanLink = links[i]\n    ? `${BASE_URL}${links[i]}`\n    : null;\n\n  search.push({\n    title: fixEncoding(titles[i]),\n    link: cleanLink, // <--- Usamos la variable que calculamos arriba\n    medio: \"ABC\"\n  });\n}\n\nreturn [\n  {\n    json: {\n      search,\n    },\n  },\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1920,
        -528
      ],
      "id": "895966de-3c17-4f31-958a-9841fd44cfbe",
      "name": "Apilar_noticias_abc"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.search }}",
        "options": {
          "systemMessage": "=Eres un Editor Jefe de un portal de noticias virales en Paraguay, experto en identificar contenido de alto impacto, pol\u00e9mica y sucesos.\n\nTU OBJETIVO:\nProcesar una lista bruta de noticias de diferentes medios (ABC, La Naci\u00f3n, \u00daltima Hora), limpiarlas, eliminar duplicados (noticias repetidas entre medios) y seleccionar solo el Top 3 m\u00e1s viral.\n\nENTRADA:\nRecibir\u00e1s un array de objetos JSON. Cada objeto tiene: \"title\", \"link\" y \"medio\".\n\nTUS TAREAS (EJECUTAR EN ORDEN):\n\n1. LIMPIEZA DE TEXTO:\nRevisa los campos \"title\". Corrige errores de codificaci\u00f3n (mojibakes) y caracteres rotos. Reemplaza s\u00edmbolos extra\u00f1os por la vocal con tilde o la \"\u00f1\" adecuada.\nEjemplo: \"Canci\u00c3\u00b3n\" -> \"Canci\u00f3n\", \"Ni\u00c3\u00b1a\" -> \"Ni\u00f1a\".\n\n2. DEDUPLICACI\u00d3N INTELIGENTE (IMPORTANTE):\nIdentifica noticias que hablen exactamente del MISMO evento, aunque vengan de medios distintos.\n- Si ABC y \u00daltima Hora cubren el mismo asalto, NO incluyas los dos.\n- Compara sus titulares y qu\u00e9date SOLO con la versi\u00f3n que tenga el t\u00edtulo m\u00e1s impactante o clickbait. Descarta la otra versi\u00f3n.\n\n3. FILTRADO POR IMPACTO:\nDe las noticias \u00fanicas resultantes, selecciona solo las que cumplan con criterios de alto inter\u00e9s masivo:\n- Crimen y Policiales: Robos, asaltos, sicariato, justicia por mano propia.\n- Indignaci\u00f3n Social: Corrupci\u00f3n descarada, planillerismo, negligencia m\u00e9dica o estatal.\n- Tragedias: Accidentes fatales, incendios grandes.\n- Morbo/Curiosidad: Esc\u00e1ndalos sexuales, sucesos extra\u00f1os, pol\u00e9micas de far\u00e1ndula.\n\n4. SELECCI\u00d3N FINAL:\nElige las 3 mejores noticias de la lista filtrada.\n\nFORMATO DE SALIDA:\nDevuelve EXCLUSIVAMENTE un Array JSON v\u00e1lido con los 3 objetos seleccionados.\n- Debes conservar el \"link\" y el \"medio\" original de la noticia ganadora.\n- No uses bloques de c\u00f3digo markdown (```json). Solo el texto plano del JSON.\n\nEJEMPLO DE SALIDA EXACTA:\n[\n  {\n    \"title\": \"Motochorro termina llorando tras ser atrapado por vecinos\",\n    \"link\": \"https://www.abc.com.py/...\",\n    \"medio\": \"ABC\"\n  },\n  {\n    \"title\": \"Esc\u00e1ndalo en el Senado: Graban a legislador durmiendo\",\n    \"link\": \"https://www.lanacion.com.py/...\",\n    \"medio\": \"LA NACI\u00d3N\"\n  },\n  {\n    \"title\": \"Terrible accidente deja dos fallecidos en ruta 2\",\n    \"link\": \"https://www.ultimahora.com/...\",\n    \"medio\": \"ULTIMA HORA\"\n  }\n]"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        -1248,
        -720
      ],
      "id": "cd76dbda-a88a-470b-ab9e-7f38dbe9f653",
      "name": "Agente_filtrar_noticias"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1d426a44-0683-40cd-98a2-8cf60f0f1b3f",
              "name": "search",
              "value": "={{ $json.search }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1712,
        192
      ],
      "id": "7d7e9451-d26a-4bd5-bdfa-fac75e47a78f",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "content": "# Farandula",
        "height": 992,
        "width": 2848
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2704,
        -80
      ],
      "typeVersion": 1,
      "id": "a6ca1c24-cb42-4c88-8836-89ae8ec55edc",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1d426a44-0683-40cd-98a2-8cf60f0f1b3f",
              "name": "search",
              "value": "={{ $json.search }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1712,
        384
      ],
      "id": "b03ae265-9f57-42b4-a43c-0cbd12530b9b",
      "name": "Edit Fields16"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-5-mini",
          "mode": "list",
          "cachedResultName": "gpt-5-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -1248,
        560
      ],
      "id": "9c2a35c1-dfbc-42d1-ad25-c8e16c47043a",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1d426a44-0683-40cd-98a2-8cf60f0f1b3f",
              "name": "search",
              "value": "={{ $json.search }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1712,
        576
      ],
      "id": "f82730bc-1f1f-4287-8fb3-4873ac5d4c04",
      "name": "Edit Fields18"
    },
    {
      "parameters": {
        "numberInputs": 3
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        -1456,
        368
      ],
      "id": "05aead97-80cf-408e-b29d-e315579c2573",
      "name": "Merge1"
    },
    {
      "parameters": {
        "jsCode": "// --- CONFIGURACI\u00d3N ---\nconst ID_CATEGORIA = 1; // Ajusta seg\u00fan corresponda (ej: 3 para far\u00e1ndula)\nconst NOTA_DEFAULT = null;\nconst BASE_URL_ABC = \"https://www.abc.com.py\";\n\n// --- FUNCIONES ---\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  return str\n    .replace(/\\uFFFD/g, \"\u00f1\")\n    .replace(/\u00c3\u00a1/g, \"\u00e1\")\n    .replace(/\u00c3\u00a9/g, \"\u00e9\")\n    .replace(/\u00c3\u00ad/g, \"\u00ed\")\n    .replace(/\u00c3\u00b3/g, \"\u00f3\")\n    .replace(/\u00c3\u00ba/g, \"\u00fa\")\n    .replace(/\u00c3\u00b1/g, \"\u00f1\")\n    .replace(/\\s+/g, \" \")\n    .trim();\n}\n\n// Lista temporal para guardar todo\nconst listaParaEnviar = [];\n\n// Recorremos todos los diarios\nfor (const item of $input.all()) {\n  let output = item.json.output;\n\n  if (typeof output === 'string') {\n    try {\n      const cleanJson = output.replace(/```json/g, \"\").replace(/```/g, \"\").trim();\n      output = JSON.parse(cleanJson);\n    } catch (e) {\n      output = [];\n    }\n  }\n\n  if (Array.isArray(output)) {\n    for (const news of output) {\n      let finalLink = news.link || \"\";\n      if (finalLink.startsWith(\"/\")) {\n        finalLink = BASE_URL_ABC + finalLink;\n      }\n\n      // Agregamos a la lista temporal\n      listaParaEnviar.push({\n        medio: news.medio || \"Desconocido\",\n        titulo: fixEncoding(news.title),\n        link: finalLink,\n        id_categoria: ID_CATEGORIA,\n        nota: \"No\"\n      });\n    }\n  }\n}\n\n// IMPORTANTE: Devolvemos UN solo \u00edtem que contiene la lista completa\nreturn [\n  {\n    json: {\n      paquete_noticias: listaParaEnviar\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -704,
        384
      ],
      "id": "1dae151c-bc03-4986-a8f6-827f865b1ce1",
      "name": "Limpieza_caracteres1",
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "3a7a9669-4922-4c4e-8109-5640fe4888ce",
              "name": "output",
              "value": "={{ $json.output }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -896,
        384
      ],
      "id": "19df9b28-f519-45b9-a920-4e039c6061b9",
      "name": "Normalizar_noticias1"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://agent_dashboard:5000/links/create",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.paquete_noticias }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -416,
        384
      ],
      "id": "64b40260-71e5-4e02-a8d9-e0c9be7eb8a0",
      "name": "HTTP Insertar_noticias1",
      "alwaysOutputData": true,
      "retryOnFail": true,
      "waitBetweenTries": 3000,
      "executeOnce": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.search }}",
        "options": {
          "systemMessage": "=Eres un Editor Jefe de un portal de noticias virales en Paraguay, experto en identificar contenido de alto impacto, pol\u00e9mica y sucesos.\n\nTU OBJETIVO:\nProcesar una lista bruta de noticias de diferentes medios (ABC, La Naci\u00f3n, \u00daltima Hora), limpiarlas, eliminar duplicados (noticias repetidas entre medios) y seleccionar solo el Top 3 m\u00e1s viral.\n\nENTRADA:\nRecibir\u00e1s un array de objetos JSON. Cada objeto tiene: \"title\", \"link\" y \"medio\".\n\nTUS TAREAS (EJECUTAR EN ORDEN):\n\n1. LIMPIEZA DE TEXTO:\nRevisa los campos \"title\". Corrige errores de codificaci\u00f3n (mojibakes) y caracteres rotos. Reemplaza s\u00edmbolos extra\u00f1os por la vocal con tilde o la \"\u00f1\" adecuada.\nEjemplo: \"Canci\u00c3\u00b3n\" -> \"Canci\u00f3n\", \"Ni\u00c3\u00b1a\" -> \"Ni\u00f1a\".\n\n2. DEDUPLICACI\u00d3N INTELIGENTE (IMPORTANTE):\nIdentifica noticias que hablen exactamente del MISMO evento, aunque vengan de medios distintos.\n- Si ABC y \u00daltima Hora cubren el mismo asalto, NO incluyas los dos.\n- Compara sus titulares y qu\u00e9date SOLO con la versi\u00f3n que tenga el t\u00edtulo m\u00e1s impactante o clickbait. Descarta la otra versi\u00f3n.\n\n3. FILTRADO POR IMPACTO:\nDe las noticias \u00fanicas resultantes, selecciona solo las que cumplan con criterios de alto inter\u00e9s masivo:\n- Crimen y Policiales: Robos, asaltos, sicariato, justicia por mano propia.\n- Indignaci\u00f3n Social: Corrupci\u00f3n descarada, planillerismo, negligencia m\u00e9dica o estatal.\n- Tragedias: Accidentes fatales, incendios grandes.\n- Morbo/Curiosidad: Esc\u00e1ndalos sexuales, sucesos extra\u00f1os, pol\u00e9micas de far\u00e1ndula.\n\n4. SELECCI\u00d3N FINAL:\nElige las 3 mejores noticias de la lista filtrada.\n\nFORMATO DE SALIDA:\nDevuelve EXCLUSIVAMENTE un Array JSON v\u00e1lido con los 3 objetos seleccionados.\n- Debes conservar el \"link\" y el \"medio\" original de la noticia ganadora.\n- No uses bloques de c\u00f3digo markdown (```json). Solo el texto plano del JSON.\n\nEJEMPLO DE SALIDA EXACTA:\n[\n  {\n    \"title\": \"Motochorro termina llorando tras ser atrapado por vecinos\",\n    \"link\": \"https://www.abc.com.py/...\",\n    \"medio\": \"ABC\"\n  },\n  {\n    \"title\": \"Esc\u00e1ndalo en el Senado: Graban a legislador durmiendo\",\n    \"link\": \"https://www.lanacion.com.py/...\",\n    \"medio\": \"LA NACI\u00d3N\"\n  },\n  {\n    \"title\": \"Terrible accidente deja dos fallecidos en ruta 2\",\n    \"link\": \"https://www.ultimahora.com/...\",\n    \"medio\": \"ULTIMA HORA\"\n  }\n]"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        -1248,
        384
      ],
      "id": "90fce370-a911-401c-87d5-3ce74dc88317",
      "name": "Agente_filtrar_noticias1"
    },
    {
      "parameters": {
        "url": "https://www.extra.com.py/fama",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2336,
        192
      ],
      "id": "cf4dc1cd-4fb9-4691-8cbf-fd3041dd21bd",
      "name": "HTTP EXTRA"
    },
    {
      "parameters": {
        "url": "https://www.popular.com.py/categoria/farandula/",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2336,
        384
      ],
      "id": "98234f6a-c34f-4b62-b498-21bb13c17819",
      "name": "HTTP POPULAR"
    },
    {
      "parameters": {
        "url": "https://www.cronica.com.py/category/farandula/",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2336,
        576
      ],
      "id": "f263e61b-25ae-40de-9bc1-07631613d9cb",
      "name": "HTTP CRONICA"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": ".entry-title a",
              "returnArray": true
            },
            {
              "key": "link",
              "cssSelector": ".entry-title a",
              "returnValue": "attribute",
              "attribute": "href",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        -2128,
        576
      ],
      "id": "a7ae1d77-b197-459d-83d9-6c9c7886c1d6",
      "name": "HTML Recuperar_noticias_cronica"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": "h5.clamped a",
              "returnArray": true
            },
            {
              "key": "link",
              "cssSelector": "h5.clamped a",
              "returnValue": "attribute",
              "attribute": "href",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        -2128,
        384
      ],
      "id": "908de82d-c11b-4f28-b0be-8588f2eed1c2",
      "name": "HTML Recuperar_noticias_popular"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": ".PagePromo-title a",
              "returnArray": true
            },
            {
              "key": "link",
              "cssSelector": ".PagePromo-title a",
              "returnValue": "attribute",
              "attribute": "href",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        -2128,
        192
      ],
      "id": "fdddc0af-2da1-4d93-8f86-1d19ec3f28a3",
      "name": "HTML Recuperar_noticias_extra"
    },
    {
      "parameters": {
        "jsCode": "// Convierte cadenas mal codificadas (ISO-8859-1 \u2192 UTF-8)\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  try {\n    return Buffer.from(str, \"latin1\")\n      .toString(\"utf8\")\n      .replace(/\\s+/g, \" \") // limpia saltos de l\u00ednea extra\n      .trim();\n  } catch (e) {\n    return str;\n  }\n}\n\nconst BASE_URL = \"https://www.abc.com.py\";\n\nconst titles = items[0].json.title || [];\nconst links = items[0].json.link || [];\n\nconst search = [];\n\nfor (let i = 0; i < titles.length; i++) {\n  const cleanLink = links[i]\n    ? `${BASE_URL}${links[i]}`\n    : null;\n\nsearch.push({\n  title: fixEncoding(titles[i]),\n  link: links[i] || null,\n  medio: \"CRONICA\"\n});\n}\n\nreturn [\n  {\n    json: {\n      search,\n    },\n  },\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1920,
        576
      ],
      "id": "7dc69ab7-d2fc-4e56-9b14-80b6b49def50",
      "name": "Apilar_noticias_cronica"
    },
    {
      "parameters": {
        "jsCode": "// Convierte cadenas mal codificadas (ISO-8859-1 \u2192 UTF-8)\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  try {\n    return Buffer.from(str, \"latin1\")\n      .toString(\"utf8\")\n      .replace(/\\s+/g, \" \") // limpia saltos de l\u00ednea extra\n      .trim();\n  } catch (e) {\n    return str;\n  }\n}\n\nconst BASE_URL = \"https://www.lanacion.com.py\";\n\nconst titles = items[0].json.title || [];\nconst links = items[0].json.link || [];\n\nconst search = [];\n\nfor (let i = 0; i < titles.length; i++) {\n  const cleanLink = links[i]\n    ? `${BASE_URL}${links[i]}`\n    : null;\n\nsearch.push({\n  title: fixEncoding(titles[i]),\n  link: links[i] || null,\n  medio: \"POPULAR\"\n});\n}\n\nreturn [\n  {\n    json: {\n      search,\n    },\n  },\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1920,
        384
      ],
      "id": "2cfbfe45-0b0b-43a2-812e-3d73cf17fd5a",
      "name": "Apilar_noticias_popular"
    },
    {
      "parameters": {
        "jsCode": "// Convierte cadenas mal codificadas (ISO-8859-1 \u2192 UTF-8)\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  try {\n    return Buffer.from(str, \"latin1\").toString(\"utf8\")\n      .replace(/\\s+/g, \" \") // limpia saltos de l\u00ednea extra\n      .trim();\n  } catch (e) {\n    return str;\n  }\n}\n\nconst titles = items[0].json.title || [];\nconst links = items[0].json.link || [];\n\nconst search = [];\n\nfor (let i = 0; i < titles.length; i++) {\nsearch.push({\n  title: fixEncoding(titles[i]),\n  link: links[i] || null,\n  medio: \"EXTRA\"\n});\n}\n\nreturn [\n  {\n    json: {\n      search\n    }\n  }\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1920,
        192
      ],
      "id": "e314f1a9-6f24-40a3-937c-e3b6c08f4eab",
      "name": "Apilar_noticias_extra"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -4240,
        224
      ],
      "id": "c3636df9-7c04-4303-a5d3-e12f5a18a5c9",
      "name": "When clicking \u2018Execute workflow\u2019"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1d426a44-0683-40cd-98a2-8cf60f0f1b3f",
              "name": "search",
              "value": "={{ $json.search }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1696,
        1296
      ],
      "id": "1fb859ba-e9d0-4841-9bba-05c408c9c711",
      "name": "Edit Fields2"
    },
    {
      "parameters": {
        "content": "# Deportes",
        "height": 992,
        "width": 2880
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2688,
        1024
      ],
      "typeVersion": 1,
      "id": "c1b44c67-1e66-4c02-bab2-47db34f06e1a",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1d426a44-0683-40cd-98a2-8cf60f0f1b3f",
              "name": "search",
              "value": "={{ $json.search }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1696,
        1488
      ],
      "id": "ff5c05bd-0af9-420c-b8b1-50ab4cbe6e9c",
      "name": "Edit Fields19"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-5-mini",
          "mode": "list",
          "cachedResultName": "gpt-5-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -1232,
        1664
      ],
      "id": "66a10b00-678f-4f27-863f-8a37cba4beac",
      "name": "OpenAI Chat Model1",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1d426a44-0683-40cd-98a2-8cf60f0f1b3f",
              "name": "search",
              "value": "={{ $json.search }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1696,
        1680
      ],
      "id": "ea645e7a-d4bc-48db-8b53-5df51fbfc9d6",
      "name": "Edit Fields20"
    },
    {
      "parameters": {
        "numberInputs": 3
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        -1440,
        1472
      ],
      "id": "fd4e7283-2158-4374-9a20-05f43c269fb1",
      "name": "Merge2"
    },
    {
      "parameters": {
        "jsCode": "// --- CONFIGURACI\u00d3N ---\nconst ID_CATEGORIA = 1; // Ajusta seg\u00fan corresponda (ej: 3 para far\u00e1ndula)\nconst NOTA_DEFAULT = null;\nconst BASE_URL_ABC = \"https://www.abc.com.py\";\n\n// --- FUNCIONES ---\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  return str\n    .replace(/\\uFFFD/g, \"\u00f1\")\n    .replace(/\u00c3\u00a1/g, \"\u00e1\")\n    .replace(/\u00c3\u00a9/g, \"\u00e9\")\n    .replace(/\u00c3\u00ad/g, \"\u00ed\")\n    .replace(/\u00c3\u00b3/g, \"\u00f3\")\n    .replace(/\u00c3\u00ba/g, \"\u00fa\")\n    .replace(/\u00c3\u00b1/g, \"\u00f1\")\n    .replace(/\\s+/g, \" \")\n    .trim();\n}\n\n// Lista temporal para guardar todo\nconst listaParaEnviar = [];\n\n// Recorremos todos los diarios\nfor (const item of $input.all()) {\n  let output = item.json.output;\n\n  if (typeof output === 'string') {\n    try {\n      const cleanJson = output.replace(/```json/g, \"\").replace(/```/g, \"\").trim();\n      output = JSON.parse(cleanJson);\n    } catch (e) {\n      output = [];\n    }\n  }\n\n  if (Array.isArray(output)) {\n    for (const news of output) {\n      let finalLink = news.link || \"\";\n      if (finalLink.startsWith(\"/\")) {\n        finalLink = BASE_URL_ABC + finalLink;\n      }\n\n      // Agregamos a la lista temporal\n      listaParaEnviar.push({\n        medio: news.medio || \"Desconocido\",\n        titulo: fixEncoding(news.title),\n        link: finalLink,\n        id_categoria: ID_CATEGORIA,\n        nota: \"No\"\n      });\n    }\n  }\n}\n\n// IMPORTANTE: Devolvemos UN solo \u00edtem que contiene la lista completa\nreturn [\n  {\n    json: {\n      paquete_noticias: listaParaEnviar\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -688,
        1488
      ],
      "id": "c0ff93e9-bba0-41aa-bdbf-86d5fa33f605",
      "name": "Limpieza_caracteres2",
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "3a7a9669-4922-4c4e-8109-5640fe4888ce",
              "name": "output",
              "value": "={{ $json.output }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -880,
        1488
      ],
      "id": "e778743f-c490-4ed2-aea2-40ba507818f0",
      "name": "Normalizar_noticias2"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.search }}",
        "options": {
          "systemMessage": "=Eres un Editor Jefe de la secci\u00f3n de Deportes de un portal paraguayo, experto en identificar noticias que generan pasi\u00f3n, debate y clics masivos.\n\nTU OBJETIVO:\nProcesar una lista bruta de noticias deportivas de diferentes medios (ABC, Versus, Hoy, etc.), limpiarlas, eliminar duplicados y seleccionar el Top 3 m\u00e1s relevante.\n\nENTRADA:\nRecibir\u00e1s un array de objetos JSON. Cada objeto tiene: \"title\", \"link\" y \"medio\".\n\nTUS TAREAS (EJECUTAR EN ORDEN):\n\n1. LIMPIEZA DE TEXTO:\nRevisa los campos \"title\". Corrige errores de codificaci\u00f3n (mojibakes). Reemplaza s\u00edmbolos extra\u00f1os por la vocal con tilde o la \"\u00f1\" adecuada.\nEjemplo: \"Campe\u00c3\u00b3n\" -> \"Campe\u00f3n\", \"Cerro Porte\u00c3\u00b1o\" -> \"Cerro Porte\u00f1o\".\n\n2. DEDUPLICACI\u00d3N INTELIGENTE (CRUCIAL):\nIdentifica noticias que hablen del MISMO partido, fichaje o declaraci\u00f3n.\n- Si dos medios hablan de \"Goleada de Cerro\", NO incluyas ambos.\n- Compara los titulares y qu\u00e9date con la versi\u00f3n m\u00e1s \"picante\", emotiva o que venda mejor la noticia.\n\n3. FILTRADO POR IMPACTO (CRITERIOS DE SELECCI\u00d3N):\nPrioriza noticias que encajen en estas categor\u00edas de alto inter\u00e9s:\n- Paraguayos en el Exterior: Goles de figuras (Almir\u00f3n, Enciso, Ram\u00f3n Sosa, Gustavo G\u00f3mez), fichajes millonarios o lesiones graves.\n- Supercl\u00e1sico y Grandes: Noticias bombas sobre Olimpia y Cerro Porte\u00f1o (fichajes, crisis, renuncias de DTs).\n- Selecci\u00f3n Paraguaya (Albirroja): Convocatorias, declaraciones del t\u00e9cnico, pol\u00e9micas.\n- Pol\u00e9mica/Viral: Errores arbitrales groseros, peleas en cancha, declaraciones picantes de jugadores o dirigentes.\n- Haza\u00f1as: Victorias hist\u00f3ricas o remontadas \u00e9picas.\n*Descarta resultados irrelevantes de ligas menores o deportes con poco seguimiento masivo, a menos que sea un suceso extraordinario.*\n\n4. SELECCI\u00d3N FINAL:\nElige las 3 noticias m\u00e1s potentes.\n\nFORMATO DE SALIDA:\nDevuelve EXCLUSIVAMENTE un Array JSON v\u00e1lido con los 3 objetos seleccionados.\n- Conserva el \"link\" y \"medio\" original.\n- No uses bloques markdown. Solo el JSON plano.\n\nEJEMPLO DE SALIDA EXACTA:\n[\n  {\n    \"title\": \"\u00a1Golazo de Enciso! El paraguayo brilla en la Premier League\",\n    \"link\": \"https://www.vssports.com.py/...\",\n    \"medio\": \"HOY\"\n  },\n  {\n    \"title\": \"Esc\u00e1ndalo arbitral: El penal que no le cobraron a Olimpia\",\n    \"link\": \"https://www.abc.com.py/...\",\n    \"medio\": \"ABC\"\n  },\n  {\n    \"title\": \"Cerro Porte\u00f1o se queda sin DT tras la derrota en la Olla\",\n    \"link\": \"https://www.lanacion.com.py/...\",\n    \"medio\": \"LA NACION\"\n  }\n]"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        -1232,
        1488
      ],
      "id": "f8de70d2-e70b-44d4-abc0-3adb84480e84",
      "name": "Agente_filtrar_noticias2"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": ".article-title span",
              "returnArray": true
            },
            {
              "key": "link",
              "cssSelector": ".article-info > a",
              "returnValue": "attribute",
              "attribute": "href",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        -2112,
        1680
      ],
      "id": "751e9557-af91-4cbd-81fc-75f684453a3e",
      "name": "HTML Recuperar_noticias_cronica1"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": ".list-entry-title a",
              "returnArray": true
            },
            {
              "key": "link",
              "cssSelector": ".list-entry-title a",
              "returnValue": "attribute",
              "attribute": "href",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        -2112,
        1488
      ],
      "id": "8e3a784f-a1af-4250-b9d1-2b0a4033d463",
      "name": "HTML Recuperar_noticias_popular1"
    },
    {
      "parameters": {
        "jsCode": "// Convierte cadenas mal codificadas (ISO-8859-1 \u2192 UTF-8)\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  try {\n    return Buffer.from(str, \"latin1\")\n      .toString(\"utf8\")\n      .replace(/\\s+/g, \" \") // limpia saltos de l\u00ednea extra\n      .trim();\n  } catch (e) {\n    return str;\n  }\n}\n\nconst BASE_URL = \"https://www.abc.com.py\";\n\nconst titles = items[0].json.title || [];\nconst links = items[0].json.link || [];\n\nconst search = [];\n\nfor (let i = 0; i < titles.length; i++) {\n  // Calculamos la URL completa y la guardamos en cleanLink\n  const cleanLink = links[i]\n    ? `${BASE_URL}${links[i]}`\n    : null;\n\n  search.push({\n    title: fixEncoding(titles[i]),\n    link: cleanLink, // <--- Usamos la variable que calculamos arriba\n    medio: \"ABC\"\n  });\n}\n\nreturn [\n  {\n    json: {\n      search,\n    },\n  },\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1904,
        1680
      ],
      "id": "a81f68af-1ce1-42e1-85ef-568eaca14593",
      "name": "Apilar_noticias_cronica1"
    },
    {
      "parameters": {
        "jsCode": "// Convierte cadenas mal codificadas (ISO-8859-1 \u2192 UTF-8)\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  try {\n    return Buffer.from(str, \"latin1\")\n      .toString(\"utf8\")\n      .replace(/\\s+/g, \" \") // limpia saltos de l\u00ednea extra\n      .trim();\n  } catch (e) {\n    return str;\n  }\n}\n\nconst BASE_URL = \"https://www.lanacion.com.py\";\n\nconst titles = items[0].json.title || [];\nconst links = items[0].json.link || [];\n\nconst search = [];\n\nfor (let i = 0; i < titles.length; i++) {\n  const cleanLink = links[i]\n    ? `${BASE_URL}${links[i]}`\n    : null;\n\nsearch.push({\n  title: fixEncoding(titles[i]),\n  link: links[i] || null,\n  medio: \"LA NACI\u00d3N\"\n});\n}\n\nreturn [\n  {\n    json: {\n      search,\n    },\n  },\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1904,
        1488
      ],
      "id": "24455f83-8fc5-436f-b013-c8bd7d8ad17a",
      "name": "Apilar_noticias_popular1"
    },
    {
      "parameters": {
        "url": "https://d10.ultimahora.com/ultimas-noticias",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2320,
        1296
      ],
      "id": "dfe0aab8-f03b-4722-bc99-f3a3266c66c1",
      "name": "HTTP D10"
    },
    {
      "parameters": {
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": ".PagePromo-title a",
              "returnArray": true
            },
            {
              "key": "link",
              "cssSelector": ".PagePromo-title a",
              "returnValue": "attribute",
              "attribute": "href",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "position": [
        -2112,
        1296
      ],
      "id": "7aa5df75-3b11-46e7-91f1-454fbdb57ebc",
      "name": "HTML Recuperar_noticias_d10"
    },
    {
      "parameters": {
        "jsCode": "// Convierte cadenas mal codificadas (ISO-8859-1 \u2192 UTF-8)\nfunction fixEncoding(str) {\n  if (!str) return \"\";\n  try {\n    return Buffer.from(str, \"latin1\").toString(\"utf8\")\n      .replace(/\\s+/g, \" \") // limpia saltos de l\u00ednea extra\n      .trim();\n  } catch (e) {\n    return str;\n  }\n}\n\nconst titles = items[0].json.title || [];\nconst links = items[0].json.link || [];\n\nconst search = [];\n\nfor (let i = 0; i < titles.length; i++) {\nsearch.push({\n  title: fixEncoding(titles[i]),\n  link: links[i] || null,\n  medio: \"D10\"\n});\n}\n\nreturn [\n  {\n    json: {\n      search\n    }\n  }\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1904,
        1296
      ],
      "id": "02f5e40b-e61b-4971-b954-3d2a58923e4b",
      "name": "Apilar_noticias_d10"
    },
    {
      "parameters": {
        "url": "https://www.hoy.com.py/deportes",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2320,
        1488
      ],
      "id": "b1c90fed-a639-40f4-91a5-63f3d9336ce3",
      "name": "HTTP La Naci\u00f3n Deportes"
    },
    {
      "parameters": {
        "url": "https://www.abc.com.py/deportes/",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2320,
        1680
      ],
      "id": "500265e0-b174-499f-a263-d979edc5ce19",
      "name": "HTTP ABC Deportes"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://agent_dashboard:5000/links/create",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.paquete_noticias }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -400,
        -704
      ],
      "id": "b7bab9c5-8e67-493a-b439-b2b74bede30a",
      "name": "HTTP Insertar_noticias3",
      "alwaysOutputData": true,
      "retryOnFail": true,
      "waitBetweenTries": 3000,
      "executeOnce": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://agent_dashboard:5000/links/create",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.paquete_noticias }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -368,
        1488
      ],
      "id": "e80ef3e4-9e13-4766-b57e-20925e5d53eb",
      "name": "HTTP Insertar_noticias",
      "alwaysOutputData": true,
      "retryOnFail": true,
      "waitBetweenTries": 3000,
      "executeOnce": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "numberInputs": 3
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        560,
        416
      ],
      "id": "c5a562d0-cd32-4c05-9fba-3c0e4cdb447e",
      "name": "Uni\u00f3n_Noticias"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "425b8db9-12b1-466a-a5cc-e019ee646b5c",
              "name": "selected_news_current",
              "value": "={{ $json.created_details }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -16,
        -720
      ],
      "id": "98b1101c-6a0b-4fc5-8d36-ddd44daa2c6f",
      "name": "Edit Fields4"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "21f45c79-abef-4ab5-8a81-9388e4ad4003",
              "name": "selected_news_entertainment",
              "value": "={{ $json.created_details[0] }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -32,
        368
      ],
      "id": "d6b4d342-e737-4d8a-a90e-7b5c6c3d4814",
      "name": "Edit Fields5"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "932a5c8a-4e94-4cd9-8953-09ce32bb6c67",
              "name": "selected_news_sports",
              "value": "={{ $json.created_details }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -48,
        1472
      ],
      "id": "abaa66bc-84a2-4b95-9e3f-7f5e908a44f3",
      "name": "Edit Fields6"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.selected_news_current }}",
                    "rightValue": "Actualidad",
                    "operator": {
                      "type": "array",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "id": "cb396ed6-d7a4-4a25-9636-2db04737de6b"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Actualidad"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "59202e92-41d8-471c-b6e2-f1ce851fd1fb",
                    "leftValue": "={{ $json.selected_news_sports }}",
                    "rightValue": "Deportes",
                    "operator": {
                      "type": "array",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Deportes"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        1072,
        432
      ],
      "id": "03f87b1d-96e2-45de-bf39-db66888603f8",
      "name": "Switch"
    }
  ],
  "connections": {
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Ultima Hora": {
      "main": [
        [
          {
            "node": "HTML Recuperar_noticias_ULTIMA_HORA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields15": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "OpenAI Chat Model6": {
      "ai_languageModel": [
        [
          {
            "node": "Agente_filtrar_noticias",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields17": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "HTTP ABC": {
      "main": [
        [
          {
            "node": "HTML Recuperar_noticias_ABC",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP LA NACI\u00d3N": {
      "main": [
        [
          {
            "node": "HTML Recuperar_noticias_LA_NACION",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Agente_filtrar_noticias",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limpieza_caracteres": {
      "main": [
        [
          {
            "node": "HTTP Insertar_noticias3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalizar_noticias": {
      "main": [
        [
          {
            "node": "Limpieza_caracteres",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Recuperar_noticias_ULTIMA_HORA": {
      "main": [
        [
          {
            "node": "Apilar_noticias_ultima_hora",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Recuperar_noticias_LA_NACION": {
      "main": [
        [
          {
            "node": "Apilar_noticias_la_nacion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Recuperar_noticias_ABC": {
      "main": [
        [
          {
            "node": "Apilar_noticias_abc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apilar_noticias_ultima_hora": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apilar_noticias_la_nacion": {
      "main": [
        [
          {
            "node": "Edit Fields15",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apilar_noticias_abc": {
      "main": [
        [
          {
            "node": "Edit Fields17",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agente_filtrar_noticias": {
      "main": [
        [
          {
            "node": "Normalizar_noticias",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields16": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Agente_filtrar_noticias1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields18": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Agente_filtrar_noticias1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limpieza_caracteres1": {
      "main": [
        [
          {
            "node": "HTTP Insertar_noticias1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalizar_noticias1": {
      "main": [
        [
          {
            "node": "Limpieza_caracteres1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agente_filtrar_noticias1": {
      "main": [
        [
          {
            "node": "Normalizar_noticias1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP EXTRA": {
      "main": [
        [
          {
            "node": "HTML Recuperar_noticias_extra",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP POPULAR": {
      "main": [
        [
          {
            "node": "HTML Recuperar_noticias_popular",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP CRONICA": {
      "main": [
        [
          {
            "node": "HTML Recuperar_noticias_cronica",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Recuperar_noticias_cronica": {
      "main": [
        [
          {
            "node": "Apilar_noticias_cronica",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Recuperar_noticias_popular": {
      "main": [
        [
          {
            "node": "Apilar_noticias_popular",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Recuperar_noticias_extra": {
      "main": [
        [
          {
            "node": "Apilar_noticias_extra",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apilar_noticias_cronica": {
      "main": [
        [
          {
            "node": "Edit Fields18",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apilar_noticias_popular": {
      "main": [
        [
          {
            "node": "Edit Fields16",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apilar_noticias_extra": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "HTTP EXTRA",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP POPULAR",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP CRONICA",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP Ultima Hora",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP LA NACI\u00d3N",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP ABC",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP D10",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP La Naci\u00f3n Deportes",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP ABC Deportes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields2": {
      "main": [
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields19": {
      "main": [
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Agente_filtrar_noticias2",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields20": {
      "main": [
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Merge2": {
      "main": [
        [
          {
            "node": "Agente_filtrar_noticias2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limpieza_caracteres2": {
      "main": [
        [
          {
            "node": "HTTP Insertar_noticias",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalizar_noticias2": {
      "main": [
        [
          {
            "node": "Limpieza_caracteres2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agente_filtrar_noticias2": {
      "main": [
        [
          {
            "node": "Normalizar_noticias2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Recuperar_noticias_cronica1": {
      "main": [
        [
          {
            "node": "Apilar_noticias_cronica1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Recuperar_noticias_popular1": {
      "main": [
        [
          {
            "node": "Apilar_noticias_popular1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apilar_noticias_cronica1": {
      "main": [
        [
          {
            "node": "Edit Fields20",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apilar_noticias_popular1": {
      "main": [
        [
          {
            "node": "Edit Fields19",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP D10": {
      "main": [
        [
          {
            "node": "HTML Recuperar_noticias_d10",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Recuperar_noticias_d10": {
      "main": [
        [
          {
            "node": "Apilar_noticias_d10",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apilar_noticias_d10": {
      "main": [
        [
          {
            "node": "Edit Fields2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP La Naci\u00f3n Deportes": {
      "main": [
        [
          {
            "node": "HTML Recuperar_noticias_popular1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP ABC Deportes": {
      "main": [
        [
          {
            "node": "HTML Recuperar_noticias_cronica1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Insertar_noticias3": {
      "main": [
        [
          {
            "node": "Edit Fields4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Insertar_noticias1": {
      "main": [
        [
          {
            "node": "Edit Fields5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Insertar_noticias": {
      "main": [
        [
          {
            "node": "Edit Fields6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Uni\u00f3n_Noticias": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields4": {
      "main": [
        [
          {
            "node": "Uni\u00f3n_Noticias",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields5": {
      "main": [
        [
          {
            "node": "Uni\u00f3n_Noticias",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Edit Fields6": {
      "main": [
        [
          {
            "node": "Uni\u00f3n_Noticias",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [],
        []
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false
  },
  "versionId": "331ddd02-2971-41ef-b450-7c346655e7db",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "kY5rzsUNMy8p42Nz",
  "tags": [
    {
      "updatedAt": "2026-02-03T12:33:25.586Z",
      "createdAt": "2026-02-03T12:33:25.586Z",
      "id": "iz1TOwAtlbvrbTJG",
      "name": "agent_journalist"
    }
  ]
}