Enable AI Chatbot Long-Term Memory with n8n Tools Router

This n8n workflow equips AI chatbots with long-term memory capabilities using Google Docs, routing tools dynamically for saving, retrieving, and sending memories via Telegram or Gmail. Automate memory management to reduce repetitive queries and deliver personalized responses effortlessly.
ExecuteWorkflowTrigger
GoogleDocs
Set
+9
Workflow Identifier: 1314
NODES in Use: ExecuteWorkflowTrigger, GoogleDocs, Set, Telegram, Gmail, Switch, lmChatOpenAi, toolWorkflow, memoryBufferWindow, agent, chatTrigger, chainLlm
Enable AI chatbot memory with n8n and Google Docs

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

Learn how to Build this Workflow with AI:

What This Automation Does

This workflow is a smart AI agent that saves and finds important chat memories automatically.
It helps chatbot remember what users said before and share updates via Telegram and email.
This stops users from repeating themselves and keeps support staff informed without manual work.

The AI reads chat input, stores or gets memories from Google Docs, and sends notifications using clear routing rules in n8n.
This makes chatbot replies better and faster with long-term memory and shows info to the team on time.


Who Should Use This Workflow

This workflow suits tech startups or small companies wanting smarter chatbots.
It is good for teams that want to save key chat details automatically.
You should use it if you want to avoid manual memory tracking and improve customer support response.
Anyone with basic n8n experience can activate this without coding.


Tools and Services Used


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

Import Workflow

  1. Open the n8n editor.
  2. Download this workflow file using the Download button on this page.
  3. Use the n8n “Import from File” option to load the workflow into your editor.

Configure Credentials and Settings

  1. Add or update your OpenAI API Key in the credential manager.
  2. Set up Google Docs OAuth2 credentials with access to your memory document.
  3. Insert your Telegram Bot token and chat ID. Use environment variable {{ $env.TELEGRAM_CHAT_ID }} if needed.
  4. Update Gmail OAuth2 credentials for sending emails.
  5. Modify document URLs, email addresses, or other IDs if your account differs.

Test the Workflow

  1. Trigger a test message through the Chat Trigger node.
  2. Observe if memory saves to Google Docs.
  3. Check if notifications arrive in Telegram and email.

Activate for Production

  1. Toggle the workflow active in the n8n editor top-right corner.
  2. Ensure environment variables and credentials stay secure.
  3. Monitor executions in the n8n dashboard for errors.

Using this simple import and configure method lets beginners deploy the workflow fast without building from scratch.
For more hosting options on your own server, see self-host n8n.


Inputs, Processing Steps, and Outputs

Inputs

  • User chat messages come through a webhook in the Chat Trigger node.
  • Upstream workflows can also trigger the memory management workflow.

Processing Steps

  • The AI agent node reads chat text and decides action by setting a route.
  • The Switch node directs data to save memories, fetch past data, or send notifications.
  • Save memories are stored as JSON snippets with timestamps into a Google Docs file.
  • Retrieval nodes pull saved memories from that same Google Doc.
  • Message prep nodes format the retrieved data for either Telegram or Gmail.
  • Telegram and Gmail nodes send updates to the right channels.
  • A window buffer memory node keeps recent short-term chat context for smarter replies.

Outputs

  • Contextual chatbot replies with long-term memory awareness.
  • Notifications sent automatically to Telegram chats.
  • Email reports delivering formatted memory summaries.

Edge Cases and Common Failures

  • Google Docs 403 Error: Usually means OAuth2 permissions or document sharing is wrong. Recheck credentials and sharing.
  • AI Agent Routes Not Working: If route keys are incorrect or missing, routing fails. Make sure AI system messages output correct $json.route values.
  • Telegram Messages Not Received: Check bot token, chat ID, and environment variables. Test manually.

Customization Ideas

  • Switch Google Docs nodes to Google Sheets or databases to store memories differently.
  • Use different OpenAI GPT models by changing the model name in LangChain nodes.
  • Change message formats in Chain LLM nodes to fit brand or add info.
  • Add new routes in the Switch node to notify Slack or SMS.
  • Change short-term message history size in the buffer memory node.

Conclusion

✓ The workflow gives AI chatbots long-term memory to remember users better.

✓ Notifications keep support teams updated automatically via Telegram and email.

→ Manual tracking of chat info is removed.

→ Chatbots answer with more context and personalize conversations.

→ Teams save time on reporting and follow-ups.


Enable AI chatbot memory with n8n and Google Docs

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

The AI agent sets a route property in its output. The Switch node reads this and sends data to save, retrieve, or notify tools accordingly.
Google Docs OAuth2 credentials with permission to access and update the specific document are required.
The workflow uses a Telegram Bot token and chat ID to send messages after formatting memory data.
Verify that the AI agent outputs the correct route keys like ‘save_memory’ or ‘retrieve_memory’ so the Switch node can route tasks properly.

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.