Build a multi-functional Telegram bot with Gemini, RAG PDF search & Google Suite
The Ultimate Beginner's Guide to an AI-Powered Telegram Assistant (PDF, Brave search & Google Suite)
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 intelligent PDF document search using a Retrieval-Augmented Generation (RAG) system, and automates various Google Suite tasks like calendar management and document generation. Perfect for beginners looking to explore advanced AI and automation capabilities.
Disclaimer
This template is designed for self-hosted n8n instances.
๐ Key Features
- Telegram Bot Interface: Interact with your AI assistant using both text and voice commands through Telegram.
- AI Voice Bot:
- Transcribes user voice messages using OpenAI Whisper.
- Processes requests with an AI agent powered by Google Gemini.
- Responds with AI-synthesized voice using Replicate API.
- PDF RAG System:
- Index PDF documents from Google Drive via Telegram commands.
- Utilizes Mistral AI for Optical Character Recognition (OCR) on PDFs.
- Stores document content and embeddings in a Qdrant vector database.
- Answers questions about your documents using Google Gemini, based on retrieved context.
- Google Suite Automation:
- Manage Google Calendar: Create events, find upcoming holidays, and list birthdays.
- Google Drive: Search for PDF files and manage document templates.
- Google Docs: Automatically generate invoices from templates.
- Intelligent Web Search: Employs Brave Search for fetching real-time information from the web.
- Versatile AI Agent: Leverages Google Gemini with a suite of tools including a calculator, date & time utilities, and custom integrations (e.g., example Airbnb tools).
- Command-Driven Functionality: Easily trigger specific actions using Telegram commands like
/help,/pdf,/rag,/invoice,/chat,/brave, and/birthday.
โ๏ธ How It Works
The workflow is initiated by messages or commands sent to your Telegram bot. A central Switch node directs the flow based on the input received.
1. Telegram Interaction & Command Routing
- A Telegram Trigger node listens for new messages (text or voice).
- A "typing..." indicator is sent to Telegram for better user experience.
- The Switch node parses the message content and routes it to the appropriate sub-workflow based on predefined commands (e.g.,
/pdf,/rag,/voice) or general chat.
2. AI Voice Bot Functionality
- For voice messages (or if the voice path is triggered):
- The voice file is downloaded from Telegram.
- OpenAI Whisper transcribes the audio into text.
- The transcribed text is fed to an AI Agent (powered by Google Gemini and equipped with various tools and memory).
- The AI Agent's text response is then sent to the Replicate API to generate a natural-sounding voice.
- The generated audio response is sent back to the user on Telegram.
3. PDF RAG System with Mistral OCR & Qdrant
- Indexing PDFs (via
/qdrant <Google_Drive_File_ID>command):- The specified PDF is downloaded from Google Drive.
- The PDF is uploaded to Mistral AI for OCR processing.
- The extracted text (in markdown format) is retrieved.
- The text is split into manageable chunks.
- OpenAI Embeddings are generated for each chunk.
- These chunks and their embeddings are stored in a Qdrant vector collection.
- A confirmation message is sent to Telegram.
- Querying PDFs (via
/rag <your_question>command):- The user's question is processed by a RetrievalQA Chain.
- This chain uses Google Gemini as the Language Model and retrieves relevant document chunks from Qdrant based on semantic similarity (embeddings).
- Google Gemini then generates a concise answer based on the user's question and the retrieved contextual information from the documents.
- The answer is sent back to the user on Telegram.
- Searching PDFs in Drive (via
/pdf <search_term>command):- Searches your Google Drive for PDF files matching the provided search term.
- Sends a list of found PDF files (name and ID) to the user on Telegram, allowing them to easily identify files for indexing with
/qdrant.
4. AI Chat & Task Automation (General Chat & /chat command)
- Handles general text messages or transcribed voice inputs that are not specific commands.
- An AI Agent (Google Gemini) processes these inputs.
- The agent is equipped with tools such as:
- Google Calendar Tools: To create events, find the next public holiday, or list upcoming birthdays.
- Brave Search Tool: To search the internet for information.
- Calculator Tool: For mathematical computations.
- Date & Time Utility: For handling and formatting dates.
- Example Airbnb Tools: Demonstrates extensibility for custom tool integrations.
- The agent utilizes a "Think Node" process for reasoning and Window Buffer Memory to maintain conversational context.
- Responses are formulated and sent back to the user on Telegram.
5. Google Automations
- Invoice Generation (via
/invoicecommand):- Copies a predefined Google Docs invoice template from your Google Drive.
- Populates the new document with details (client name, items, etc. โ currently uses placeholder data from an 'Edit Fields' node, which can be customized to parse input from the command).
- Converts the populated Google Doc into a PDF file.
- Sends the generated PDF invoice to the user via Telegram.
- Calendar Management (via AI Agent or specific commands like
/birthday):- The
/birthdaycommand fetches upcoming birthdays from a specified Google Calendar. - The AI Agent can also interact with Google Calendar to create events or retrieve information based on natural language requests.
- The
6. Web Search (via /brave <query> command or AI Agent)
- Performs a web search using the Brave Search API.
- Returns a list of search results, including titles and URLs, to the user on Telegram.
7. Help Command (/help)
- Provides the user with a formatted list of all available Telegram commands and their basic usage instructions.
๐ ๏ธ Setup Steps & Credentials
To get this workflow bundle up and running, you'll need to configure several credentials:
- Telegram:
- Create a new bot via
@BotFatheron Telegram to obtain a Bot Token. - Add this token to the
Telegram Triggernode and allTelegram(sender) nodes in the workflow.
- Create a new bot via
- OpenAI:
- Obtain an API Key from platform.openai.com.
- Create an
OpenAIcredential. - Use this credential in the
Convert audio to text(OpenAI node for Whisper transcription) and allEmbeddings OpenAInodes (for RAG system).
- Replicate API (Text-to-Speech):
- Sign up at replicate.com and get your API token.
- Create an
HTTP Bearer Authcredential using this token. - Assign this credential to the
Call Replicate API(HTTP Request) node.
- Google Gemini (PaLM API):
- Get an API key from Google AI Studio or Google Cloud Console.
- Create a
Google Gemini(PaLM) Apicredential. - Assign it to all
Google Gemini Chat Modelnodes.
- Qdrant (Vector Database):
- Set up a Qdrant instance (either cloud-hosted or self-managed).
- Note your Qdrant instance URL and API Key (if security is enabled).
- Create a
QdrantApicredential with these details. - Assign it to the
Qdrant Vector Storenodes. - For the
Refresh collectionnode (an HTTP Request node used to clear the collection for/pdfcommand demo), create anHTTP Header Authcredential with your Qdrant API key if required by your instance.
- Mistral AI (PDF OCR):
- Obtain an API key from console.mistral.ai.
- Create a
Mistral Cloud APIcredential. - Assign this to the
Mistral Upload,Mistral Signed URL, andMistral DOC OCR(HTTP Request) nodes.
- Google Drive & Google Docs:
- Ensure the Google Drive API and Google Docs API are enabled in your Google Cloud Console project.
- Set up OAuth 2.0 credentials (Client ID and Client Secret).
- Create
Google Drive OAuth2 ApiandGoogle Docs OAuth2 Apicredentials. - Assign these to the respective
Google DriveandGoogle Docsnodes throughout the workflow. - Important: Configure relevant Folder IDs (for PDF search, invoice template source, invoice output) and the invoice template Document ID in the Google Drive and Google Docs nodes.
- Google Calendar:
- Enable the Google Calendar API in your Google Cloud Console project.
- Set up OAuth 2.0 credentials.
- Create a
Google Calendar OAuth2 Apicredential. - Assign it to the
Google CalendarToolandGoogle Calendarnodes. - Specify the correct calendar names or IDs in the nodes (e.g., for birthdays, holidays, new event creation).
- Brave Search:
- Get a Brave Search API key from their developer portal.
- Create a
Brave Search APIcredential. - Assign it to the
Brave Searchnodes and tools.
- (Optional) Airbnb MCP Client:
- The workflow includes example nodes for Airbnb MCP tools. If you intend to use or expand these, set up the corresponding
MCP Client APIcredentials.
- The workflow includes example nodes for Airbnb MCP tools. If you intend to use or expand these, set up the corresponding
๐ก Customization & Learning
This "Beginner Bundle" is not just a ready-to-use solution but also a fantastic learning resource:
- Explore AI Agent Prompts: Dive into the
AI Agentnodes to see how prompts are structured to guide the LLM's behavior, including the "Think Node" process and character guidance for robust messaging. - Modify Toolsets: Easily add or remove tools for the AI agent to expand its capabilities.
- Invoice Customization: Adapt the
Edit Fieldsnode and the Google Docs template to match your invoicing needs. You can extend it to parse invoice details directly from the Telegram command. - RAG Parameters: Experiment with chunk sizes, overlap, and different embedding models in the RAG pipeline.
- Extend Commands: Add new commands and corresponding functionalities by expanding the main
Switchnode and building out new automation paths.
By setting up and dissecting this workflow, beginners can gain a practical understanding of building complex, AI-driven applications, integrating various services, and managing different data flows.
n8n Telegram Bot with Gemini (RAG, PDF Search) and Google Suite Integration
This n8n workflow creates a powerful, multi-functional Telegram bot that leverages Google Gemini for AI capabilities, including Retrieval Augmented Generation (RAG) for PDF content and integrates with various Google Suite services. It allows users to interact with their Google Drive, Google Calendar, and Google Docs directly through Telegram commands.
What it does
This workflow automates the following tasks:
- Listens for Telegram Messages: Triggers when a user sends a message to the configured Telegram bot.
- Parses Telegram Input: Extracts the user's message and chat ID.
- Routes Commands: Uses a Switch node to identify specific commands (e.g.,
/searchpdf,/createevent,/listdocs). - Google Drive PDF Search (RAG):
- If the
/searchpdfcommand is detected, it retrieves a specified PDF from Google Drive. - Loads the PDF content using a Default Data Loader.
- Splits the document into manageable chunks using a Token Splitter.
- Generates embeddings for the document chunks using OpenAI Embeddings.
- Stores these embeddings in a Qdrant Vector Store for efficient retrieval.
- Uses a Question and Answer Chain (powered by Google Gemini Chat Model) with the Vector Store Retriever to answer user questions based on the PDF content (RAG).
- Sends the AI-generated answer back to the user via Telegram.
- If the
- Google Calendar Event Creation:
- If a command for creating a calendar event is detected, it uses the Google Calendar node to create a new event.
- Sends a confirmation message to the user via Telegram.
- Google Docs Listing:
- If a command for listing Google Docs is detected, it uses the Google Docs node to retrieve a list of documents.
- Formats the document list and sends it to the user via Telegram.
- General AI Agent (Gemini):
- For other queries, it utilizes an AI Agent (powered by Google Gemini Chat Model) with a Simple Memory to maintain conversation context.
- Includes a Calculator tool for mathematical operations and a Think tool for internal reasoning.
- Processes the user's query and responds via Telegram.
- Error Handling: Includes a "Wait" node, potentially for rate limiting or to introduce delays in responses.
Prerequisites/Requirements
To use this workflow, you will need:
- n8n Instance: A running n8n instance.
- Telegram Bot Token: A Telegram bot token obtained from BotFather.
- Telegram Credentials: Configured Telegram credentials in n8n.
- Google Cloud Project: A Google Cloud project with the following APIs enabled:
- Google Drive API
- Google Calendar API
- Google Docs API
- Google OAuth2 Credentials: Configured Google OAuth2 credentials in n8n for Google Drive, Google Calendar, and Google Docs.
- OpenAI API Key: An OpenAI API key for generating embeddings.
- Qdrant Instance: A running Qdrant vector database instance (or a cloud service like Qdrant Cloud).
- Google Gemini API Key: Access to the Google Gemini API.
Setup/Usage
- Import the Workflow: Download the JSON provided and import it into your n8n instance.
- Configure Credentials:
- Set up your Telegram Bot Token credentials.
- Configure Google OAuth2 credentials for Google Drive, Google Calendar, and Google Docs. Ensure the necessary scopes are granted for reading/writing to these services.
- Add your OpenAI API Key credentials.
- Set up Qdrant credentials (API key and host if applicable).
- Configure your Google Gemini Chat Model credentials.
- Customize Nodes:
- Telegram Trigger (Node 50): Ensure it's configured to listen to your bot.
- Google Drive (Node 58): Specify the folder or file ID for PDF documents if you are using the RAG feature.
- Google Calendar (Node 317): Adjust calendar IDs or event details as needed.
- Google Docs (Node 495): Customize search queries or document listing parameters.
- AI Agent (Node 1119), Question and Answer Chain (Node 1125), Google Gemini Chat Model (Node 1262): Review their configurations, especially the prompts and model parameters, to align with your desired bot behavior.
- Activate the Workflow: Once all credentials are set and nodes are configured, activate the workflow.
- Interact via Telegram: Start sending commands to your Telegram bot.
- Example commands might include:
/searchpdf Your question about the document/createevent Event Title at Date Time/listdocs- Any general question for the AI agent.
- Example commands might include:
Related Templates
Two-way property repair management system with Google Sheets & Drive
This workflow automates the repair request process between tenants and building managers, keeping all updates organized in a single spreadsheet. It is composed of two coordinated workflows, as two separate triggers are required โ one for new repair submissions and another for repair updates. A Unique Unit ID that corresponds to individual units is attributed to each request, and timestamps are used to coordinate repair updates with specific requests. General use cases include: Property managers who manage multiple buildings or units. Building owners looking to centralize tenant repair communication. Automation builders who want to learn multi-trigger workflow design in n8n. --- โ๏ธ How It Works Workflow 1 โ New Repair Requests Behind the Scenes: A tenant fills out a Google Form (โRepair Request Formโ), which automatically adds a new row to a linked Google Sheet. Steps: Trigger: Google Sheets rowAdded โ runs when a new form entry appears. Extract & Format: Collects all relevant form data (address, unit, urgency, contacts). Generate Unit ID: Creates a standardized identifier (e.g., BUILDING-UNIT) for tracking. Email Notification: Sends the building manager a formatted email summarizing the repair details and including a link to a Repair Update Form (which activates Workflow 2). --- Workflow 2 โ Repair Updates Behind the Scenes:\ Triggered when the building manager submits a follow-up form (โRepair Update Formโ). Steps: Lookup by UUID: Uses the Unit ID from Workflow 1 to find the existing row in the Google Sheet. Conditional Logic: If photos are uploaded: Saves each image to a Google Drive folder, renames files consistently, and adds URLs to the sheet. If no photos: Skips the upload step and processes textual updates only. Merge & Update: Combines new data with existing repair info in the same spreadsheet row โ enabling a full repair history in one place. --- ๐งฉ Requirements Google Account (for Forms, Sheets, and Drive) Gmail/email node connected for sending notifications n8n credentials configured for Google API access --- โก Setup Instructions (see more detail in workflow) Import both workflows into n8n, then copy one into a second workflow. Change manual trigger in workflow 2 to a n8n Form node. Connect Google credentials to all nodes. Update spreadsheet and folder IDs in the corresponding nodes. Customize email text, sender name, and form links for your organization. Test each workflow with a sample repair request and a repair update submission. --- ๐ ๏ธ Customization Ideas Add Slack or Telegram notifications for urgent repairs. Auto-create folders per building or unit for photo uploads. Generate monthly repair summaries using Google Sheets triggers. Add an AI node to create summaries/extract relevant repair data from repair request that include long submissions.
Generate song lyrics and music from text prompts using OpenAI and Fal.ai Minimax
Spark your creativity instantly in any chatโturn a simple prompt like "heartbreak ballad" into original, full-length lyrics and a professional AI-generated music track, all without leaving your conversation. ๐ What This Template Does This chat-triggered workflow harnesses AI to generate detailed, genre-matched song lyrics (at least 600 characters) from user messages, then queues them for music synthesis via Fal.ai's minimax-music model. It polls asynchronously until the track is ready, delivering lyrics and audio URL back in chat. Crafts original, structured lyrics with verses, choruses, and bridges using OpenAI Submits to Fal.ai for melody, instrumentation, and vocals aligned to the style Handles long-running generations with smart looping and status checks Returns complete song package (lyrics + audio link) for seamless sharing ๐ง Prerequisites n8n account (self-hosted or cloud with chat integration enabled) OpenAI account with API access for GPT models Fal.ai account for AI music generation ๐ Required Credentials OpenAI API Setup Go to platform.openai.com โ API keys (sidebar) Click "Create new secret key" โ Name it (e.g., "n8n Songwriter") Copy the key and add to n8n as "OpenAI API" credential type Test by sending a simple chat completion request Fal.ai HTTP Header Auth Setup Sign up at fal.ai โ Dashboard โ API Keys Generate a new API key โ Copy it In n8n, create "HTTP Header Auth" credential: Name="Fal.ai", Header Name="Authorization", Header Value="Key [Your API Key]" Test with a simple GET to their queue endpoint (e.g., /status) โ๏ธ Configuration Steps Import the workflow JSON into your n8n instance Assign OpenAI API credentials to the "OpenAI Chat Model" node Assign Fal.ai HTTP Header Auth to the "Generate Music Track", "Check Generation Status", and "Fetch Final Result" nodes Activate the workflowโchat trigger will appear in your n8n chat interface Test by messaging: "Create an upbeat pop song about road trips" ๐ฏ Use Cases Content Creators: YouTubers generating custom jingles for videos on the fly, streamlining production from idea to audio export Educators: Music teachers using chat prompts to create era-specific folk tunes for classroom discussions, fostering interactive learning Gift Personalization: Friends crafting anniversary R&B tracks from shared memories via quick chats, delivering emotional audio surprises Artist Brainstorming: Songwriters prototyping hip-hop beats in real-time during sessions, accelerating collaboration and iteration โ ๏ธ Troubleshooting Invalid JSON from AI Agent: Ensure the system prompt stresses valid JSON; test the agent standalone with a sample query Music Generation Fails (401/403): Verify Fal.ai API key has minimax-music access; check usage quotas in dashboard Status Polling Loops Indefinitely: Bump wait time to 45-60s for complex tracks; inspect fal.ai queue logs for bottlenecks Lyrics Under 600 Characters: Tweak agent prompt to enforce fuller structures like [V1][C][V2][B][C]; verify output length in executions
Automate Dutch Public Procurement Data Collection with TenderNed
TenderNed Public Procurement What This Workflow Does This workflow automates the collection of public procurement data from TenderNed (the official Dutch tender platform). It: Fetches the latest tender publications from the TenderNed API Retrieves detailed information in both XML and JSON formats for each tender Parses and extracts key information like organization names, titles, descriptions, and reference numbers Filters results based on your custom criteria Stores the data in a database for easy querying and analysis Setup Instructions This template comes with sticky notes providing step-by-step instructions in Dutch and various query options you can customize. Prerequisites TenderNed API Access - Register at TenderNed for API credentials Configuration Steps Set up TenderNed credentials: Add HTTP Basic Auth credentials with your TenderNed API username and password Apply these credentials to the three HTTP Request nodes: "Tenderned Publicaties" "Haal XML Details" "Haal JSON Details" Customize filters: Modify the "Filter op ..." node to match your specific requirements Examples: specific organizations, contract values, regions, etc. How It Works Step 1: Trigger The workflow can be triggered either manually for testing or automatically on a daily schedule. Step 2: Fetch Publications Makes an API call to TenderNed to retrieve a list of recent publications (up to 100 per request). Step 3: Process & Split Extracts the tender array from the response and splits it into individual items for processing. Step 4: Fetch Details For each tender, the workflow makes two parallel API calls: XML endpoint - Retrieves the complete tender documentation in XML format JSON endpoint - Fetches metadata including reference numbers and keywords Step 5: Parse & Merge Parses the XML data and merges it with the JSON metadata and batch information into a single data structure. Step 6: Extract Fields Maps the raw API data to clean, structured fields including: Publication ID and date Organization name Tender title and description Reference numbers (kenmerk, TED number) Step 7: Filter Applies your custom filter criteria to focus on relevant tenders only. Step 8: Store Inserts the processed data into your database for storage and future analysis. Customization Tips Modify API Parameters In the "Tenderned Publicaties" node, you can adjust: offset: Starting position for pagination size: Number of results per request (max 100) Add query parameters for date ranges, status filters, etc. Add More Fields Extend the "Splits Alle Velden" node to extract additional fields from the XML/JSON data, such as: Contract value estimates Deadline dates CPV codes (procurement classification) Contact information Integrate Notifications Add a Slack, Email, or Discord node after the filter to get notified about new matching tenders. Incremental Updates Modify the workflow to only fetch new tenders by: Storing the last execution timestamp Adding date filters to the API query Only processing publications newer than the last run Troubleshooting No data returned? Verify your TenderNed API credentials are correct Check that you have setup youre filter proper Need help setting this up or interested in a complete tender analysis solution? Get in touch ๐ LinkedIn โ Wessel Bulte