{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "43e712ff-dbda-4924-8d45-faac98713e20",
      "name": "Sticky Note20",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        416,
        240
      ],
      "parameters": {
        "width": 272,
        "height": 352,
        "content": "## 3. Result Splitter\nSplitting feed results to separe items"
      },
      "typeVersion": 1
    },
    {
      "id": "b927d71f-0547-4051-afeb-f00e5ce16241",
      "name": "Sticky Note21",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        240
      ],
      "parameters": {
        "color": 7,
        "width": 320,
        "height": 352,
        "content": "## 3. Filter by last 24h\nYou can edit HOURS in the code if you need a wider window."
      },
      "typeVersion": 1
    },
    {
      "id": "4d5cd7cf-0c31-45a4-838a-92505b192056",
      "name": "Sticky Note22",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1552,
        240
      ],
      "parameters": {
        "color": 4,
        "width": 880,
        "height": 352,
        "content": "## 5. Register in Notion\n* Filter fields before Notion\n* Register to Notion\n* Freeze **page_id** of each record\n* Add subtitle **Deep Research Summary** inside new pages (will be used later)"
      },
      "typeVersion": 1
    },
    {
      "id": "f3a392a2-2e79-4c81-89e7-f19f749b0e86",
      "name": "Sticky Note23",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3968,
        464
      ],
      "parameters": {
        "color": 4,
        "width": 256,
        "height": 352,
        "content": "## 10. Saving to Notion\nEach chunk is saved, one by one, under the related paper according to their **page_id**"
      },
      "typeVersion": 1
    },
    {
      "id": "7c7b1d33-ce9b-49fe-b94f-a1a2daa56ba9",
      "name": "Sticky Note24",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2464,
        240
      ],
      "parameters": {
        "color": 7,
        "width": 2240,
        "height": 800,
        "content": "## 7. Generating and Saving a Deep Research Summary for each Paper\nProcessing every paper (full documents), one by one. Then generating a **Deep Research Summary** for each document and saving it to Notion. The **Deep Research Summary** provides a deeper analysis explaining paper's ideas and meanings clearly to curious professionals and non technical experts.\n\nContents Generated:\n-> 1) 3\u20135 core insights; 2) Core idea and motivation \u2014 explained simply; 3) Why this research matters now (context & importance); 4) Key innovations & contributions; 5) Method \u2014 explained step-by-step in plain language; 6) Math / theory intuition (no formulas); 7) Experiments and evaluation \u2014 what was tested and why it matters; 8) Key results & what they prove; 9) Limitations / where it may fail; 10) Real-world impact and applications; 11) Future work / open questions; 12) Closing takeaway \u2014 2-3 sentences summarizing the big picture"
      },
      "typeVersion": 1
    },
    {
      "id": "edafcf5f-5cf6-409a-af6e-a75a4149e6f9",
      "name": "Sticky Note25",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2224,
        -96
      ],
      "parameters": {
        "color": 5,
        "width": 528,
        "height": 304,
        "content": "## 6. Send News to Telegram\nMessages are sent as separate items, which include **title**, **authors**, **data** and **links** (including a link to Notion with **Deep Resume** we will be generating)."
      },
      "typeVersion": 1
    },
    {
      "id": "003c9df5-db71-4921-a212-39048bac0c17",
      "name": "Sticky Note26",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1072,
        240
      ],
      "parameters": {
        "width": 448,
        "height": 352,
        "content": "## 4. Result Cleaner\nDedupe results in case of repeated items and prepare clean fields for the next node"
      },
      "typeVersion": 1
    },
    {
      "id": "91ca89b2-1c87-4baa-a490-d10b3bc73bdb",
      "name": "Sticky Note28",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        -240
      ],
      "parameters": {
        "color": 3,
        "width": 4992,
        "height": 80,
        "content": "# AI NEWS FROM ARXIV"
      },
      "typeVersion": 1
    },
    {
      "id": "dbd106b3-5991-4279-b6a1-6ac708e20242",
      "name": "Sticky Note29",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3440,
        464
      ],
      "parameters": {
        "width": 496,
        "height": 352,
        "content": "## 9. Splitting Output\nThe Output Data is too long to be saved to Notion, so is splitted into different chunks [<2000 characters], then debuged before saving"
      },
      "typeVersion": 1
    },
    {
      "id": "4a019d5e-d657-476e-80f8-2f4dd0ef03e5",
      "name": "Sticky Note30",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2832,
        464
      ],
      "parameters": {
        "color": 3,
        "width": 576,
        "height": 464,
        "content": "## 8. Generating Deep Research Summary\nEach paper's pfd is analized to get a **Deep Research Summary**, and then **merge** the result with the related **page_id** to be saved to Notion."
      },
      "typeVersion": 1
    },
    {
      "id": "65ba3fb9-7d0d-4a66-b658-5d549366f188",
      "name": "Code (Parse Gemini JSON in chunks)7",
      "type": "n8n-nodes-base.code",
      "position": [
        3552,
        608
      ],
      "parameters": {
        "jsCode": "// Toma todos los items del Merge\nconst items = $input.all();\n\n// 1) Localiza page_id y el texto de Gemini\nconst pageId =\n  items.find(it => it.json?.page_id)?.json.page_id ?? null;\n\nconst rawText =\n  items.find(it => it.json?.content)?.json?.content?.parts?.[0]?.text ?? \"\";\n\n// 2) Limpia fences ```json ... ``` y espacios\nconst cleaned = String(rawText)\n  .replace(/```json/gi, \"\")\n  .replace(/```/g, \"\")\n  .trim();\n\n// 3) Intenta parsear JSON. Si falla, deja objeto vac\u00edo.\nlet parsed = {};\ntry {\n  parsed = cleaned ? JSON.parse(cleaned) : {};\n} catch (_) {\n  parsed = {};\n}\n\n// 4) Extrae el array de trozos con tolerancia de nombres\nconst chunks =\n  Array.isArray(parsed.chunks) ? parsed.chunks :\n  Array.isArray(parsed.summary_chunks) ? parsed.summary_chunks :\n  Array.isArray(parsed.slices) ? parsed.slices :\n  [];\n\n// 5) Si no hay page_id o no hay chunks, no emites nada \u00fatil\nif (!pageId || !Array.isArray(chunks) || chunks.length === 0) {\n  // Opcional: emite un item de depuraci\u00f3n para ver qu\u00e9 lleg\u00f3\n  return [{\n    json: {\n      __parse_debug: true,\n      page_id_present: !!pageId,\n      got_chunks: Array.isArray(chunks) ? chunks.length : -1,\n      preview: cleaned.slice(0, 280)\n    }\n  }];\n}\n\n// 6) Emite un item por chunk: { page_id, slice, chunk_index, slice_index }\nreturn chunks.map((chunk, i) => ({\n  json: {\n    page_id: pageId,\n    slice: String(chunk).trim(),\n    chunk_index: i,\n    slice_index: 0,\n  }\n}));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "fedd41d3-62ac-4685-a66f-8c0e5a42a329",
      "name": "Split Results",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        496,
        400
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "feed.entry"
      },
      "typeVersion": 1
    },
    {
      "id": "86faed42-ea10-499f-bbbf-c2edca9dffd8",
      "name": "Sticky Note32",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        240
      ],
      "parameters": {
        "width": 368,
        "height": 352,
        "content": "## 2. Website Scraper\nScraping papers from [arXiv.org] filtered by **Artificial Intelligence** and then converting the results to JSON"
      },
      "typeVersion": 1
    },
    {
      "id": "a3b34013-d1e8-429e-a998-704bcb3bee13",
      "name": "Sticky Note33",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        240
      ],
      "parameters": {
        "color": 6,
        "width": 272,
        "height": 368,
        "content": "## 1. Daily arXiv AI News Trigger\nExecuted daily at 8.00 am CET\n\nlink: https://arxiv.org/search/?query=Artificial+Intelligence&searchtype=all&source=header"
      },
      "typeVersion": 1
    },
    {
      "id": "95d19cfc-f7d9-4326-bda7-2deaebaedfdd",
      "name": "Scheduled Daily Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -208,
        448
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "befe2fc3-f00e-4157-a4ba-fbdbb4a003dc",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        80,
        400
      ],
      "parameters": {
        "url": "https://export.arxiv.org/api/query",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          },
          "allowUnauthorizedCerts": true
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "search_query",
              "value": "abs:\"artificial intelligence\""
            },
            {
              "name": "sortBy",
              "value": "submittedDate"
            },
            {
              "name": "sortOrder",
              "value": "descending"
            },
            {
              "name": "start",
              "value": "0"
            },
            {
              "name": "max_results",
              "value": "100"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "81ea7bd5-edac-43f7-9736-3f5fed6678cc",
      "name": "Format Conversor",
      "type": "n8n-nodes-base.xml",
      "position": [
        240,
        400
      ],
      "parameters": {
        "options": {
          "mergeAttrs": true
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c4c53a6d-cfae-4817-b077-5c82f8381fff",
      "name": "Dedupe with Static Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1136,
        400
      ],
      "parameters": {
        "jsCode": "// === DEDUPLICADOR PERSISTENTE ===\n// Guarda IDs ya vistos entre ejecuciones (funciona en \"Code\" con modo Run Once for All Items)\n\nconst store = $getWorkflowStaticData('global'); // \u2705 Correcta sintaxis en n8n actual\nif (!store.seen) store.seen = {}; // mapa id -> fecha\nconst seen = store.seen;\n\n// Dedupe dentro de la misma ejecuci\u00f3n\nconst batchSeen = new Set();\nconst out = [];\n\nfor (const it of items) {\n  const id = it.json.arxiv_id || it.json.link || it.json.id;\n  if (!id) continue;\n\n  if (batchSeen.has(id)) continue;  // ya apareci\u00f3 en esta ejecuci\u00f3n\n  batchSeen.add(id);\n\n  if (seen[id]) continue;           // ya apareci\u00f3 en ejecuciones previas\n\n  // marcar como nuevo\n  seen[id] = new Date().toISOString();\n  out.push(it);\n}\n\n// Limpiar registros viejos si excede 2000 entradas\nconst MAX = 2000;\nconst entries = Object.entries(seen)\n  .sort((a, b) => new Date(b[1]) - new Date(a[1]));\nif (entries.length > MAX) {\n  const keep = new Set(entries.slice(0, MAX).map(([k]) => k));\n  for (const k of Object.keys(seen)) {\n    if (!keep.has(k)) delete seen[k];\n  }\n}\n\nreturn out;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "d66eb078-88f1-4de0-b3ae-95ad34398c27",
      "name": "Edit Fields for Notion (incl. pdf)",
      "type": "n8n-nodes-base.set",
      "position": [
        1632,
        400
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "4f50a382-fd77-425b-b583-5140078f1d15",
              "name": "title",
              "type": "string",
              "value": "={{ $json.properties.title.title[0].text.content }}"
            },
            {
              "id": "943afbe5-13a8-46e8-8904-6c9139e741a5",
              "name": "published",
              "type": "string",
              "value": "={{ $json.properties.published.date.start }}"
            },
            {
              "id": "2476f04e-1db7-41aa-9388-bc9d692883bf",
              "name": "arxiv_id",
              "type": "string",
              "value": "={{ $json.properties.arxiv_id.rich_text[0].text.content }}"
            },
            {
              "id": "ca36a055-966b-4b29-a164-cfee360fc999",
              "name": "authors",
              "type": "string",
              "value": "={{ $json.properties.authors.rich_text[0].text.content }}"
            },
            {
              "id": "e820d5fd-d900-4b00-82d3-773a9eafe6a6",
              "name": "abstract",
              "type": "string",
              "value": "={{ $json.properties.abstract.rich_text[0].text.content }}"
            },
            {
              "id": "1e5e2d1b-ae9b-4a7a-b6c3-aa4b80751a61",
              "name": "abstract_clean",
              "type": "string",
              "value": "={{ \n  String($json.properties.abstract.rich_text[0].text.content || $json.summary)\n    .replace(/\\\\\\\\n/g, ' ')  // limpia \"\\n\" escapado\n    .replace(/\\\\n/g, ' ')    // limpia \"\\n\" si llega doble escapado\n    .replace(/\\n/g, ' ')     // limpia saltos reales\n    .replace(/\\s+/g, ' ')    // colapsa espacios m\u00faltiples\n    .trim() \n}}"
            },
            {
              "id": "eece341f-e5cc-4d2f-8c0b-66796d7e5c45",
              "name": "url_pdf",
              "type": "string",
              "value": "={{ (() => {\n     const src = ($json.link || $json.properties.arxiv_id.rich_text[0].text.content || '').trim();\n     if (!src) return '';\n     // Cambia /abs/ por /pdf/\n     let u = src.replace('/abs/', '/pdf/');\n     // Asegura protocolo\n     if (!/^https?:\\/\\//i.test(u)) u = 'https://' + u.replace(/^\\/+/, '');\n     // A\u00f1ade .pdf si no lo tiene\n     if (!u.toLowerCase().endsWith('.pdf')) u += '.pdf';\n     return u;\n})() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "df174b58-d4a9-4bcf-b35d-ef564521408d",
      "name": "Register to Notion Database",
      "type": "n8n-nodes-base.notion",
      "position": [
        1840,
        400
      ],
      "parameters": {
        "title": "={{ $json.title }}",
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "2992729c-bda2-8008-950c-f617082228a1",
          "cachedResultUrl": "https://www.notion.so/2992729cbda28008950cf617082228a1",
          "cachedResultName": "ARXIV"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "arxiv_id|url",
              "urlValue": "={{ $json.arxiv_id }}"
            },
            {
              "key": "authors|rich_text",
              "textContent": "={{ $json.authors }}"
            },
            {
              "key": "published|date",
              "date": "={{ $json.published }}",
              "timezone": "US/Eastern"
            },
            {
              "key": "abstract|rich_text",
              "textContent": "={{ $json.abstract_clean }}"
            },
            {
              "key": "url_pdf|url",
              "urlValue": "={{ $json.url_pdf }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "2e7d8869-f34c-4ba8-a1f3-4e4721cf6916",
      "name": "Freeze page_id",
      "type": "n8n-nodes-base.set",
      "position": [
        2048,
        400
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "2b4c8c3c-d029-4d03-a74b-85c361e7c0ec",
              "name": "=page_id",
              "type": "string",
              "value": "={{ $json.id }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "78861c59-f436-4959-9f77-2c919adf512d",
      "name": "Append a block (adding \"block\" subtitle)",
      "type": "n8n-nodes-base.notion",
      "position": [
        2256,
        400
      ],
      "parameters": {
        "blockId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "blockUi": {
          "blockValues": [
            {
              "type": "heading_2",
              "textContent": "Deep Research Summary"
            }
          ]
        },
        "resource": "block"
      },
      "typeVersion": 2.2
    },
    {
      "id": "d20e2281-2f80-4ac9-ab46-fa170379c4f8",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2320,
        32
      ],
      "parameters": {
        "text": "=<b>{{ $('Register to Notion Database').item.json.property_title }}</b>\n\n<b>{{ $('Register to Notion Database').item.json.property_published.start }}</b>\n\n<b>{{ $('Register to Notion Database').item.json.property_authors }}</b>\n\n<em>ABSTRACT (short):</em>\n{{ $('Edit Fields for Notion (incl. pdf)').item.json.abstract_clean }}\n\n<b>Links</b>\n\u2022 arXiv: {{ $json.url || $json.arxiv_id || '' }}\n\u2022 Complete paper (pdf): {{ $json.property_url_pdf || '' }}\n\u2022 Deep Summary (Notion): {{ $('Register to Notion Database').item.json.url }}\n",
        "chatId": "=-1003277954309",
        "additionalFields": {
          "parse_mode": "=HTML",
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ab41032c-3654-4ea5-83b3-3a690a597ed3",
      "name": "Clean page_id",
      "type": "n8n-nodes-base.set",
      "position": [
        2880,
        592
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d928dfb2-65a2-449e-8297-d458471a5075",
              "name": "=page_id",
              "type": "string",
              "value": "={{$json.page_id || $json.parent?.page_id || $json.page_id || $json.results?.[0]?.parent?.page_id || $json.id}}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "276f2649-c421-4913-86e0-3789d7187a24",
      "name": "Analyze doc (Prompt Ultra-Pro)",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "maxTries": 2,
      "position": [
        3072,
        720
      ],
      "parameters": {
        "text": "You are an elite AI research analyst and science communicator.\n\nYour task:\nDeeply read and understand the attached research PDF and generate a structured, high-value explainer that will be stored inside a Notion child page.\n\nAudience:\n- Curious, intelligent founders and professionals\n- Not technical experts, but can understand advanced concepts when clearly explained\n\nPrimary mission:\nExplain the paper\u2019s ideas, meaning, and significance \u2014 NOT the metadata.\nDo NOT repeat title, authors, arXiv ID, year, or publication info. We already store those separately.\n\nTone:\n- Clear, sharp, human, insightful\n- Like Karpathy + Paul Graham + Ali Abdaal\n- No fluff, no hype, no academic filler\n- Metaphors and intuitive explanations welcome\n- Convey meaning and understanding, not jargon\n\nCONTENT YOU MUST PRODUCE (as narrative with brief bold section headers inside text):\n\n1) 3\u20135 core insights (executive brief)\n2) Core idea and motivation \u2014 explained simply\n3) Why this research matters now (context & importance)\n4) Key innovations & contributions\n5) Method \u2014 explained step-by-step in plain language\n6) Math / theory intuition (no formulas \u2014 explain what they *mean*)\n7) Experiments and evaluation \u2014 what was tested and why it matters\n8) Key results & what they prove (plain English significance)\n9) Limitations / where it may fail\n10) Real-world impact and applications\n11) Future work / open questions\n12) Closing takeaway \u2014 2-3 sentences summarizing the big picture\n\nOutput rules:\n- DO NOT repeat metadata (title, authors, arXiv ID, etc.)\n- DO NOT output anything outside JSON\n- NO chunk > 1900 characters\n- NO markdown blocks, no backticks inside chunks\n- Make the text feel like a human expert teaching\n\nReturn only valid JSON in this format:\n\n{\n  \"chunks\": [\n    \"chunk1 <= 1900 chars\",\n    \"chunk2 <= 1900 chars\",\n    \"...if needed\"\n  ]\n}\n\nBegin your analysis now.\n",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-pro",
          "cachedResultName": "models/gemini-2.5-pro"
        },
        "options": {},
        "resource": "document",
        "documentUrls": "={{ $('Edit Fields for Notion (incl. pdf)').item.json.url_pdf }}"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1
    },
    {
      "id": "86715411-218c-4910-99de-159a0270c1b1",
      "name": "Merge page_id & Summary",
      "type": "n8n-nodes-base.merge",
      "position": [
        3264,
        608
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "89127dd3-5486-430c-9677-e44f36269460",
      "name": "Debug before append",
      "type": "n8n-nodes-base.set",
      "position": [
        3744,
        608
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a1465705-0160-46c2-8d10-50beede0eb11",
              "name": "page_id",
              "type": "string",
              "value": "={{$json.db_page_id || $json.page_id}}"
            },
            {
              "id": "9c3f2c3c-1139-4919-a45b-46db0f62659d",
              "name": "slice",
              "type": "string",
              "value": "={{$json.slice}}"
            },
            {
              "id": "f9db996a-ae16-4f8c-89ac-02f7bcc9dcee",
              "name": "=dbg_page_id",
              "type": "string",
              "value": "={{$json.page_id}}"
            },
            {
              "id": "ab9d751f-bd50-45d5-a560-65a8b8650ff1",
              "name": "dbg_slice_len",
              "type": "string",
              "value": "={{$json.slice.length}}"
            },
            {
              "id": "50a5acfd-0878-4340-8ba6-c996b5132dc6",
              "name": "dbg_chunk",
              "type": "string",
              "value": "={{$json.chunk_index}}"
            },
            {
              "id": "0c89088e-fd2b-4286-a1c3-f737efde3ae0",
              "name": "dbg_slice_index",
              "type": "string",
              "value": "={{$json.slice_index}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "f12f15de-1c28-431b-8102-a54da0541b80",
      "name": "Append chunks as blocks",
      "type": "n8n-nodes-base.notion",
      "onError": "continueRegularOutput",
      "position": [
        4048,
        608
      ],
      "parameters": {
        "blockId": {
          "__rl": true,
          "mode": "id",
          "value": "={{$json.page_id}}"
        },
        "blockUi": {
          "blockValues": [
            {
              "textContent": "={{$json.slice || '\u2014'}}\n"
            }
          ]
        },
        "resource": "block"
      },
      "typeVersion": 2.2
    },
    {
      "id": "710ef57c-cb3c-460b-a957-7aae51ddd704",
      "name": "Sticky Note27",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4256,
        672
      ],
      "parameters": {
        "width": 400,
        "height": 320,
        "content": "## 11. Wait and Start Over\nAfter saving a paper's **Deep Research Summary**, wait and start over with remaining ones."
      },
      "typeVersion": 1
    },
    {
      "id": "f3f8e985-9250-499f-a0e3-8b41bb94b55f",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -208,
        752
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "eb2b5824-d60b-4e7a-94da-1e16ac3e8514",
      "name": "Sticky Note34",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        640
      ],
      "parameters": {
        "color": 6,
        "width": 272,
        "height": 304,
        "content": "## Manual Trigger\nUse this trigger to test the workflow"
      },
      "typeVersion": 1
    },
    {
      "id": "897206e4-e3e8-4a92-8592-e90fc1a7d648",
      "name": "Sticky Note31",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -272,
        1104
      ],
      "parameters": {
        "color": 3,
        "width": 4992,
        "height": 80,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "9bba5011-5203-4b14-b456-d4b1fc46d202",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1072,
        -160
      ],
      "parameters": {
        "width": 652,
        "height": 1248,
        "content": "## Try It Out\n\n### What this template does (end-to-end)\n* Fetches new AI papers from arXiv.\n* Filters by last 24h time window and de-duplicates papers.\n* Creates a Notion database page per paper and stores key fields (+ the PDF link).\n* Generates a plain-English **Deep Research** summary from the PDF (Gemini) and saves it as child blocks in the same Notion page.\n* Posts a Telegram update at **08:00** with title + link(s) + a short abstract, including a link to the Deep Research in Notion.\n\n### Run it now\n* Click **Execute workflow** to test manually.\n* When ready, enable the **Scheduled Trigger** (08:00 local by default).\n\n### Configure these nodes (minimal)\n* **HTTP Request** \u2192 arXiv feed/query (e.g., your AI categories or keywords).\n* **Filter by last 24h** -> you can edit HOURS in the code if you need a wider window.\n* **Result Cleaner** \u2192 keeps first occurrence of each `arxiv_id`.\n* **Register in Notion**\n  * Notion account (integration added to the target DB)\n  * Database ID and property mapping (`name`, `url`, `abstract`, `authors`, `tags`, `pdf_url`, `arxiv_id`, `status`).\n* **Freeze page_id** \u2192 carries the created Notion `page_id` forward.\n* **Analyze doc (Gemini)** \u2192 set your model + API key (env var recommended).\n* **Code (Parse Gemini JSON in chunks)** \u2192 splits the model output into \u22641900-char slices.\n* **Append chunks (Notion)** \u2192 appends each slice under the same `page_id`.\n* **Send to Telegram** \u2192 bot token + `chat_id` (channel or group).\n\n### What you\u2019ll see\n* One Notion page per paper with metadata, PDF link, and a **Deep Research** section composed of multiple rich-text blocks.\n* One Telegram post per paper with the Notion page link and the PDF.\n\n### Notes & limits\n* The summarizer reads the PDF and returns a structured explainer (core insights, method, results, limits, applications).\n* Chunking ensures each block \u22641900 chars to avoid Notion/API errors.\n* If you expect many items, keep **Wait** enabled to pace API calls.\n\n### Requirements\n* Notion integration with access to your target database.\n* Telegram bot + channel/group `chat_id`.\n* Gemini API key and model (e.g., `gemini-2.5-pro`).\n* Optional: environment variables for secrets and IDs.\n\n### Troubleshooting\n* Empty summaries \u2192 check PDF URL reachability and Gemini key/model.\n* \"Page not found\" on append \u2192 verify `page_id` is set before Append.\n* Duplicates \u2192 confirm `arxiv_id` exists and the dedupe node is before Notion create.\n* Telegram not posting \u2192 bot must be **admin** of the channel.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d80aa1ea-5332-46bb-a03c-89a5655039aa",
      "name": "End Telegram branch (no further actions)",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2544,
        32
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "84efcd13-b37e-47fd-95f1-385181986bb3",
      "name": "Process each paper (Gemini + Notion loop)",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        2592,
        480
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "88d53b3c-e277-4cc9-91f9-bc083e41314c",
      "name": "Return to paper loop (next paper)",
      "type": "n8n-nodes-base.noOp",
      "position": [
        4496,
        784
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "1abceb48-d007-4eaf-83ab-8234ecd6db56",
      "name": "Delay between paper summaries",
      "type": "n8n-nodes-base.wait",
      "position": [
        4320,
        784
      ],
      "parameters": {
        "amount": 0.4
      },
      "typeVersion": 1.1
    },
    {
      "id": "9a6e800c-1fd2-45c3-ac36-2cfb95c259bc",
      "name": "Prepare Notion payload (JSON)",
      "type": "n8n-nodes-base.code",
      "position": [
        1360,
        400
      ],
      "parameters": {
        "jsCode": "return items.map(item => ({\n  json: {\n    parent: { database_id: \"TU_DATABASE_ID\" },\n    properties: {\n      title: {\n        title: [{ text: { content: item.json.title || \"Sin t\u00edtulo\" } }]\n      },\n      arxiv_id: {\n        rich_text: [{ text: { content: item.json.arxiv_id || \"\" } }]\n      },\n      abstract: {\n        rich_text: [{ text: { content: item.json.summary || \"\" } }]\n      },\n      authors: {\n        rich_text: [{ text: { content: item.json.authors || \"\" } }]\n      },\n      categories: {\n        rich_text: [{ text: { content: item.json.categories || \"\" } }]\n      },\n      published: {\n        date: { start: item.json.published || null }\n      },\n      link: {\n        url: item.json.link || null\n      }\n    }\n  }\n}));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "34727c62-2923-4868-82c1-037fb449615f",
      "name": "Filter recent papers (last 24h)",
      "type": "n8n-nodes-base.code",
      "position": [
        832,
        400
      ],
      "parameters": {
        "jsCode": "// === Configuraci\u00f3n ===\nconst HOURS = 24; // Cambia a 48 o 72 si quieres ampliar el rango\nconst now = new Date();\nconst threshold = new Date(now.getTime() - HOURS * 60 * 60 * 1000);\n\n// === Utilidad para limpiar texto ===\nconst get = v => Array.isArray(v) ? String(v[0] ?? '').trim() : String(v ?? '').trim();\n\n// === Procesar cada paper ===\nconst out = [];\n\nfor (const it of items) {\n  const e = it.json;\n\n  // Convertimos fechas\n  const published = new Date(get(e.published || e.updated));\n  if (isNaN(published) || published < threshold) continue; // filtra los m\u00e1s antiguos\n\n  // --- Autores ---\n  const authorList = Array.isArray(e.author) ? e.author : [e.author];\n  const authors = authorList\n    .filter(Boolean)\n    .map(a => get(a.name))\n    .join(', ');\n\n  // --- Categor\u00edas ---\n  const categoryList = Array.isArray(e.category) ? e.category : [e.category];\n  const categories = categoryList\n    .filter(Boolean)\n    .map(c => c?.['@_term'] || c?.['$'] || '')\n    .filter(Boolean)\n    .join(', ');\n\n  // --- A\u00f1adir al resultado ---\n  out.push({\n    json: {\n      arxiv_id: get(e.id),\n      title: get(e.title),\n      summary: get(e.summary),\n      authors,\n      categories,\n      published: published.toISOString(),\n      link: get(e.id)\n    }\n  });\n}\n\nreturn out;\n"
      },
      "typeVersion": 2
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Format Conversor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean page_id": {
      "main": [
        [
          {
            "node": "Analyze doc (Prompt Ultra-Pro)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge page_id & Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Results": {
      "main": [
        [
          {
            "node": "Filter recent papers (last 24h)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Freeze page_id": {
      "main": [
        [
          {
            "node": "Append a block (adding \"block\" subtitle)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Conversor": {
      "main": [
        [
          {
            "node": "Split Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Debug before append": {
      "main": [
        [
          {
            "node": "Append chunks as blocks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a text message": {
      "main": [
        [
          {
            "node": "End Telegram branch (no further actions)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append chunks as blocks": {
      "main": [
        [
          {
            "node": "Delay between paper summaries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dedupe with Static Data": {
      "main": [
        [
          {
            "node": "Prepare Notion payload (JSON)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge page_id & Summary": {
      "main": [
        [
          {
            "node": "Code (Parse Gemini JSON in chunks)7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scheduled Daily Trigger": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Register to Notion Database": {
      "main": [
        [
          {
            "node": "Freeze page_id",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delay between paper summaries": {
      "main": [
        [
          {
            "node": "Return to paper loop (next paper)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Notion payload (JSON)": {
      "main": [
        [
          {
            "node": "Edit Fields for Notion (incl. pdf)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze doc (Prompt Ultra-Pro)": {
      "main": [
        [
          {
            "node": "Merge page_id & Summary",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Filter recent papers (last 24h)": {
      "main": [
        [
          {
            "node": "Dedupe with Static Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Return to paper loop (next paper)": {
      "main": [
        [
          {
            "node": "Process each paper (Gemini + Notion loop)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields for Notion (incl. pdf)": {
      "main": [
        [
          {
            "node": "Register to Notion Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code (Parse Gemini JSON in chunks)7": {
      "main": [
        [
          {
            "node": "Debug before append",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append a block (adding \"block\" subtitle)": {
      "main": [
        [
          {
            "node": "Process each paper (Gemini + Notion loop)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process each paper (Gemini + Notion loop)": {
      "main": [
        [],
        [
          {
            "node": "Clean page_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}