Debounce Telegram support messages and aggregate replies with OpenAI

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

0
Downloads
5
Views
8.26
Quality Score
beginner
Complexity
Author:Naveen Choudhary(View Original →)
Created:2/13/2026
Updated:3/19/2026

šŸ”’ Please log in to import templates to n8n and favorite templates

Workflow Visualization

Loading...

Preparing workflow renderer

Comments (0)

Login to post comments