Respond to Telegram messages with intelligent agent and query buffering
Workflow Description
This automation receives Telegram messages, buffers them into batches for efficiency, then processes them through an AI agent powered by OpenAI while maintaining conversation context in Postgres for coherent, stateful interactions.
How it works
- 1.Receive incoming Telegram messages via the dedicated trigger node
- 2.Buffer and aggregate consecutive messages by time and sender to optimize resource usage
- 3.Process queries through an AI agent powered by OpenAI with access to previous conversation history
- 4.Store context and responses in Postgres to ensure conversation continuity and memory
- 5.Send the AI-generated reply back to the user in Telegram
Use cases
- Automated customer support bot on Telegram that learns from conversation history
- Intelligent bot that groups similar questions and answers them in batches
- Personal AI assistant that maintains long-term conversation memory
- Autonomous Telegram channel responder with full contextual understanding
Requirements
- Active Telegram Bot account with its API token configured
- OpenAI API key for accessing the language model
- Postgres database set up to store conversation context and message history
- Supabase account for simplified data management interface (optional)
Service Value
Ideal as a smart automation service combining integrations and AI to produce ready-to-use results.
Apps Used
Details
How to Use
- 1.Click "Download Template"
- 2.Open your n8n dashboard
- 3.Go to Workflows > Import from File
- 4.Select downloaded file and configure credentials
Nodes Used (22)
Sticky Note
Sticky Note
Sticky Note1
Sticky Note
Reply
Set
Receive Message
Set
Wait 10 Seconds
Wait
Sticky Note3
Sticky Note
Add to Queued Messages
Supabase
No Operation, do nothing
No Op
Aggregate
Aggregate
Delete Queued Messages
Supabase
Sticky Note2
Sticky Note
OpenAI Chat Model
OpenAI
Sort by Message ID
Sort
Get Queued Messages
Supabase
Check Most Recent Message
If
AI Agent
Agent
Postgres Chat Memory
Memory Postgres Chat
Sticky Note4
Sticky Note
Sticky Note5
Sticky Note
Sticky Note6
Sticky Note
Sticky Note8
Sticky Note
Sticky Note9
Sticky Note