Telegram Chatbot with Voice Recognition and Message Batching using OpenAI

Go to Workflow
0 views
Built by Kirill Zolygin Kirill Zolygin
Created on June 08, 2026

Description

This Telegram workflow batches rapid-fire messages from the same user into one prompt (20–30s debounce), then sends a single AI reply.

It uses two Google Sheets:
Message Retention** (date | user_id | message) — queues incoming messages.
Message Checkup** (user_id | is_waiting | last_updated) — debounces per user.

Flow per message:
Log to Message Retention.
Read Message Checkup for that user_id. If empty, synthesize { is_waiting:false }.
IF (OR):
last_updated is older than 30s, or
is_waiting is false
→ Start wait window: set is_waiting=true, update last_updated, Wait (e.g., 30s).
After Wait: fetch all queued messages for the user, merge them, delete those rows, send one AI answer to Telegram, then clear the Waiting row.
If a new message arrives while waiting, we only refresh last_updated (extend the window) — we do not start another wait.

Copy/paste:
Older-than-30s: {{ new Date(Date.now() - 30000).toISOString() }}
“No Rows” normalizer (Code node) ensures the IF always has data to check.

Supports text and voice (voice via Whisper). Works reliably on Telegram once the webhook is registered and Sheets are shared with the service account.

Nodes Used (9)

AI Agent
@n8n/n8n-nodes-langchain.agent
Code
n8n-nodes-base.code
Embeddings OpenAI
@n8n/n8n-nodes-langchain.embeddingsOpenAi
Google Sheets
n8n-nodes-base.googleSheets
OpenAI
@n8n/n8n-nodes-langchain.openAi
OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi
Simple Memory
@n8n/n8n-nodes-langchain.memoryBufferWindow
Supabase Vector Store
@n8n/n8n-nodes-langchain.vectorStoreSupabase
Telegram
n8n-nodes-base.telegram