Desarrollado - Chat con PDF a través de Telegram

Avanzado

Este es unDocument Extraction, AI RAGflujo de automatización del dominio deautomatización que contiene 25 nodos.Utiliza principalmente nodos como If, Code, Limit, Telegram, StopAndError. Automatización del bot "chatear con PDF" en Telegram con Google Gemini y Pinecone

Requisitos previos
  • Bot Token de Telegram
  • Clave de API de Google Gemini
  • Clave de API de Pinecone
Vista previa del flujo de trabajo
Visualización de las conexiones entre nodos, con soporte para zoom y panorámica
Exportar flujo de trabajo
Copie la siguiente configuración JSON en n8n para importar y usar este flujo de trabajo
{
  "id": "ibBeVW3tpY92HUpA",
  "meta": {
    "instanceId": "1a54c41d9050a8f1fa6f74ca858828ad9fb97b9fafa3e9760e576171c531a787",
    "templateCredsSetupCompleted": true
  },
  "name": "Development Done - Chat with PDF via Telegram",
  "tags": [
    {
      "id": "0BJmSFs6EfUsyTWo",
      "name": "AI Internal",
      "createdAt": "2025-10-13T09:18:40.187Z",
      "updatedAt": "2025-10-13T09:18:40.187Z"
    }
  ],
  "nodes": [
    {
      "id": "c2e95dd8-961b-42d0-89cd-c31e810da2e8",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1584,
        944
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1
    },
    {
      "id": "4ed51c5d-23e5-4836-ad13-1a5fb48a0317",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        1648,
        1104
      ],
      "parameters": {
        "options": {},
        "chunkSize": 3000,
        "chunkOverlap": 200
      },
      "typeVersion": 1
    },
    {
      "id": "61db0aad-53de-4655-af01-7389c603137f",
      "name": "Detener y error",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        1936,
        1664
      ],
      "parameters": {
        "errorMessage": "An error occurred"
      },
      "typeVersion": 1
    },
    {
      "id": "b525eb52-d03f-4b1c-83c1-54855c4f2701",
      "name": "Question and Answer Cadena",
      "type": "@n8n/n8n-nodes-langchain.chainRetrievalQa",
      "position": [
        1008,
        1488
      ],
      "parameters": {
        "text": "=**INSTRUCTIONS:**\nYou are an expert RAG system. Answer the user's question ONLY using the provided context.\n\n1.  **Format Mode:** Your response MUST be formatted for Telegram's **HTML Parse Mode**.\n2.  **Formatting:**\n    * Use the bold tag (<b>) for all titles and key benefits.\n    * **CRITICAL LINE BREAK RULE:** For all line breaks, lists, and spacing, use the **newline character (\\n)** instead of any HTML tags like <br/> or <br>.\n    * Ensure the list is clearly structured with a single newline after each key item.\n\n**CONTEXT:** (The retrieved information follows here)\nSearch the database with the retriever for information for the answer\n\n**USER QUESTION:**\n{{ $json.message.text }}",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.3
    },
    {
      "id": "666d4966-aa07-4b39-9f9f-6101f6f70b27",
      "name": "Almacén de vectores Retriever",
      "type": "@n8n/n8n-nodes-langchain.retrieverVectorStore",
      "position": [
        1072,
        1680
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "2ea5294f-def8-43d6-84ca-5f4bbb4b8b4a",
      "name": "Pinecone Almacén de vectores1",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        992,
        1872
      ],
      "parameters": {
        "options": {},
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "telegram",
          "cachedResultName": "telegram"
        }
      },
      "credentials": {
        "pineconeApi": {
          "id": "Your_Pinecone_Credential_ID",
          "name": "PineconeApi account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d9e88d5c-096b-4a8f-8f17-fb8d1887c95f",
      "name": "Check If is a document",
      "type": "n8n-nodes-base.if",
      "position": [
        288,
        1344
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8839993b-9fe7-4e1e-a1cc-fe5de6b0bb62",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.message.document }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "18c639ce-3517-4f1f-b02a-a40ba4f1e14b",
      "name": "Change to application/pdf",
      "type": "n8n-nodes-base.code",
      "position": [
        1072,
        1072
      ],
      "parameters": {
        "jsCode": "// Função para modificar os metadados do arquivo binário\nfunction modifyBinaryMetadata(items) {\n for (const item of items) {\n if (item.binary && item.binary.data) {\n // Modifica o tipo MIME\n item.binary.data.mimeType = 'application/pdf';\n \n // Garante que o nome do arquivo termine com .pdf\n if (!item.binary.data.fileName.toLowerCase().endsWith('.pdf')) {\n item.binary.data.fileName += '.pdf';\n }\n \n // Atualiza o contentType no fileType (se existir)\n if (item.binary.data.fileType) {\n item.binary.data.fileType.contentType = 'application/pdf';\n }\n }\n }\n return items;\n}\n\n// Aplica a modificação e retorna os itens atualizados\nreturn modifyBinaryMetadata($input.all());"
      },
      "typeVersion": 2
    },
    {
      "id": "9abd0d30-8bfd-4a9c-94a7-ddfe919f22df",
      "name": "Telegram get File",
      "type": "n8n-nodes-base.telegram",
      "position": [
        752,
        1072
      ],
      "webhookId": "911eeb6b-d6c2-4d35-9433-24b7ec4886ef",
      "parameters": {
        "fileId": "={{ $json.message.document.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "Your_Telegram_Credential_ID",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f9af0cdd-7ea3-4e97-b53f-b65fdf4e9355",
      "name": "Telegram Response",
      "type": "n8n-nodes-base.telegram",
      "onError": "continueErrorOutput",
      "position": [
        1552,
        1488
      ],
      "webhookId": "a5b324f8-649f-4a3a-b26f-57cd0eb341ec",
      "parameters": {
        "text": "={{ $json.response.text }}",
        "chatId": "={{ $('Telegram Message Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "Your_Telegram_Credential_ID",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "048f9df4-1d15-4dcf-b853-52fe376434a0",
      "name": "Telegram Response about Database",
      "type": "n8n-nodes-base.telegram",
      "onError": "continueErrorOutput",
      "position": [
        2176,
        768
      ],
      "webhookId": "52437171-bdad-408c-bced-5ffec75b851d",
      "parameters": {
        "text": "={{ $json.metadata.pdf.totalPages }} pages saved on Pinecone",
        "chatId": "={{ $('Telegram Message Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "Your_Telegram_Credential_ID",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "36017ee3-5c44-469b-aad7-6a44faa57d32",
      "name": "Detener y error1",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        2448,
        864
      ],
      "parameters": {
        "errorMessage": "An error occurred."
      },
      "typeVersion": 1
    },
    {
      "id": "68b2dc90-c4a5-436f-9c17-e811974f333b",
      "name": "Pinecone Almacén de vectores",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        1488,
        768
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "telegram",
          "cachedResultName": "telegram"
        }
      },
      "credentials": {
        "pineconeApi": {
          "id": "Your_Pinecone_Credential_ID",
          "name": "PineconeApi account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fa712022-84c5-4c6d-aff1-dd71f73a7c20",
      "name": "Limitar to 1",
      "type": "n8n-nodes-base.limit",
      "position": [
        1904,
        768
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "71e24d0d-1e70-4c59-acf8-c7b73b5d33c5",
      "name": "Incrustaciones Google Gemini",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        1456,
        992
      ],
      "parameters": {
        "modelName": "models/gemini-embedding-001"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "Your_Gemini_Credential_ID",
          "name": "Your Google Gemini Credential Name"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0e7c375a-1aaa-459f-b8c2-13659f71320a",
      "name": "Incrustaciones Google Gemini1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        1024,
        2016
      ],
      "parameters": {
        "modelName": "models/gemini-embedding-001"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "Your_Gemini_Credential_ID",
          "name": "Your Google Gemini Credential Name"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "77d57e70-ef74-49eb-9019-6103a09ae391",
      "name": "Modelo de chat Google Gemini",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        880,
        1696
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "Your_Gemini_Credential_ID",
          "name": "Your Google Gemini Credential Name"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "92162e34-98e9-44ce-89a2-3ae058133a2d",
      "name": "Telegram Message Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -80,
        1344
      ],
      "webhookId": "b178f034-9997-4832-9bb4-a43c3015506e",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "Your_Telegram_Credential_ID",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "01da8891-6cb5-444e-8848-b34ee5af095c",
      "name": "Nota adhesiva",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        1056
      ],
      "parameters": {
        "color": 5,
        "width": 368,
        "height": 272,
        "content": "## 1. **Trigger & Router**\n**Task:** This node is the starting point. It listens for *any* message on the configured Telegram bot.\n\n**Output:**\n- **Text:** User's question (goes to the RAG chain).\n- **Document:** Binary file data (goes to the indexing process).\n\n**Next Stop:** Routes the message to the **\"Check If is a document\"** node."
      },
      "typeVersion": 1
    },
    {
      "id": "246059a8-fbc0-4f33-8cfd-7b33c87c7c02",
      "name": "Nota adhesiva1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        176,
        1056
      ],
      "parameters": {
        "color": 6,
        "width": 384,
        "height": 256,
        "content": "## 2. **Router Node**\n**Task:** Determines the message type to route the workflow.\n\n**Condition:** Checks if `{{ $json.message.document }}` **exists**.\n- **TRUE (Top Branch):** A file was uploaded. Proceed to **Indexing** (download the file).\n- **FALSE (Bottom Branch):** It is a plain text question. Proceed to **Querying** (run the RAG Chain)."
      },
      "typeVersion": 1
    },
    {
      "id": "6e03fbfc-58e6-4cd5-9ce9-82b0942a85e2",
      "name": "Nota adhesiva2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1824,
        944
      ],
      "parameters": {
        "width": 336,
        "height": 272,
        "content": "## 5. **Text Splitter**\n**Task:** Breaks the large PDF text into small, manageable chunks for indexing.\n\n**Configuration:**\n- **Chunk Size:** 3000\n- **Chunk Overlap:** 200 (Ensures context overlaps between chunks for better retrieval).\n\n**Purpose:** This configuration is key for **Retrieval-Augmented Generation (RAG)** accuracy."
      },
      "typeVersion": 1
    },
    {
      "id": "dd26c4da-207a-4b8e-90a4-4d2db8f1c529",
      "name": "Nota adhesiva3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1408,
        544
      ],
      "parameters": {
        "color": 3,
        "width": 368,
        "height": 336,
        "content": "## 4. **Embeddings (Indexing)**\n**Task:** Converts the split text chunks into high-dimensional numerical **vectors**.\n\n**Model:** `models/gemini-embedding-001`\n\n**Purpose:** These vectors are what the Pinecone database stores and uses for fast, semantic similarity searches when a user asks a question."
      },
      "typeVersion": 1
    },
    {
      "id": "ed22ea85-0803-4926-b118-fb4100bbf937",
      "name": "Nota adhesiva4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        1776
      ],
      "parameters": {
        "color": 2,
        "width": 368,
        "height": 256,
        "content": "## 6. **Vector Store: Indexing**\n**Task:** **Inserts** the Gemini embeddings and their associated text content into the configured Pinecone index (`telegram`).\n\n**Mode:** **`insert`**\n\n**Result:** The PDF is now fully indexed and searchable. The workflow then sends a confirmation to the user via **\"Telegram Response about Database\"**."
      },
      "typeVersion": 1
    },
    {
      "id": "a8cada20-ac48-4c8b-ab0f-de9b56d7d4a2",
      "name": "Nota adhesiva5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        1232
      ],
      "parameters": {
        "color": 3,
        "width": 416,
        "height": 368,
        "content": "## 7. **Core RAG Engine**\n**Task:** Generates the final, context-based answer.\n\n**Connections:**\n- **LLM:** Google Gemini Chat Model (for generation).\n- **Retriever:** Vector Store Retriever (for context lookup).\n\n**CRITICAL PROMPT:** The prompt strictly enforces:\n1.  Answer **ONLY** using provided context.\n2.  Response must be in **Telegram HTML Parse Mode** (`<b>` and `\\n`)."
      },
      "typeVersion": 1
    },
    {
      "id": "2688705d-3dae-4235-84b0-8b880bf4cdeb",
      "name": "Nota adhesiva6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1376,
        1264
      ],
      "parameters": {
        "color": 4,
        "width": 432,
        "height": 336,
        "content": "## 8. **Final Telegram Response**\n**Task:** Sends the RAG result back to the user.\n\n**Text Input:** `={{ $json.response.text }}`\n\n**CRITICAL SETTING:**\n- **Parse Mode:** **HTML**\nThis is required to properly display the bold tags (`<b>`) and newline characters (`\\n`) formatted by the Question and Answer Chain."
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "40963e46-0c2a-4887-9aaf-b9fafff20ab6",
  "connections": {
    "Limit to 1": {
      "main": [
        [
          {
            "node": "048f9df4-1d15-4dcf-b853-52fe376434a0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "f9af0cdd-7ea3-4e97-b53f-b65fdf4e9355": {
      "main": [
        [],
        [
          {
            "node": "Stop and Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "9abd0d30-8bfd-4a9c-94a7-ddfe919f22df": {
      "main": [
        [
          {
            "node": "18c639ce-3517-4f1f-b02a-a40ba4f1e14b",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "c2e95dd8-961b-42d0-89cd-c31e810da2e8": {
      "ai_document": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Store": {
      "main": [
        [
          {
            "node": "Limit to 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d9e88d5c-096b-4a8f-8f17-fb8d1887c95f": {
      "main": [
        [
          {
            "node": "9abd0d30-8bfd-4a9c-94a7-ddfe919f22df",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Question and Answer Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Store1": {
      "ai_vectorStore": [
        [
          {
            "node": "Vector Store Retriever",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "Vector Store Retriever": {
      "ai_retriever": [
        [
          {
            "node": "Question and Answer Chain",
            "type": "ai_retriever",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Question and Answer Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "92162e34-98e9-44ce-89a2-3ae058133a2d": {
      "main": [
        [
          {
            "node": "d9e88d5c-096b-4a8f-8f17-fb8d1887c95f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "18c639ce-3517-4f1f-b02a-a40ba4f1e14b": {
      "main": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini1": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Question and Answer Chain": {
      "main": [
        [
          {
            "node": "f9af0cdd-7ea3-4e97-b53f-b65fdf4e9355",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "048f9df4-1d15-4dcf-b853-52fe376434a0": {
      "main": [
        [],
        [
          {
            "node": "Stop and Error1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4ed51c5d-23e5-4836-ad13-1a5fb48a0317": {
      "ai_textSplitter": [
        [
          {
            "node": "c2e95dd8-961b-42d0-89cd-c31e810da2e8",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    }
  }
}
Preguntas frecuentes

¿Cómo usar este flujo de trabajo?

Copie el código de configuración JSON de arriba, cree un nuevo flujo de trabajo en su instancia de n8n y seleccione "Importar desde JSON", pegue la configuración y luego modifique la configuración de credenciales según sea necesario.

¿En qué escenarios es adecuado este flujo de trabajo?

Avanzado - Extracción de documentos, RAG de IA

¿Es de pago?

Este flujo de trabajo es completamente gratuito, puede importarlo y usarlo directamente. Sin embargo, tenga en cuenta que los servicios de terceros utilizados en el flujo de trabajo (como la API de OpenAI) pueden requerir un pago por su cuenta.

Información del flujo de trabajo
Nivel de dificultad
Avanzado
Número de nodos25
Categoría2
Tipos de nodos14
Descripción de la dificultad

Adecuado para usuarios avanzados, flujos de trabajo complejos con 16+ nodos

Autor
Intuz

Intuz

@intuz

Workflow automation can help automate your routine activities and help saves $$$, as well as hours of time. As a boutique tech consulting company, Intuz help businesses with custom AI/ML, AI Workflow Automations, and software development. Automate your business workflow for: Sales Marketing Accounting Finance Operations E-Commerce Customer Support Admin & Backoffice Logistics & Supply Chain

Enlaces externos
Ver en n8n.io

Compartir este flujo de trabajo

Categorías

Categorías: 34