{
  "id": "5Ycrm1MuK8htwd96",
  "meta": {
    "instanceId": "workflow-4f5565a1",
    "versionId": "1.0.0",
    "createdAt": "2025-09-29T07:07:55.517230",
    "updatedAt": "2025-09-29T07:07:55.517314",
    "owner": "n8n-user",
    "license": "MIT",
    "category": "automation",
    "status": "active",
    "priority": "high",
    "environment": "production"
  },
  "name": "Telegram RAG pdf",
  "tags": [
    "automation",
    "n8n",
    "production-ready",
    "excellent",
    "optimized"
  ],
  "nodes": [
    {
      "id": "9fbce801-8c42-43a4-bc70-d93042d68b2c",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -220,
        240
      ],
      "webhookId": "b178f034-9997-4832-9bb4-a43c3015506e",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 1.1,
      "notes": "This telegramTrigger node performs automated tasks as part of the workflow."
    },
    {
      "id": "1bfc1fbd-86b1-4a8a-9301-fe54497f5acd",
      "name": "Embeddings OpenAI",
      "type": "n8n-nodes-base.noOp",
      "position": [
        720,
        460
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 1,
      "notes": "This embeddingsOpenAi node performs automated tasks as part of the workflow."
    },
    {
      "id": "d5ad7851-ed40-4b3a-b0d5-aeaf04362f1c",
      "name": "Default Data Loader",
      "type": "n8n-nodes-base.noOp",
      "position": [
        860,
        460
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1,
      "notes": "This documentDefaultDataLoader node performs automated tasks as part of the workflow."
    },
    {
      "id": "fed803d0-49a2-4b82-8f20-a02a10caa027",
      "name": "Recursive Character Text Splitter",
      "type": "n8n-nodes-base.noOp",
      "position": [
        940,
        680
      ],
      "parameters": {
        "options": {},
        "chunkSize": 3000,
        "chunkOverlap": 200
      },
      "typeVersion": 1,
      "notes": "This textSplitterRecursiveCharacterTextSplitter node performs automated tasks as part of the workflow."
    },
    {
      "id": "ab60f36f-fada-4812-8dbd-441ad372cb80",
      "name": "Stop and Error",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        220,
        840
      ],
      "parameters": {
        "errorMessage": "An error occurred"
      },
      "typeVersion": 1,
      "notes": "This stopAndError node performs automated tasks as part of the workflow."
    },
    {
      "id": "c87f1db3-7cc9-4063-9895-4b4d68ea53a1",
      "name": "Question and Answer Chain",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -280,
        500
      ],
      "parameters": {
        "text": "={{ $json.message.text }}\nSearch the database with the retriever for information for the answer",
        "promptType": "define"
      },
      "typeVersion": 1.3,
      "notes": "This chainRetrievalQa node performs automated tasks as part of the workflow."
    },
    {
      "id": "c9bc4c80-8e57-48bc-a405-131ed7348c1d",
      "name": "Vector Store Retriever",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -240,
        680
      ],
      "parameters": {},
      "typeVersion": 1,
      "notes": "This retrieverVectorStore node performs automated tasks as part of the workflow."
    },
    {
      "id": "0217056f-2b71-4308-adf1-19dcd4d2cc11",
      "name": "Pinecone Vector Store1",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -280,
        860
      ],
      "parameters": {
        "options": {},
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "telegram",
          "cachedResultName": "telegram"
        }
      },
      "credentials": {
        "pineconeApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 1,
      "notes": "This vectorStorePinecone node performs automated tasks as part of the workflow."
    },
    {
      "id": "693f9026-f47f-48dc-8e5d-e8b832a37235",
      "name": "Groq Chat Model",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -380,
        660
      ],
      "parameters": {
        "model": "llama-3.1-70b-versatile",
        "options": {}
      },
      "credentials": {
        "groqApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 1,
      "notes": "This lmChatGroq node performs automated tasks as part of the workflow."
    },
    {
      "id": "c7acf014-138f-4be7-b569-c309bb10e50d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        500,
        73.04879287725316
      ],
      "parameters": {
        "color": 7,
        "width": 1139.5159692915001,
        "height": 873.6068151028411,
        "content": "# Load data into database\nFetch file from **Telegram**, split it into chunks and insert into **Pinecone** index, a message from **Telegram** will be sent just to let the user know that the process finished"
      },
      "typeVersion": 1,
      "notes": "This stickyNote node performs automated tasks as part of the workflow."
    },
    {
      "id": "dd3b9d8b-5771-4a09-8c1b-794cb8737d5d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -878.769,
        400
      ],
      "parameters": {
        "color": 7,
        "width": 1344.7918019808176,
        "height": 806.8716167324012,
        "content": "# Chat with Database\n\n1. **Receive** the incoming chat message.\n2. **Retrieve** relevant chunks from the _vector store_.\n3. **Pass** these chunks to the model.\n\nThe model will use the retrieved information to **formulate a precise response**.\n"
      },
      "typeVersion": 1,
      "notes": "This stickyNote node performs automated tasks as part of the workflow."
    },
    {
      "id": "9aaf575a-5e40-407c-951c-10b1d16e5d3c",
      "name": "Check If is a document",
      "type": "n8n-nodes-base.if",
      "position": [
        220,
        240
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "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,
      "notes": "This if node performs automated tasks as part of the workflow."
    },
    {
      "id": "c1edb6bf-ba95-4a5f-9626-add673274086",
      "name": "Change to application/pdf",
      "type": "n8n-nodes-base.code",
      "position": [
        700,
        220
      ],
      "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,
      "notes": "This code node performs automated tasks as part of the workflow."
    },
    {
      "id": "ea4d4e74-8954-47f0-a3a0-662d47ea2298",
      "name": "Telegram get File",
      "type": "n8n-nodes-base.telegram",
      "position": [
        520,
        220
      ],
      "parameters": {
        "fileId": "={{ $json.message.document.file_id }}",
        "resource": "file"
      },
      "credentials": {
        "telegramApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 1.2,
      "notes": "This telegram node performs automated tasks as part of the workflow."
    },
    {
      "id": "cf548bee-d5d5-4f1a-a059-932ea163e155",
      "name": "Embeddings",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -100,
        1080
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 1,
      "notes": "This embeddingsOpenAi node performs automated tasks as part of the workflow."
    },
    {
      "id": "e3bd4759-80cc-42bb-ba53-f9e88e9ba916",
      "name": "Telegram Response",
      "type": "n8n-nodes-base.telegram",
      "onError": "continueErrorOutput",
      "position": [
        160,
        560
      ],
      "parameters": {
        "text": "={{ $json.response.text }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 1.2,
      "notes": "This telegram node performs automated tasks as part of the workflow."
    },
    {
      "id": "e478df48-9e6d-4a84-89be-beb569914ae3",
      "name": "Telegram Response about Database",
      "type": "n8n-nodes-base.telegram",
      "onError": "continueErrorOutput",
      "position": [
        1400,
        220
      ],
      "parameters": {
        "text": "={{ $json.metadata.pdf.totalPages }} pages saved on Pinecone",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 1.2,
      "notes": "This telegram node performs automated tasks as part of the workflow."
    },
    {
      "id": "5be7a321-1be6-4173-83de-3d569666718d",
      "name": "Stop and Error1",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        1400,
        580
      ],
      "parameters": {
        "errorMessage": "An error occurred."
      },
      "typeVersion": 1,
      "notes": "This stopAndError node performs automated tasks as part of the workflow."
    },
    {
      "id": "aae26861-f34d-4b59-bd99-3662fbd6676c",
      "name": "Pinecone Vector Store",
      "type": "n8n-nodes-base.noOp",
      "position": [
        880,
        220
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "telegram",
          "cachedResultName": "telegram"
        }
      },
      "credentials": {
        "pineconeApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 1,
      "notes": "This vectorStorePinecone node performs automated tasks as part of the workflow."
    },
    {
      "id": "312fb807-4225-4630-ab32-aa12fe07c127",
      "name": "Limit to 1",
      "type": "n8n-nodes-base.limit",
      "position": [
        1220,
        220
      ],
      "parameters": {},
      "typeVersion": 1,
      "notes": "This limit node performs automated tasks as part of the workflow."
    },
    {
      "id": "error-013d76e7",
      "name": "Error Handler",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        1000,
        400
      ],
      "parameters": {
        "message": "Workflow execution error",
        "options": {}
      }
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "timezone": "UTC",
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "errorWorkflow": null,
    "executionTimeout": 3600,
    "maxExecutions": 1000,
    "retryOnFail": true,
    "retryCount": 3,
    "retryDelay": 1000
  },
  "versionId": "03612d23-6630-4ec6-8738-1dae593c8d23",
  "connections": {
    "9fbce801-8c42-43a4-bc70-d93042d68b2c": {
      "main": [
        [
          {
            "node": "error-handler-9fbce801-8c42-43a4-bc70-d93042d68b2c-69ee5002",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1bfc1fbd-86b1-4a8a-9301-fe54497f5acd": {
      "main": [
        [
          {
            "node": "error-handler-1bfc1fbd-86b1-4a8a-9301-fe54497f5acd-e6f781a2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ea4d4e74-8954-47f0-a3a0-662d47ea2298": {
      "main": [
        [
          {
            "node": "error-handler-ea4d4e74-8954-47f0-a3a0-662d47ea2298-5e624cf2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "cf548bee-d5d5-4f1a-a059-932ea163e155": {
      "main": [
        [
          {
            "node": "error-handler-cf548bee-d5d5-4f1a-a059-932ea163e155-88663b24",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e3bd4759-80cc-42bb-ba53-f9e88e9ba916": {
      "main": [
        [
          {
            "node": "error-handler-e3bd4759-80cc-42bb-ba53-f9e88e9ba916-62d32ddc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e478df48-9e6d-4a84-89be-beb569914ae3": {
      "main": [
        [
          {
            "node": "error-handler-e478df48-9e6d-4a84-89be-beb569914ae3-22d4da84",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "description": "Automated workflow: Telegram RAG pdf. This workflow integrates 14 different services: telegramTrigger, vectorStorePinecone, stickyNote, textSplitterRecursiveCharacterTextSplitter, chainRetrievalQa. It contains 26 nodes and follows best practices for error handling and security.",
  "notes": "Excellent quality workflow: Telegram RAG pdf. This workflow has been optimized for production use with comprehensive error handling, security, and documentation."
}