Debounce Telegram support messages and aggregate replies with OpenAI

Go to Workflow
5 views
Built by Naveen Choudhary Naveen Choudhary
Created on June 05, 2026

Description

This workflow prevents your AI support bot from responding to every single message by intelligently aggregating rapid-fire messages from users before generating a comprehensive response.

Who's it for

Support teams and bot developers who want to provide better AI responses by letting users fully explain their issue before the bot responds, reducing unnecessary back-and-forth and improving response quality.

How it works

When a user sends a message to your Telegram bot, the workflow:
Checks if the user has an active session within the last 60 seconds
If no session exists, creates a new one and starts a 60-second timer
If a session is active, appends the new message to the existing conversation
After 60 seconds of the first message, fetches all aggregated messages
Sends the complete conversation to OpenAI for a comprehensive response
Delivers the AI-generated answer back to the user via Telegram
Clears the session for the next interaction

Requirements

Telegram bot token (set up via BotFather)
OpenAI API key
PostgreSQL database with a user_sessions table containing columns: user_id, session_id, messages (jsonb array), first_message_at, wait_expires_at, status, and resume_url
n8n instance (self-hosted or cloud)

How to set up

Configure your Telegram credentials in the Telegram Trigger node
Add your OpenAI API key to the OpenAI Chat Model node
Set up PostgreSQL credentials and create the required database table
Adjust the wait time (default 60 seconds) in the Wait node if needed
Activate the workflow and test with your Telegram bot

How to customize

Modify the aggregation window by changing the wait duration
Customize the AI prompt in the AI Agent node for different response styles
Add additional logic to handle specific keywords or commands
Integrate other AI models or add context from external sources

Nodes Used (5)

AI Agent
@n8n/n8n-nodes-langchain.agent
Code
n8n-nodes-base.code
OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi
Postgres
n8n-nodes-base.postgres
Telegram
n8n-nodes-base.telegram