n8n Telegram AI Chatbot 2026: Build a Bot With Memory (ChatGPT-Powered)

This n8n workflow creates a ChatGPT-powered Telegram chatbot that remembers your conversation history — no server, no code. Deploy in 15 minutes and give your bot real memory.
telegramTrigger
googleSheets
switch
+9
Workflow Identifier: 1646
NODES in Use: telegramTrigger, googleSheets, switch, code, telegram, lmChatOpenAi, memoryBufferWindow, agent, chainSummarization, chainLlm, set, stickyNote
Automate Telegram chatbot with n8n and OpenAI

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:
ChatGPT (OpenAI GPT-4o-mini): The AI brain of this chatbot.
The same model that powers ChatGPT — running inside your own
Telegram bot, with no monthly ChatGPT subscription needed.
You pay only for what you use via the OpenAI API.


What This Automation Does

This workflow is a fully automated AI image generator built inside
n8n. Type a text prompt — and it generates a high-quality FLUX image
and saves it directly to your Google Drive. No manual downloading,
no copy-pasting URLs, no babysitting the process.

Here’s exactly what happens:

→ You provide a text prompt describing the image you need
→ n8n sends it to the FLUX AI model via fal.ai API
→ The workflow polls every 3 seconds until the image is ready
→ It downloads the image and uploads it straight to your Google Drive folder

One prompt. One click. Image saved — ready to use for social media,
ads, blog posts, or any project.


Tools and Services Used


How the Workflow Works

Inputs

 

Processing Steps

 

Outputs

  • Clean chatbot answers sent to user chats.
  • Session summaries when requested.
  • Answers to past-chat questions.

Who Should Use This Workflow

Support teams handling many users through Telegram bots.

Anyone who wants to save time and keep chatbot talks clear.

People needing multiple sessions with easy resume and summary.


Beginner Step-by-Step: How to Use This Workflow in n8n

Download and Import

  1. Download the workflow file using the Download button on this page.
  2. Open n8n editor where you want to run the bot.
  3. Use Import from File option to upload the downloaded workflow.

 

Configure Credentials and IDs

  1. Add your Telegram Bot API credentials in the Telegram Trigger nodes.
  2. Put your OpenAI API Key into the Langchain OpenAI Chat Model nodes.
  3. Update Google Sheets document ID and sheet names if different from default.
  4. Check and copy/paste code snippets provided in the workflow for session extraction or question parsing.

 

Test the Workflow

  1. Send sample commands like /new or a chat message to test the flow.
  2. Look in n8n execution output if the nodes work without errors.

 

Activate Workflow

  1. Toggle the workflow switch to active when ready.
  2. Check Telegram bot replies to confirm it handles multiple sessions.
  3. Make sure the Google Sheets updates show session changes after commands.

 

For advanced control or more security, consider self-host n8n.


Key Code Snippets to Use

Extract Session from “/resume” Command

This code finds the session ID user writes after /resume.

for (const item of $input.all()) {
  const text = item.json.text || '';
  const match = text.match(/\/resume\s+(.*)/);

  if (match) {
    item.json.resume = match[1].trim();
  } else {
    item.json.resume = null; 
  }
}
return $input.all();

 

Extract Question from “/question” Command

This code reads the question text after /question command.

for (const item of $input.all()) {
  const text = item.json.text || '';
  const match = text.match(/\/question\s+(.*)/);

  if (match) {
    item.json.question = match[1].trim();
  } else {
    item.json.question = null;
  }
}
return $input.all();

Customization Ideas

  • Add more commands like /help by updating the Switch node.
  • Use a different GPT-4 or GPT-3.5 model in the AI nodes to save cost or add features.
  • Extending session expiry times in Google Sheets helps keep sessions longer.
  • Store chat data in other databases like Airtable or MySQL for larger scale.
  • Change Telegram messages to have clearer or richer text and formatting.

Troubleshooting

  • Issue: No current session found after starting new.
    Fix: Check Google Sheets update nodes to ensure current session state is set and old sessions expire.
  • Issue: Telegram Trigger does not get messages.
    Fix: Verify webhook URL in Telegram BotFather and confirm message update type enabled.
  • Issue: AI answers forget past chats or sound off.
    Fix: Confirm session key passes correctly to Simple Memory node.
  • Issue: Question answering returns irrelevant replies.
    Fix: Check code nodes combining chat history and prompt format before AI call.

Pre-Production Checklist

  • Check Telegram Bot API credentials and webhook are correct.
  • Make sure Google Sheets document IDs and sheet names match your setup.
  • Try sending all commands (/new, /resume, /summary, /question) and check responses.
  • Confirm OpenAI API key works and has enough quota.
  • Activate workflow after successful test.

Summary and Results

✓ Saves at least 5 hours weekly by automating session management.

✓ Avoids user confusion by keeping chat context clear.

✓ Lets users start new chats, resume past sessions, and get summaries easily.

→ Improves customer experience and team efficiency.


Automate Telegram chatbot with n8n and OpenAI

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

Yes, other GPT-4 variants or GPT-3.5 compatible with Langchain nodes can be used.
Chat and session data is stored securely in Google Sheets controlled by the user.
It supports small to medium volumes; high scale needs database optimization.
Check that the session key is properly passed to the Simple Memory node to keep context.
Author
Written By
Ankit Sharma

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.