Build an AI Chatbot with Long-Term Memory & Telegram Integration using n8n

Learn how to create a powerful AI chatbot using n8n that remembers past conversations with long-term memory in Google Docs and interacts via Telegram. This workflow transforms chatbots with context-aware, personalized responses reducing user frustration and saving hours of repetitive answering.
chatTrigger
googleDocs
agent
+8
Workflow Identifier: 1181
NODES in Use: chatTrigger, stickyNote, lmChatOpenAi, set, memoryBufferWindow, googleDocsTool, googleDocs, merge, aggregate, agent, telegram

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

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

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.


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 Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free