Category: Automations › WhatsApp, SMS & Messaging · Best for: Bots that need natural, grouped replies · Platform: n8n · Steps: 13
What it does
The bot waits until the person finishes typing, then sends one clear reply.
Allow Users to Send a Sequence of Messages to an AI Agent in Telegram with Supabase
Works with: Telegram, OpenAI, Memory Postgres Chat, Supabase, Agent
What you get
- The n8n workflow file (
workflow.json), ready to import - This setup guide
- The list of fields to change for your own accounts (see Install below)
- Email support if you get stuck
Before you start
-
An n8n account. Easiest: n8n Cloud (free trial). Self-host for free with Docker:
docker run -it --rm -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n, then open http://localhost:5678. -
Accounts and API keys for these services:
- Telegram bot token from @BotFather: how to connect (used by Reply, Receive Message)
- Supabase project: how to connect (used by Add to Queued Messages, Delete Queued Messages, Get Queued Messages)
- OpenAI API key: how to connect (used by OpenAI Chat Model)
- PostgreSQL database: how to connect (used by Postgres Chat Memory)
Install
- In n8n, click Create workflow (top right).
- Click the ⋯ menu → Import from file and choose
workflow.json. Or open the file, copy everything and paste it onto the empty canvas with Ctrl/Cmd + V. - Open each node with a red warning triangle and pick or create the matching credential from the list above.
- Point these fields at your own sheets, chats and accounts:
- Reply →
chatId: choose your own
- Reply →
- Click Save.
Test it
- Click Test workflow (or Execute workflow). Receive Message starts it. Trigger it once with real sample data.
- Click each node to check its output. A green tick means the step worked.
- Fix any red node: it's almost always a credential or a field that still points at a sheet or chat that isn't yours.
Go live
Toggle Active (top right). From now on it runs on its own. Check Executions in the left sidebar to see every run.
How it works, step by step
- Receive Message starts the workflow (Telegram).
- OpenAI Chat Model uses AI (OpenAI).
- Postgres Chat Memory uses AI (Memory Postgres Chat).
- Add to Queued Messages uses Supabase.
- AI Agent uses AI (Agent).
- Wait 10 Seconds pauses before continuing.
- Reply uses Telegram.
- Get Queued Messages uses Supabase to getAll.
- Sort by Message ID uses Sort.
- Check Most Recent Message checks a condition and routes items accordingly.
- Delete Queued Messages uses Supabase to delete.
- No Operation, do nothing uses No Op.
- Aggregate uses Aggregate.
India & US notes
India: use the official WhatsApp Business Cloud API from Meta (free to start, pay per conversation). Unofficial WhatsApp tools can get your number banned. US: the same API works; SMS via Twilio is a good fallback.
Extra setup notes
These notes are also on the canvas as yellow sticky notes:
1. Receive Message
3. AI Assistant
2. Buffer Incoming Messages
4. Send Reply
Allow Users to Send a Sequence of Messages to an AI Agent in Telegram with Supabase
Use Case
When creating chatbots that interface through applications such as Telegram and WhatsApp, users can often sends multiple shorter messages in quick succession, in place of a single, longer message. This workflow accounts for this behaviour.
What it Does
This workflow allows users to send several messages in quick succession, treating them as one coherent conversation instead of separate messages requiring individual responses.
How it Works
- When messages arrive, they are stored in a Supabase PostgreSQL table
- The system waits briefly to see if additional messages arrive
- If no new messages arrive within the waiting period, all queued messages are:
- Combined and processed as a single conversation
- Responded to with one unified reply
- Deleted from the queue
Setup
- Create a table in Supabase called message_queue. It needs to have the following columns: user_id (
uint8), message (text), and message_id (uint8) - Add your Telegram, Supabase, OpenAI, and PostgreSQL credentials
- Activate the workflow and test by sending multiple messages the Telegram bot in one go
- Wait ten seconds after which you will receive a single reply to all of your messages
Modification
Change the value of Wait Amount to vary the buffering window
Modification
Replace this sub-node to use a different language model
Modification
Add a System Message to tailor the chatbot to your use case
Troubleshooting
- "Credentials not found": open the node and select your credential again.
- Google "access blocked": in Google Cloud, add your email as a test user on the OAuth consent screen.
- Webhook not firing: copy the node's Production URL (not Test URL) into the other app, and make sure the workflow is Active.
- AI node errors: check your API key has billing enabled and the model name exists on your plan.
- Nothing happens on schedule: the workflow must be Active, and self-hosted n8n must stay running.
Need help?
Reply to your Morning Method order email and we'll help you get it running.
© Morning Method