Category: Automations › WhatsApp, SMS & Messaging · Best for: Businesses running a Telegram support bot · Platform: n8n · Steps: 31
What it does
A Telegram AI bot that remembers each person's chat separately.
This workflow creates an AI-powered Telegram chatbot with session management, allowing users to:
Works with: Telegram, OpenAI, Memory Buffer Window, Google Sheets, Agent, Chain Summarization, Chain Llm
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:
- OpenAI API key: how to connect (used by OpenAI Chat Model, OpenAI Chat Model1, OpenAI Chat Model2)
- Telegram bot token from @BotFather: how to connect (used by Get message, Session activated, Send response, OK, KO, Send summary, Send answer, Send current session)
- Google (Sheets, Gmail, Drive, Calendar, Docs): how to connect (used by Get session, Disable previous session, Set new session, Update database, Set to expire, Get session1, Set new current session, Response + Text)
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:
- Get session →
sheetName: choose your own - Get session →
documentId: choose your own - Disable previous session →
sheetName: choose your own - Disable previous session →
documentId: choose your own - Set new session →
sheetName: choose your own - Set new session →
documentId: choose your own - Session activated →
chatId: choose your own - Send response →
chatId: choose your own - Update database →
sheetName: choose your own - Update database →
documentId: choose your own - Set to expire →
sheetName: choose your own - Set to expire →
documentId: choose your own - OK →
chatId: choose your own - KO →
chatId: choose your own - Get session1 →
sheetName: choose your own
- Get session →
- Click Save.
Test it
- Click Test workflow (or Execute workflow). Get 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
- Get message starts the workflow (Telegram).
- OpenAI Chat Model uses AI (OpenAI).
- Simple Memory uses AI (Memory Buffer Window).
- OpenAI Chat Model1 uses AI (OpenAI).
- OpenAI Chat Model2 uses AI (OpenAI).
- Get session uses Google Sheets.
- Telegram Chatbot uses AI (Agent).
- Summarization Chain uses AI (Chain Summarization).
- Basic LLM Chain uses AI (Chain Llm).
- Command or text? checks a condition and routes items accordingly.
- Send response uses Telegram.
- Send summary uses Telegram.
- Send answer uses Telegram.
- Disable previous session uses Google Sheets to update.
- Send current session uses Telegram.
- Get message1 reshapes the data for the next step.
- Get session1 uses Google Sheets.
- Get message2 reshapes the data for the next step.
- Update database uses Google Sheets to append.
- Set new session uses Google Sheets to append.
- Trim resume reshapes the data for the next step.
- Prompt + Resume reshapes the data for the next step.
- Trim question reshapes the data for the next step.
- Session activated uses Telegram.
- Set to expire uses Google Sheets to update.
- Response + Text uses Google Sheets.
- Set new current session uses Google Sheets to update.
- fullText reshapes the data for the next step.
- Exist? checks a condition and routes items accordingly.
- KO uses Telegram.
- OK uses Telegram.
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:
Telegram ChatBot with multiple sessions
This workflow creates an AI-powered Telegram chatbot with session management, allowing users to:
-
Start new conversations (
/new). -
Check current sessions (
/current). -
Resume past sessions (
/resume). -
Get summaries (
/summary). -
Ask questions (
/question). -
Clone this sheet
NEW SESSION
GET CURRENT SESSION
RESUME SESSION
GET SUMMARY
SEND QUESTION
CHATBOT
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