Telegram Chatbot with Voice Transcription and Message Batching - n8n Workflow

Create a robust n8n workflow for a Telegram chatbot that transcribes voice messages, intelligently batches user input, and uses an OpenAI agent with Supabase RAG.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

• Automation developers seeking advanced n8n templates for conversational AI.
• Users needing high-availability n8n workflow solutions with debouncing capabilities.
• Technical teams integrating OpenAI agents with external knowledge bases (Supabase).
• Anyone requiring a smart system to manage and batch rapid-fire user messages within n8n.

Overview

This comprehensive n8n workflow demonstrates how to build a resilient and sophisticated Telegram chatbot capable of handling both text and voice input. The core value of this n8n automation lies in its message batching and debouncing mechanism, which prevents the AI model from being overwhelmed by multiple, rapid messages from the same user. By leveraging Google Sheets to temporarily store messages and track user waiting status, the system intelligently waits for a configurable period (e.g., 30 seconds) before compiling all recent inputs into a single prompt for the AI Agent. This approach optimizes API costs and ensures the AI receives complete context, resulting in highly coherent responses. The initial phase of this n8n node pipeline incorporates OpenAI Whisper technology to accurately transcribe voice messages, ensuring seamless accessibility for all users.

How it Works

The entire process is initiated by the Telegram Trigger, which listens for incoming messages.


  1. Input Classification: The n8n workflow uses an If n8n node (Link Filter) to check if the incoming message contains a voice file ID. If true, the Get Audio File Telegram n8n node downloads it, and the Transcribe a recording OpenAI n8n node converts the audio to text (Whisper). If false, the text passes directly through.

  2. Data Unification: All paths merge into the Edit Fields n8n node, standardizing the user message (processedMessage) and sessionId.

  3. Retention: The message is saved to the 'Msg Retention' Google Sheet via the Append row in sheet n8n node.

  4. Debounce Check: The n8n workflow retrieves the user's status from the 'Msg Waiting' sheet. The No Rows code n8n node ensures that new users default to a 'not waiting' status.

  5. Batching Decision: The What to do If n8n node decides whether to start the batching timer. It proceeds if the user is not waiting OR if the last message was received over 30 seconds ago.

  6. TRUE Path (Batching): The system updates the status (Update row in sheet), initiates a fixed time pause using the Wait n8n node, and then uses Get row(s) in sheet to pull all accumulated messages.

  7. Message Consolidation: The Batch Messages code n8n node combines the retrieved messages into a single text block.

  8. AI Processing: After deleting the retained rows, the AI Agent n8n node processes the batched message. This agent utilizes the OpenAI Chat Model, Simple Memory (for session history), and a Supabase Vector Store (for RAG capabilities).

  9. Reply & Cleanup: The final response is sent back to the user using the Send message Back to TG n8n node, and the user's waiting status is cleared by the final Google Sheets operation, completing the n8n workflow execution.

Installation Guide


  1. Importing the n8n workflow: Copy the provided JSON data and paste it into your n8n canvas using the 'New' -> 'Import from JSON' option.

  2. Credential Setup: Configure credentials for Telegram API, OpenAI API, and Google Sheets OAuth2. Ensure your Google Sheets credential grants Editor access to the service account email for the two required sheets.

  3. Google Sheets Preparation: Create two sheets:

Msg Retention: Columns date | userid | message.
Msg Waiting: Columns user
id | iswaiting | lastupdated.
Update the Sheet ID references in the Google Sheets n8n node parameters accordingly.

  1. Telegram Trigger Activation: Select the correct Telegram credential in the Telegram Trigger n8n node and execute it once to register the webhook with Telegram.

  2. AI Configuration: Update the system message prompt in the AI Agent n8n node and ensure the Supabase Vector Store n8n node is correctly configured with your knowledge base table ID and embedding credentials.

Node Details

Telegram Trigger n8n trigger: The entry point of the n8n workflow, configured to listen for new message updates.
Transcribe a recording (OpenAI n8n node): Uses the OpenAI Whisper model to convert audio files received via Telegram into text, enabling voice message handling.
Append row in sheet (Google Sheets n8n node): Saves the user's message, date, and user ID to the 'Msg Retention' sheet for later batch processing.
What to do (If n8n node): Implements the debouncing logic, checking if a user's lastupdated time is older than the wait period (30 seconds) or if the user is not currently marked as iswaiting.
Wait n8n node: Pauses the execution on the batching path for 30 seconds, allowing for additional user messages to arrive and accumulate.
Batch Messages (Code n8n node): Custom JavaScript n8n node responsible for retrieving multiple rows from Google Sheets and concatenating them into a single, cohesive input string for the AI agent.
AI Agent n8n node: The core of the conversational flow. It orchestrates the AI components, including the OpenAI Chat Model, Simple Memory (for context), and the Supabase Vector Store (for RAG context retrieval).
Supabase Vector Store n8n node: Configured as a tool for the AI Agent, allowing the agent to access and retrieve relevant information from an external vector database (RAG knowledge base).

Related n8n Workflows

Free

Nodes: 15 Nodes
Updated: December 26 2025
View all
Created by
Kirill Zolygin
Kirill Zolygin

Featured*