workflows.fit
Back to n8n workflows
n8n templateFreeBy Naveen Choudhary

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...

DevelopmentData & StorageCommunicationHITLCore NodesAILangchainUtility
Loading interactive preview...

Template notes

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 usersessions table containing columns: userid, sessionid, messages (jsonb array), firstmessageat, waitexpiresat, status, and resumeurl - n8n instance (self-hosted or cloud)

How to set up