Asistente de aprendizaje de IA para Telegram basado en RAG (usando MongoDB y Google Drive)

Avanzado

Este es unautomatización que contiene 17 nodos.Utiliza principalmente nodos como Telegram, FormTrigger, GoogleDrive, Agent, TelegramTrigger. Usar RAG, Gemini, Telegram y MongoDB para crear un asistente de aprendizaje de hechos

Requisitos previos
  • Bot Token de Telegram
  • Credenciales de API de Google Drive
  • Clave de API de Google Gemini
  • Cadena de conexión de MongoDB

Categoría

-
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
{
  "name": "RAG-based AI Learning Assistant for Telegram using MongoDB and Google Drive",
  "tags": [],
  "nodes": [
    {
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -160,
        256
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1.1,
      "id": "Default-Data-Loader-0"
    },
    {
      "name": "Al recibir mensaje de chat",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        96,
        -32
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.3,
      "id": "Al-recibir-mensaje-de-chat-1"
    },
    {
      "name": "File uploaded",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        -672,
        128
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "<GOOGLE_DRIVE_FOLDER_ID_WATCH>",
          "cachedResultUrl": "https://drive.google.com/drive/folders/<GOOGLE_DRIVE_FOLDER_ID_WATCH>",
          "cachedResultName": "YT"
        }
      },
      "credentials": {},
      "typeVersion": 1,
      "id": "File-uploaded-2"
    },
    {
      "name": "MongoDB Atlas Almacén de vectores - Insert",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreMongoDBAtlas",
      "position": [
        -240,
        48
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "mongoCollection": {
          "__rl": true,
          "mode": "list",
          "value": "<MONGO_ATLAS_COLLECTION_NAME>",
          "cachedResultName": "<MONGO_ATLAS_COLLECTION_NAME>"
        },
        "vectorIndexName": "<MONGO_ATLAS_VECTOR_INDEX_NAME_INSERT>",
        "embeddingBatchSize": 10
      },
      "credentials": {},
      "typeVersion": 1.3,
      "id": "MongoDB-Atlas-Almac-n-de-vectores---Insert-3"
    },
    {
      "name": "MongoDB Atlas Almacén de vectores - Retrieve",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreMongoDBAtlas",
      "position": [
        544,
        224
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "options": {},
        "mongoCollection": {
          "__rl": true,
          "mode": "list",
          "value": "<MONGO_ATLAS_COLLECTION_NAME>",
          "cachedResultName": "<MONGO_ATLAS_COLLECTION_NAME>"
        },
        "toolDescription": "Tool for AI Agent: Use this to search and retrieve relevant documents from the vector store to answer questions or analyze or fulfill tasks.",
        "vectorIndexName": "<MONGO_ATLAS_VECTOR_INDEX_NAME_RETRIEVE>"
      },
      "credentials": {},
      "typeVersion": 1.3,
      "id": "MongoDB-Atlas-Almac-n-de-vectores---Retrieve-4"
    },
    {
      "name": "Modelo de chat Google Gemini",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        272,
        256
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-flash-lite"
      },
      "credentials": {},
      "typeVersion": 1,
      "id": "Modelo-de-chat-Google-Gemini-5"
    },
    {
      "name": "Download file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -480,
        128
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "list",
          "value": "<GOOGLE_DRIVE_FILE_ID_DOWNLOAD>",
          "cachedResultUrl": "https://docs.google.com/document/d/<GOOGLE_DRIVE_FILE_ID_DOWNLOAD>/edit?usp=drivesdk",
          "cachedResultName": "History of modern India Spectrum 2"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {},
      "typeVersion": 3,
      "id": "Download-file-6"
    },
    {
      "name": "RAG Agente",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        384,
        32
      ],
      "parameters": {
        "text": "={{ $json.message.text }}{{ $json.chatInput }}",
        "options": {
          "systemMessage": "You are an Expert UPSC Examination Analyst and Study Assistant. Your primary function is to accurately, comprehensively, and analytically answer user queries related to the Union Public Service Commission (UPSC) Civil Services Examination (CSE).\n\nCore Directives and Persona\nExpertise: You are a master of the UPSC syllabus, exam patterns, current affairs relevance, and interdisciplinary analysis required for the Mains and Prelims examinations.\n\nRAG Mandate: You must utilize the context retrieved from the uploaded documents/knowledge base via the Retrieval-Augmented Generation (RAG) system to formulate your answers.\n\nSource Usage: Answer the query based primarily on the provided documents. Do not hallucinate or introduce information from your general training knowledge if it is contradicted by the documents.\n\nResponse Rules\nComprehensiveness & Depth: Provide answers that are deep, well-structured, and suitable for a high-level competitive exam like UPSC.\n\nAnalytical Approach: If the query asks for analysis, evaluation, comparison, or critical assessment, you must not simply restate facts. Instead, synthesize and analyze the information from the documents to provide a nuanced, insightful, and well-reasoned argument, as an expert would.\n\nSynthesis over Quotation: Do not use direct quotes or phrases like \"according to the document,\" \"the knowledge base states,\" or \"as per the database.\" Integrate the information naturally into a coherent and original answer.\n\nFormatting: Structure your response using clear headings, subheadings, and bullet points where appropriate to enhance readability for an examiner.\n\nLanguage and Tone: Maintain a formal, objective, and authoritative tone suitable for an academic and expert-level response.\n\nQuery Handling Procedure\nAnalyze Query: Determine the core subject, key concepts, and the type of response required (e.g., factual, analytical, comparative).\n\nRetrieve Context: Use the RAG tool to fetch the most relevant and complete information from the indexed documents.\n\nDraft Response: Synthesize the retrieved context and your domain expertise to craft a complete answer that adheres to all the above rules. "
        },
        "promptType": "define"
      },
      "typeVersion": 2.2,
      "id": "RAG-Agente-7"
    },
    {
      "name": "On File Upload",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -672,
        -32
      ],
      "parameters": {
        "options": {},
        "formTitle": "file upload",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "file",
              "acceptFileTypes": ".pdf, .csv, .jpg, .jpeg, .png"
            }
          ]
        }
      },
      "typeVersion": 2.3,
      "id": "On-File-Upload-8"
    },
    {
      "name": "Listen for Aspirant Question",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        96,
        96
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "chatIds": "@educationalch"
        }
      },
      "credentials": {},
      "typeVersion": 1.2,
      "id": "Listen-for-Aspirant-Question-9"
    },
    {
      "name": "Send Answer via Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        752,
        32
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "=<TELEGRAM_CHAT_ID>",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {},
      "retryOnFail": false,
      "typeVersion": 1.2,
      "id": "Send-Answer-via-Telegram-10"
    },
    {
      "name": "Convert Documents to Incrustaciones",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        -384,
        416
      ],
      "parameters": {},
      "credentials": {},
      "typeVersion": 1,
      "id": "Convert-Documents-to-Incrustaciones-11"
    },
    {
      "name": "Retrieve Documents from Incrustaciones",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        656,
        384
      ],
      "parameters": {},
      "credentials": {},
      "typeVersion": 1,
      "id": "Retrieve-Documents-from-Incrustaciones-12"
    },
    {
      "name": "Simple Memoria",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        400,
        240
      ],
      "parameters": {},
      "typeVersion": 1.3,
      "id": "Simple-Memoria-13"
    },
    {
      "name": "Nota adhesiva",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1440,
        -112
      ],
      "parameters": {
        "width": 672,
        "height": 1344,
        "content": "Who's it for?\nThis template is perfect for educational institutions, coaching centers (like UPSC, GMAT, or specialized technical training), internal corporate knowledge bases, and SaaS companies that need to provide instant, accurate, and source-grounded answers based on proprietary documents.\n\nIt's designed for users who want to leverage **Google Gemini's** powerful reasoning but ensure its answers are strictly factual and based only on their verified knowledge repository.\n\n## How it works / What it does\nThis workflow establishes a **Retrieval-Augmented Generation (RAG) pipeline** to build a secure, fact-based AI Agent. It operates in two main phases:\n\n**Knowledge Ingestion:** When a new document (e.g., a PDF, lecture notes, or policy manual) is uploaded via a **form** or **Google Drive**, the **Embeddings Google Gemini** node converts the content into numerical vectors. These vectors are then stored in a secure **MongoDB Atlas Vector Store**, creating a private knowledge base.\n\n**AI Query & Response:** A user asks a question via **Telegram**. The **RAG Agent** uses the question to perform a semantic search on the **MongoDB Vector Store**, retrieving the most relevant, source-specific passages. It then feeds this retrieved context to the **Google Gemini Chat Model** to generate a precise, factual answer, which is sent back to the user on Telegram.\n\nThis process ensures the agent never \"hallucinates\" or uses general internet knowledge, making the responses accurate and trustworthy.\n\n## Requirements\nTo use this template, you will need the following accounts and credentials:\n\n* **n8n Account**\n* **Google Gemini API Key:** For generating vector embeddings and powering the AI Agent.\n* **MongoDB Atlas Cluster:** A free-tier cluster is sufficient, configured with a Vector Search index.\n* **Telegram Bot:** A bot created via BotFather and a Chat ID where the bot will listen for and send messages.\n* **Google Drive Credentials** (if using the Google Drive ingestion path).\n\n## How to set up\n\n1.  **Set up MongoDB Atlas:** Create a free cluster and a database. Create a Vector Search Index on your collection to enable efficient searching.\n2.  **Configure Ingestion Path (Left Side):** Set up the **On File Upload** webhook or connect your **Google Drive** credentials. Configure the **Embeddings** and **MongoDB Insert** nodes with your credentials, collection name, and index name.\n3.  **Configure Chat Path (Right Side):** Set up the **Telegram Trigger** with your Bot Token/Webhook. Configure the **Google Gemini Chat Model** and the **MongoDB Retrieve** tool with your credentials/index details.\n4.  **Final Step:** Configure the **Send Answer via Telegram** node with your Bot Token and the Chat ID."
      },
      "typeVersion": 1,
      "id": "Nota-adhesiva-14"
    },
    {
      "name": "Nota adhesiva1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        -160
      ],
      "parameters": {
        "color": 4,
        "width": 816,
        "height": 752,
        "content": "Workflow 1: Knowledge Ingestion Pipeline\n(Triggers on file upload to form or Google Drive)"
      },
      "typeVersion": 1,
      "id": "Nota-adhesiva1-15"
    },
    {
      "name": "Nota adhesiva2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        -160
      ],
      "parameters": {
        "color": 6,
        "width": 896,
        "height": 768,
        "content": "Workflow 2: RAG Chatbot Query Pipeline\n(Triggers on question received via Telegram)"
      },
      "typeVersion": 1,
      "id": "Nota-adhesiva2-16"
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "RAG Agent": {
      "main": [
        [
          {
            "node": "Send-Answer-via-Telegram-10",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download-file-6": {
      "main": [
        [
          {
            "node": "MongoDB Atlas Vector Store - Insert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File-uploaded-2": {
      "main": [
        [
          {
            "node": "Download-file-6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "On-File-Upload-8": {
      "main": [
        [
          {
            "node": "MongoDB Atlas Vector Store - Insert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default-Data-Loader-0": {
      "ai_document": [
        [
          {
            "node": "MongoDB Atlas Vector Store - Insert",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB Atlas Vector Store1": {
      "ai_tool": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Listen-for-Aspirant-Question-9": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Documents to Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "MongoDB Atlas Vector Store - Insert",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve Documents from Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "MongoDB Atlas Vector Store1",
            "type": "ai_embedding",
            "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

¿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 nodos17
Categoría-
Tipos de nodos13
Descripción de la dificultad

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

Autor

Automation consultant with expertise in n8n, AI models, and workflow optimization. I help educators, startups, and businesses design scalable automation for content creation, exam prep, and process efficiency. Skilled in integrating Google Sheets, Telegram, and AI agents for impactful results.

Enlaces externos
Ver en n8n.io

Compartir este flujo de trabajo

Categorías

Categorías: 34