AutomationFlowsAI & RAG › Create a Multi-modal Telegram Support Bot with Gpt-4 and Supabase RAG

Create a Multi-modal Telegram Support Bot with Gpt-4 and Supabase RAG

ByEzema Kingsley Chibuzo @kingsley on n8n.io

This n8n workflow turns your Telegram bot into a smart, multi-modal AI assistant that accepts text, documents, images, and audio messages, interprets them using OpenAI models, and responds instantly with context-aware answers. It integrates a Supabase vector database to store…

Event trigger★★★★★ complexityAI-powered51 nodesTelegram TriggerTelegramOpenAIHTTP RequestGoogle DriveDocument Default Data LoaderText Splitter Recursive Character Text SplitterOpenAI Chat
AI & RAG Trigger: Event Nodes: 51 Complexity: ★★★★★ AI nodes: yes Added:
Create a Multi-modal Telegram Support Bot with Gpt-4 and Supabase RAG — n8n workflow card showing Telegram Trigger, Telegram, OpenAI integration

This workflow corresponds to n8n.io template #5589 — we link there as the canonical source.

This workflow follows the Agent → Documentdefaultdataloader recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "pE6f3n6i6GUmSTgE",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Telegram AI Support Chatbot with Multi-Modal Inputs",
  "tags": [
    {
      "id": "Hsf1ZjQwJBHNaX1m",
      "name": "telegram",
      "createdAt": "2025-06-30T13:02:48.515Z",
      "updatedAt": "2025-06-30T13:02:48.515Z"
    },
    {
      "id": "b0xPsiva0fSoITZd",
      "name": "Ai agent",
      "createdAt": "2025-06-30T13:02:48.451Z",
      "updatedAt": "2025-06-30T13:02:48.451Z"
    },
    {
      "id": "fvM6EUbE34rR2wmT",
      "name": "customer support",
      "createdAt": "2025-06-30T13:02:48.420Z",
      "updatedAt": "2025-06-30T13:02:48.420Z"
    },
    {
      "id": "w2QpLU5syMOj79qo",
      "name": "chatbot",
      "createdAt": "2025-06-30T13:02:48.473Z",
      "updatedAt": "2025-06-30T13:02:48.473Z"
    }
  ],
  "nodes": [
    {
      "id": "2bcc338a-d519-42dd-bffd-9b5854b3a456",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        860,
        489.5
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ebc22166-b749-42c7-9d91-9fef170c6b65",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3896,
        1156.5
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "343b5290-d805-4136-a609-b12025df5339",
      "name": "Download Audio",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2840,
        500
      ],
      "parameters": {
        "fileId": "={{ $json.message.voice.file_id }}",
        "resource": "file"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8d5bd08c-5b59-4bff-97b1-ffca75262d1b",
      "name": "Translate to Text",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        3060,
        500
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "translate"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "3def7806-cf50-4fc8-a2c6-ea966cd0bd4e",
      "name": "Download PDF",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2620,
        1050
      ],
      "parameters": {
        "fileId": "={{ $json.message.document.file_id }}",
        "resource": "file"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "29624835-cc63-489f-8913-ece65ecf46f2",
      "name": "Download Image",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2180,
        1250
      ],
      "parameters": {
        "fileId": "={{ $json.message.document.file_id }}",
        "resource": "file"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "11755226-785d-4719-9d75-d82518ed615b",
      "name": "Fix mimeType",
      "type": "n8n-nodes-base.code",
      "position": [
        2400,
        1250
      ],
      "parameters": {
        "jsCode": "for (const item of items) {\n  if (item.binary && item.binary['data']) {\n    const fileName = item.binary['data'].fileName || '';\n    const lowerName = fileName.toLowerCase();\n\n    if (lowerName.endsWith('.png')) {\n      item.binary['data'].mimeType = 'image/png';\n    } else if (lowerName.endsWith('.jpg') || lowerName.endsWith('.jpeg')) {\n      item.binary['data'].mimeType = 'image/jpeg';\n    } else if (lowerName.endsWith('.webp')) {\n      item.binary['data'].mimeType = 'image/webp';\n    }\n  }\n}\nreturn items;\n\n\n\n\n"
      },
      "typeVersion": 2
    },
    {
      "id": "2d7fe3f6-d152-4b6d-8184-96f1073c73c6",
      "name": "Download Photo",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2180,
        700
      ],
      "parameters": {
        "fileId": "={{ $json.message.photo[0].file_id }}",
        "resource": "file"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "802f819c-9d11-4720-a63f-0d3bada509bf",
      "name": "Fix mimeType1",
      "type": "n8n-nodes-base.code",
      "position": [
        2400,
        700
      ],
      "parameters": {
        "jsCode": "for (const item of items) {\n  if (item.binary && item.binary['data']) {\n    const fileName = item.binary['data'].fileName || '';\n    const lowerName = fileName.toLowerCase();\n\n    if (lowerName.endsWith('.png')) {\n      item.binary['data'].mimeType = 'image/png';\n    } else if (lowerName.endsWith('.jpg') || lowerName.endsWith('.jpeg')) {\n      item.binary['data'].mimeType = 'image/jpeg';\n    } else if (lowerName.endsWith('.webp')) {\n      item.binary['data'].mimeType = 'image/webp';\n    } else if (lowerName.endsWith('.gif')) {\n      item.binary['data'].mimeType = 'image/gif';\n    }\n  }\n}\nreturn items;\n\n\n\n/** This is for jpeg. Delete later\nfor (const item of items) {\n  if (item.binary && item.binary['data']) {\n    item.binary['data'].mimeType = 'image/jpeg';\n  }\n}\nreturn items;\n**/\n\n"
      },
      "typeVersion": 2
    },
    {
      "id": "e245a098-08ba-4cf1-a3aa-3134070016ae",
      "name": "Photo to text",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        2620,
        700
      ],
      "parameters": {
        "text": "Describe the contents of this photo/image",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "options": {},
        "resource": "image",
        "inputType": "base64",
        "operation": "analyze"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "74df7c06-f07f-4504-a246-33665d355d70",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1520,
        1350
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "95deb83e-1d69-46b6-92e3-59e667d698fe",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.is_supported }}",
              "rightValue": ""
            },
            {
              "id": "5d9924b8-b8e7-4640-9675-8123e1562fa8",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.reason }}",
              "rightValue": "supported_file_type"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "531826bd-e8ab-4e56-9f56-4e0dd8847c2f",
      "name": "Download Spreadsheet",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2620,
        1650
      ],
      "parameters": {
        "fileId": "={{ $json.message.document.file_id }}",
        "resource": "file"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "6ffa7f95-c506-40ff-a320-f2b8b35db632",
      "name": "Extract from PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2840,
        1050
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "795a57de-78c6-44e8-a89b-a45c354988c9",
      "name": "Extract from Spreadsheet",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2840,
        1650
      ],
      "parameters": {
        "options": {},
        "operation": "xlsx"
      },
      "typeVersion": 1
    },
    {
      "id": "f567e9a4-e043-4431-b574-b217b4fa2656",
      "name": "Typing\u2026",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1080,
        379
      ],
      "parameters": {
        "chatId": "={{ $json.message.chat.id }}",
        "operation": "sendChatAction"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "67edb91b-880e-4542-88e7-fc7bde727a75",
      "name": "Supported Document File Types",
      "type": "n8n-nodes-base.code",
      "position": [
        1300,
        1350
      ],
      "parameters": {
        "jsCode": "const supportedExtensions = ['.jpg', '.jpeg', '.png', '.webp', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.json', '.xml'];\n\nreturn $input.all().map(item => {\n  // Try to extract file name from binary first, else fall back to message.document\n  const fileName = item.binary?.data?.fileName || item.json?.message?.document?.file_name || '';\n  const lowerName = fileName.toLowerCase();\n\n  const isSupported = supportedExtensions.some(ext => lowerName.endsWith(ext));\n\n  if (!isSupported) {\n    return {\n       json: {\n        is_supported: false,\n        reason: \"unsupported_file_type\",\n        message: '\u274c The uploaded file type is not supported. Please submit one of the following formats: .jpg, jpeg, .png, .webp, .pdf, .doc, .docx, .xls, .xlsx, .json, .xml',\n        fileName: fileName || 'Unknown file'\n      }\n    };\n  }\n\n  // File is supported \u2013 pass it forward untouched\n  return {\n    ...item,\n    json: {\n      ...(item.json || {}),\n      is_supported: true,\n      reason: \"supported_file_type\"\n    }\n  };\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "5c13b643-22c6-49cb-9055-54826f49fd13",
      "name": "Group Similar Documents",
      "type": "n8n-nodes-base.code",
      "position": [
        1740,
        1550
      ],
      "parameters": {
        "jsCode": "const results = [];\nfor (const item of $input.all()) {\nconst fileName = item.json?.fileName || item.json?.message?.document?.file_name || '';\nconst ext = fileName.toLowerCase().split('.').pop();\n\nlet type = 'unknown';\nif (['jpg', 'jpeg', 'png', 'webp'].includes(ext)) {\ntype = 'image';\n} else if (['pdf'].includes(ext)) {\ntype = 'pdf';\n} else if (['doc', 'docx'].includes(ext)) {\ntype = 'word document';\n} else if (['xls', 'xlsx'].includes(ext)) {\ntype = 'spreadsheet';\n} else if (['json'].includes(ext)) {\ntype = 'json';\n} else if (['xml'].includes(ext)) {\ntype = 'xml file'\n}\nitem.json.fileTypeCategory = type;\nresults.push(item);\n}\nreturn results;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "1923a439-9f1c-4df1-9360-a41250e61931",
      "name": "Input Message Router",
      "type": "n8n-nodes-base.switch",
      "position": [
        1080,
        579
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "fcb767ee-565e-4b56-a54e-6f97f739fc24",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Audio",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c1016c40-f8f2-4e08-8ec8-5cdb88f5c87a",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.voice }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Photo",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "4f28ab72-33ae-45fa-b3ba-51cefe600434",
                    "operator": {
                      "type": "array",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.photo }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Document",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "47b17a80-c23f-4b7c-9761-f045715334f4",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.document }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "510a0800-4323-4372-9f8a-3b3c26d8a455",
      "name": "Document Router",
      "type": "n8n-nodes-base.switch",
      "position": [
        1960,
        1487
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Image",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b688a3fb-8070-4506-9c9d-526d74c2605b",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "image"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "PDF",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "157a49a2-d5fb-425d-bb23-6ac16bdc45a2",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "pdf"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Word Document",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "41b0d6a4-89a7-4e3b-9e4a-00689def90aa",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "word document"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Spreadsheet",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "478f9497-7fc8-46e9-b834-22c78bbc7b05",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "spreadsheet"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "JSON",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d90c32c0-9d28-40d1-b11c-4fa9a14b7df5",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "json"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "XML File",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "4d4f7af7-ca8f-4a22-9af1-b3c93f51958f",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "xml file"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "8c04ffbb-9a63-4089-8877-c0c668eeabcc",
      "name": "Download JSON",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2620,
        1850
      ],
      "parameters": {
        "fileId": "={{ $json.message.document.file_id }}",
        "resource": "file"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "06a353d1-1ead-4973-aeff-4991ae2ca29f",
      "name": "Extract from JSON",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2840,
        1850
      ],
      "parameters": {
        "options": {},
        "operation": "fromJson"
      },
      "typeVersion": 1
    },
    {
      "id": "376ab859-3a6a-4f2d-80da-f0ab8c5149f6",
      "name": "Download XML",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2620,
        2050
      ],
      "parameters": {
        "fileId": "={{ $json.message.document.file_id }}",
        "resource": "file"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a4c890b7-d858-42aa-9e60-746ce6b6d17b",
      "name": "Extract from XML",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2840,
        2050
      ],
      "parameters": {
        "options": {},
        "operation": "xml"
      },
      "typeVersion": 1
    },
    {
      "id": "d91df63b-926b-43f5-9846-14cdde235b8d",
      "name": "Download Word Document",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2180,
        1450
      ],
      "parameters": {
        "fileId": "={{ $json.message.document.file_id }}",
        "resource": "file"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8a4fecf9-c50e-44ce-a4ce-c60713805f71",
      "name": "File to Base64",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2400,
        1450
      ],
      "parameters": {
        "options": {},
        "operation": "binaryToPropery"
      },
      "typeVersion": 1
    },
    {
      "id": "b40a6b1f-0a8e-4788-ae3a-17138cf5918e",
      "name": "Convert to text (convertapi.com)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2620,
        1450
      ],
      "parameters": {
        "url": "https://v2.convertapi.com/convert/docx/to/txt",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"Parameters\": [\n        {\n            \"Name\": \"File\",\n            \"FileValue\": {\n                \"Name\": \"{{ $('Download Word Document').item.binary.data.fileName }}\",\n                \"Data\": \"{{ $json.data }}\"\n            }\n        },\n        {\n            \"Name\": \"StoreFile\",\n            \"Value\": true\n        }\n    ]\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "59fad9e4-dbfc-4f6b-bfad-156b821e78dd",
      "name": "Download Text",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2840,
        1450
      ],
      "parameters": {
        "url": "={{ $json.Files[0].Url }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "914ab0ed-f102-4fa3-9db3-cf097b92c0ec",
      "name": "Photo to text1",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        2620,
        1250
      ],
      "parameters": {
        "text": "Describe the content of this image.",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "options": {
          "detail": "auto"
        },
        "resource": "image",
        "inputType": "base64",
        "operation": "analyze"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "9f4e250c-fb80-4b96-a9c6-d4fd47382985",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        1280
      ],
      "parameters": {
        "color": 4,
        "width": 620,
        "height": 260,
        "content": "\n\n## Requirement/Credentials\n1. Google drive API Key\n2. Telegram Bot Token. [Guide](https://docs.n8n.io/integrations/builtin/credentials/telegram/?utm_source=n8n_app&utm_medium=credential_settings&utm_campaign=create_new_credentials_modal)\n3. OpenAI API Key.\n4. Supabase API Key + Environment.\n5. ConvertAPI Key.\n6. Cohere API Key\n6. Postgres API Key. Or you can use n8n default simple memory node."
      },
      "typeVersion": 1
    },
    {
      "id": "f38669dd-5f21-4bb6-9f4d-1768e629eb0e",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        440
      ],
      "parameters": {
        "width": 620,
        "height": 800,
        "content": "## \u2699\ufe0f How It Works \n### \ud83d\udd01 Message Routing\n1. **Telegram Trigger** captures the user message (Text, Image, Voice, Document)\n2. **Message Router** routes input by type using a Switch node\n3. Each type is handled separately:\n     - **Voice** \u2192 Translate recording to text (.ogg, .mp3)\n     - **Image** \u2192 Analyze image to text.\n     -  **Text** \u2192 Sent directly to AI Agent (.txt).\n     - **Document** \u2192 Parsed (e.g. .docx to .txt) accordingly.\n\n         #### \ud83d\udcce Document Type Routing\n         Before routing documents by type, the **Supported  Document File Types** node first checks if the file extension is allowed. If not supported, it exits early with an error message \u2014 preventing unnecessary processing.\nSupported documents are then routed using the **Document Router** node, and converted to text for further processing.\n\n         #### Supported Document File Types\n         **.jpg**   **.jpeg**   **.png**   **.webp**   **.pdf**   **.doc**   **.docx**   **.xls**   **.xlsx**   **.json**   **.xml**.\n\n4. The text content is combined with stored memory and embedded knowledge using a **RAG** approach, enabling the AI to respond based on real uploaded data.\n   ### \ud83e\udde0 RAG via Supabase\n   Uploaded documents are vectorized using OpenAI Embeddings. Embeddings are stored in Supabase with metadata. On new questions, the chatbot:\n   - Extracts question intent\n   - Queries Supabase for semantically similar chunks\n   - Injects them into the prompt for OpenAI. \n   - OpenAI generates a grounded response based on actual document content.\n\n5. Response is sent to the Telegram user with content awareness."
      },
      "typeVersion": 1
    },
    {
      "id": "ca3a50ef-8148-4bb7-810c-a14422791866",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        860,
        -160
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "5f8a25d8-a8bb-4b01-a7b0-7ad7d58ab0c9",
      "name": "Download file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1080,
        -160
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "list",
          "value": "19mt-vKtgLTvoqhR8TgbN9eSyGIkrrBjqjWfj8EDlZpU",
          "cachedResultUrl": "https://docs.google.com/document/d/19mt-vKtgLTvoqhR8TgbN9eSyGIkrrBjqjWfj8EDlZpU/edit?usp=drivesdk",
          "cachedResultName": "Conor's Cleaning - Knowledge Base Document"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "3020c220-4e42-4c80-8bc8-7b93bc9a56e6",
      "name": "Default Data Loader1",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1420,
        62.5
      ],
      "parameters": {
        "options": {},
        "dataType": "binary",
        "textSplittingMode": "custom"
      },
      "typeVersion": 1.1
    },
    {
      "id": "cc3f97fa-842d-45ae-ac51-6def07bfed1e",
      "name": "Recursive Character Text Splitter1",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        1508,
        260
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "c448b82d-7145-4d46-a0e6-f2a01234331f",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        3280,
        1376.5
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5c1f5765-6d8e-429d-80d6-c9b3b15d4525",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1300,
        60
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0e500c88-38e1-4388-b0ef-116f95cf609c",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        3548,
        1576.5
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3ecaba71-3c29-42dd-8440-cd5c574241b9",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        3400,
        1376.5
      ],
      "parameters": {
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 3
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "086a122b-ffa3-43d5-9551-a8a9888c4bba",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -140
      ],
      "parameters": {
        "color": 3,
        "width": 340,
        "height": 220,
        "content": "## \u2699\ufe0f Before using the Telegram chatbot:\nManually run this workflow to import your **Knowledge base** from Google drive into **Supabase** with vector embeddings.\nThis enables the Telegram chatbot to answer your questions based on real content."
      },
      "typeVersion": 1
    },
    {
      "id": "4d151254-2466-4c9b-9099-16f78cdf939f",
      "name": "Reranker Cohere",
      "type": "@n8n/n8n-nodes-langchain.rerankerCohere",
      "position": [
        3668,
        1576.5
      ],
      "parameters": {},
      "credentials": {
        "cohereApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "744219e9-66ef-45da-8d7c-a216862aca43",
      "name": "Extract Text",
      "type": "n8n-nodes-base.set",
      "position": [
        3060,
        300
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "74f774a8-e230-44fe-8d46-7a0ce7f34b42",
              "name": "text",
              "type": "string",
              "value": "={{ $json.message.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "76e0a4d6-8e34-4a87-9809-832c03d22097",
      "name": "Extract Text & Content",
      "type": "n8n-nodes-base.set",
      "position": [
        2840,
        700
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "5a6a5c34-c6bf-4d00-bb51-2ec5cd4af9e9",
              "name": "text",
              "type": "string",
              "value": "=Photo content: {{ $json.content }}\n\nPhoto caption: {{ $('Telegram Trigger').item.json.message.caption }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c366d6dc-bcf0-4bf8-952e-e4565e198c3a",
      "name": "Extract Error Message",
      "type": "n8n-nodes-base.set",
      "position": [
        3060,
        850
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "cd3cb375-33a8-479e-b320-6d43e23c906e",
              "name": "text",
              "type": "string",
              "value": "={{ $json.message }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "89aa2812-0952-4ab5-8e3c-63e9ee7b9128",
      "name": "Extract Text1",
      "type": "n8n-nodes-base.set",
      "position": [
        3060,
        1650
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "35b5e034-cf94-499c-967c-1aeb4edf1b58",
              "name": "text",
              "type": "string",
              "value": "={{ $json }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "5313c3b4-ecc9-47d0-a15d-33b4f7bb1b5b",
      "name": "Extract Text2",
      "type": "n8n-nodes-base.set",
      "position": [
        3060,
        1850
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d480f972-a046-4ff1-9d19-ac586c372cbd",
              "name": "text",
              "type": "string",
              "value": "={{ $json }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "676253d8-dc18-4915-9cff-8081bcb33f63",
      "name": "Extract Text3",
      "type": "n8n-nodes-base.set",
      "position": [
        3060,
        2050
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "f7d3f22b-cca6-4d5d-9e70-b4075e542979",
              "name": "text",
              "type": "string",
              "value": "={{ $json }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c3807fa7-c537-4454-a2ac-baa8996d2808",
      "name": "Extract Text4",
      "type": "n8n-nodes-base.set",
      "position": [
        3060,
        1050
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "6bb76f62-7f3e-432d-9c96-4c1d1c3e15f1",
              "name": "text",
              "type": "string",
              "value": "={{ $json.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "428f828e-bef8-425a-90dc-b53ef786216e",
      "name": "Extract Text5",
      "type": "n8n-nodes-base.set",
      "position": [
        3060,
        1450
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d26a3dd0-8bb2-4f25-9c7d-3542dc039861",
              "name": "text",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9fe5eac7-98a4-40d4-8896-5af7ea86a278",
      "name": "Add to Supabase Vector DB",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        1316,
        -160
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "e080e0a0-053a-4648-87cf-ac322b423280",
      "name": "Knowledge Base AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3312,
        1156.5
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": ""
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "d5cf1a5a-a84d-491e-922e-ce1628ab08db",
      "name": "Supabase Vector Store Search",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        3520,
        1379
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 10,
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        },
        "useReranker": true,
        "toolDescription": "Retrieve information about Conor\u2019s Cleaning from the Supabase vector store."
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "2fa6bed8-34b0-43c2-9ac0-6a77a9e60381",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Group Similar Documents",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract Error Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram": {
      "main": [
        []
      ]
    },
    "Download PDF": {
      "main": [
        [
          {
            "node": "Extract from PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download XML": {
      "main": [
        [
          {
            "node": "Extract from XML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text": {
      "main": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fix mimeType": {
      "main": [
        [
          {
            "node": "Photo to text1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download JSON": {
      "main": [
        [
          {
            "node": "Extract from JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Text": {
      "main": [
        [
          {
            "node": "Extract Text5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download file": {
      "main": [
        [
          {
            "node": "Add to Supabase Vector DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text1": {
      "main": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text2": {
      "main": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text3": {
      "main": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text4": {
      "main": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text5": {
      "main": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fix mimeType1": {
      "main": [
        [
          {
            "node": "Photo to text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Photo to text": {
      "main": [
        [
          {
            "node": "Extract Text & Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Audio": {
      "main": [
        [
          {
            "node": "Translate to Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Image": {
      "main": [
        [
          {
            "node": "Fix mimeType",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Photo": {
      "main": [
        [
          {
            "node": "Fix mimeType1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File to Base64": {
      "main": [
        [
          {
            "node": "Convert to text (convertapi.com)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Photo to text1": {
      "main": [
        [
          {
            "node": "Extract Text & Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Document Router": {
      "main": [
        [
          {
            "node": "Download Image",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download Word Document",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download Spreadsheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download JSON",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download XML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reranker Cohere": {
      "ai_reranker": [
        [
          {
            "node": "Supabase Vector Store Search",
            "type": "ai_reranker",
            "index": 0
          }
        ]
      ]
    },
    "Extract from PDF": {
      "main": [
        [
          {
            "node": "Extract Text4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from XML": {
      "main": [
        [
          {
            "node": "Extract Text3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Input Message Router",
            "type": "main",
            "index": 0
          },
          {
            "node": "Typing\u2026",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Add to Supabase Vector DB",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Extract from JSON": {
      "main": [
        [
          {
            "node": "Extract Text2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Translate to Text": {
      "main": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store Search",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader1": {
      "ai_document": [
        [
          {
            "node": "Add to Supabase Vector DB",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Download Spreadsheet": {
      "main": [
        [
          {
            "node": "Extract from Spreadsheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Input Message Router": {
      "main": [
        [
          {
            "node": "Extract Text",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download Audio",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download Photo",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Supported Document File Types",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Extract Error Message": {
      "main": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Word Document": {
      "main": [
        [
          {
            "node": "File to Base64",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text & Content": {
      "main": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Group Similar Documents": {
      "main": [
        [
          {
            "node": "Document Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Knowledge Base AI Agent": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from Spreadsheet": {
      "main": [
        [
          {
            "node": "Extract Text1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store Search": {
      "ai_tool": [
        [
          {
            "node": "Knowledge Base AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supported Document File Types": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to text (convertapi.com)": {
      "main": [
        [
          {
            "node": "Download Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter1": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader1",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This n8n workflow turns your Telegram bot into a smart, multi-modal AI assistant that accepts text, documents, images, and audio messages, interprets them using OpenAI models, and responds instantly with context-aware answers. It integrates a Supabase vector database to store…

Source: https://n8n.io/workflows/5589/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

A lightweight, self-hosted AI assistant built entirely in n8n. Multi-channel messaging (Telegram, WhatsApp, Gmail), persistent memory, task management, and autonomous work — all in a single visual wor

Telegram Trigger, OpenRouter Chat, Data Table +20
AI & RAG

This workflow implements an advanced AI automation agent (OpenClaw Agent) that interacts with users through Telegram and integrates multiple AI models, external tools, and cloud services to automate c

Telegram Trigger, Telegram, OpenAI +21
AI & RAG

Your AI workforce is ready. Are you?

Google Sheets Tool, Mcp Trigger, Google Drive +29
AI & RAG

This comprehensive workflow bundle is designed as a powerful starter kit, enabling you to build a multi-functional AI assistant on Telegram. It seamlessly integrates AI-powered voice interactions, an

Telegram Trigger, Telegram, OpenAI +19
AI & RAG

This intelligent chatbot leverages cutting-edge financial APIs and AI-driven analysis to deliver comprehensive stock research reports. Get instant access to professional-grade investment analysis that

Tool Think, Supabase Vector Store, OpenAI Embeddings +15