AI Agents

Respond to Telegram messages with intelligent agent and query buffering

22 nodes 306 150 Automatic trigger
Download

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. 1.Receive incoming Telegram messages via the dedicated trigger node
  2. 2.Buffer and aggregate consecutive messages by time and sender to optimize resource usage
  3. 3.Process queries through an AI agent powered by OpenAI with access to previous conversation history
  4. 4.Store context and responses in Postgres to ensure conversation continuity and memory
  5. 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

Telegram Supabase OpenAI Sort AI Agent Postgres

Details

Trigger Automatic trigger
Nodes 22
Apps 6
Views 306
Downloads 150

How to Use

  1. 1.Click "Download Template"
  2. 2.Open your n8n dashboard
  3. 3.Go to Workflows > Import from File
  4. 4.Select downloaded file and configure credentials

Nodes Used (22)

/

Sticky Note

Sticky Note

#1

Sticky Note1

Sticky Note

#2

Reply

Set

#3

Receive Message

Set

#4

Wait 10 Seconds

Wait

#5

Sticky Note3

Sticky Note

#6

Add to Queued Messages

Supabase

#7

No Operation, do nothing

No Op

#8

Aggregate

Aggregate

#9

Delete Queued Messages

Supabase

#10

Sticky Note2

Sticky Note

#11

OpenAI Chat Model

OpenAI

#12

Sort by Message ID

Sort

#13

Get Queued Messages

Supabase

#14

Check Most Recent Message

If

#15

AI Agent

Agent

#16

Postgres Chat Memory

Memory Postgres Chat

#17

Sticky Note4

Sticky Note

#18

Sticky Note5

Sticky Note

#19

Sticky Note6

Sticky Note

#20

Sticky Note8

Sticky Note

#21

Sticky Note9

Sticky Note

#22