Build a Telegram AI Chatbot with Long-Term Memory Using n8n [2026]

Create a Telegram chatbot that remembers users across sessions using n8n and vector storage. Includes full workflow JSON and memory architecture guide.
chatTrigger
googleDocs
agent
+8
Workflow Identifier: 1181
NODES in Use: chatTrigger, stickyNote, lmChatOpenAi, set, memoryBufferWindow, googleDocsTool, googleDocs, merge, aggregate, agent, telegram
Automate Telegram chatbot with n8n and OpenAI

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

Learn how to Build this Workflow with AI:

What This Automation Does

This workflow listens to messages from users and answers with an AI chatbot that remembers past talks and notes saved in Google Docs.
It solves the problem of chatbots forgetting what was said before, making chats smoother and helping save time.
The chatbot replies using previous memories and notes, then updates them in Google Docs.
It also can send answers back through Telegram for easy chatting.


Tools and Services Used


Inputs → Processing → Outputs Explained

Inputs

  • User chat messages come in via the LangChain Chat Trigger node.
  • Stored long-term memories are fetched from a Google Docs document.
  • Previously saved notes are retrieved separately from another Google Docs document.

Processing Steps

  • A Merge node combines memories and notes data to give the AI a full context.
  • The Aggregate node groups this data for easy use by the AI Tools Agent.
  • The AI Tools Agent node uses the chat input plus the retrieved memories and notes to create a relevant answer.
  • The Window Buffer Memory node keeps track of recent messages to maintain conversation flow.
  • After answering, updated memories and notes are written back to their Google Docs via respective Google Docs Tool nodes.
  • An optional OpenAI GPT-4o-mini node produces fallback or enhanced chat replies.

Outputs

  • Collected AI answers are sent back to users on Telegram using the Telegram node.
  • A Set node formats the final response data for logging or further use.

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

Importing and Setup

  1. Download the workflow file using the Download button on this page.
  2. Open the n8n editor where the workflow will run.
  3. Click “Import from File” and select the downloaded workflow file.
  4. Add API credentials in n8n if missing, such as OpenAI API Key, Google Docs OAuth2, and Telegram bot credentials.
  5. Update any hardcoded IDs or URLs, like Google Doc URLs, folder IDs, or Telegram chat IDs.
  6. Check prompts or system messages in the AI nodes and copy-paste any code or URLs if provided.

Testing and Activation

  1. Send a test message through the input method (e.g., Telegram) to verify the workflow triggers properly.
  2. Look at the execution logs and ensure the AI generates answers and remembers previous info.
  3. Once testing succeeds, toggle the workflow status to “active” in n8n to start production use.

For secure, privacy-focused use of this workflow, consider self-host n8n on your own server.


Common Customizations

  • Replace Google Docs nodes with Google Sheets or external databases by updating URLs and node settings.
  • Make Telegram chat IDs dynamic by pulling them from incoming messages instead of fixed values.
  • Edit the system prompt in AI Tools Agent to change chatbot tone or memory rules.
  • Change how much recent chat is kept by adjusting the Window Buffer Memory node’s contextWindowLength setting.
  • Add extra logging or error-catching nodes to track workflow status.

Troubleshooting Tips

  • If Google Docs nodes return no data, check the document URLs and OAuth permissions.
  • If messages don’t send in Telegram, verify the bot permissions and chat ID are correct.
  • If the AI Tools Agent node gives no answer, confirm system prompt settings plus map chat input properly.

Pre-Production Checklist

  • Verify Google Docs URLs and OAuth tokens are active.
  • Test webhook triggers before going live.
  • Check AI node generates good replies.
  • Confirm Telegram node can send test messages.
  • Ensure session memory preserves recent chat context.

Summary of Benefits and Outcomes

✓ Saves time by automating replies that remember past talks.
✓ Reduces repetitive questions and misunderstandings.
✓ Stores notes and memories securely in Google Docs.
✓ Works through Telegram for familiar user chatting.
✓ Easy to import, configure, and activate in n8n.


Automate Telegram chatbot with n8n and OpenAI

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

Yes, Google Sheets nodes can be used instead, but the workflow settings must be updated to handle different data formats.
Yes, every AI call with OpenAI models counts against the user’s API usage quota.
Security depends on Google Docs permissions and n8n setup. Use restricted sharing and encrypted connections to protect data.
Yes, by changing the chat trigger and messaging nodes, the workflow can support platforms like Slack or WhatsApp.

Promoted by BULDRR AI

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.