Quick overview
This workflow runs a Telegram RAG chatbot that answers questions using PDFs synced from Google Drive into a Supabase vector store, automatically re-indexing when files are added or updated and removing knowledge when files are moved to a trash folder.
How it works
- Triggers when a user sends a Telegram message and passes the text to a LangChain AI Agent.
- The agent uses an OpenRouter chat model, Postgres chat memory, and a Supabase vector store tool (with OpenAI embeddings) to retrieve relevant context and generate an answer.
- Sends the generated response back to the user in Telegram.
- Triggers when a new file is created in a watched Google Drive folder, downloads the PDF, extracts its text, chunks it, generates OpenAI embeddings, and inserts the vectors into a Supabase table.
- Triggers when a file is updated in another watched Google Drive folder, deletes existing Supabase vectors that match the file name, then re-downloads the PDF, re-extracts/chunks it, embeds it with OpenAI, and re-inserts it into Supabase.
- Triggers when a file appears in a designated Google Drive “trash” folder, deletes matching vectors from Supabase and deletes the file from Google Drive.
Setup
- Create a Telegram bot and add a Telegram credential in n8n.
- Add credentials for Google Drive OAuth2, Supabase, OpenRouter, OpenAI (for embeddings), and Postgres (for chat memory).
- In Supabase, create the
documents table configured for vector search (pgvector) and match the table name in the Supabase vector store nodes.
- Update the Google Drive trigger nodes to point at your source folder(s) (new files, updated files, and trash) and ensure the workflow has permission to download and delete files.
- If you rely on file-name matching for deletes, ensure your chunk metadata includes
fileName consistently so updates and removals target the correct vectors.