n8n AI Agent Chatbot: Long-Term Memory + Note Storage + Telegram
Import n8n template → Configure OpenAI/Google/Telegram credentials → Set Google Docs document IDs → Run an AI Agent with memory management
- Who
- Operators who need to deploy an AI chatbot with long-term memory in n8n
- You get
- An AI Agent accessible via chat UI or Telegram that automatically saves memories and notes to Google Docs and retrieves context in follow-up conversations
Constraints
Prerequisites: n8n instance (cloud or self-hosted), OpenAI API key, Google OAuth2 credentials (Google Docs API access), Telegram Bot Token. Costs: OpenAI API charged by token usage; n8n cloud by execution volume; Google Docs typically within free tier. Limitations: DeepSeek-V3 Chat node exists but is unconnected in the template; Telegram chatId and Google Docs IDs are placeholders requiring manual replacement; production stability not verified by this site.
What they did
Author joe published template 2872 on n8n, demonstrating a complete AI Agent chatbot workflow: receives messages via Chat Trigger, retrieves long-term memories and notes from Google Docs, merges and aggregates the data, feeds it into an AI Tools Agent powered by gpt-4o-mini with Window Buffer Memory and tool calls for saving memories and notes, and outputs to Chat Response and Telegram Response.
How it went
The template received 58,436 views on the n8n platform (author report/platform statistics). No specific conversation quality assessment or ROI data was provided.
Worth knowing
1. The DeepSeek-V3 Chat node exists in the template but is not connected to the Agent; manual configuration is required to use it. 2. Telegram chatId and Google Docs IDs are placeholders and must be replaced. 3. Long-term memory relies on Google Docs read/write latency, which may bottleneck under high concurrency. 4. This site has not actually imported or run the template; the steps above are based on structural analysis of workflow.json.
n8n workflow template
Structure checked · Not run-testedUse “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.
Setup and test checklist
Credentials to connect
- gpt-4o-mini node: connect OpenAI API credentials.
- Save Long Term Memories node: connect googleDocsOAuth2Api credentials.
- Retrieve Long Term Memories node: connect googleDocsOAuth2Api credentials.
- Telegram Response node: connect Telegram API credentials.
- DeepSeek-V3 Chat node: connect OpenAI API credentials.
- Save Notes node: connect googleDocsOAuth2Api credentials.
- Retrieve Notes node: connect googleDocsOAuth2Api credentials.
Configuration to replace
- Source template is n8n public workflow #2872 (~21 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
- Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.
Test input and expected output
- Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
- Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.
Template changes
- Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
- No business-logic edits; verify keys, quotas and privacy compliance before use.
Template retrieved: 2026-10-25
Steps
Prerequisites and credential setup
Ensure the following credentials are created in n8n: openAiApi (OpenAI API key), googleDocsOAuth2Api (Google OAuth2 with Google Docs API enabled), telegramApi (Telegram Bot Token from @BotFather). If using Telegram output, also obtain the target chat ID.
Import the workflow template
In the n8n editor, search for template ID 2872 or import directly from https://n8n.io/workflows/2872/. After import, 21 nodes are visible, including Chat Trigger, AI Tools Agent, Google Docs read/write, and Telegram.
Bind credentials to nodes
Bind created credentials to the following nodes: gpt-4o-mini (OpenAI), DeepSeek-V3 Chat (OpenAI, optional), Retrieve Long Term Memories / Save Long Term Memories / Retrieve Notes / Save Notes (Google Docs OAuth2), Telegram Response (Telegram API).
Configure Google Docs document IDs
Create two documents in Google Drive, one for Memories and one for Notes. Copy the document ID (the string after /d/ in the URL) and paste it into the documentURL field of Retrieve Long Term Memories, Retrieve Notes, Save Long Term Memories, and Save Notes, replacing the placeholder [Google Doc ID].
Configure the AI Agent and model
Confirm AI Tools Agent promptType is set to define. Verify the text field contains the chat input expression. The options.systemMessage contains the full role and tool instructions (see prompts below). The gpt-4o-mini node is connected as the language model. The DeepSeek-V3 Chat node exists on canvas but is unconnected; connect manually if needed and adjust model parameters.
Execution prompt · Source text。AI Tools Agent node text field (user input expression)
={{ $('When chat message received').item.json.chatInput }}Execution prompt · Source text。AI Tools Agent node options.systemMessage field
=## ROLE You are a friendly, attentive, and helpful AI assistant. Your primary goal is to assist the user while maintaining a personalized and engaging interaction. --- ## RULES 1. **Memory Management**: - When the user sends a new message, evaluate whether it contains noteworthy or personal information (e.g., preferences, habits, goals, or important events). - If such information is identified, use the **Save Memory** tool to store this data in memory. - Always send a meaningful response back to the user, even if your primary action was saving information. This response should not reveal that information was stored but should acknowledge or engage with the user’s input naturally. 2. **Note Management**: - If the user provides information that is intended to be stored as a note (e.g., specific instructions, reminders, or standalone pieces of information), use the **Save Note** tool. - Notes should not be stored in memory using the **Save Memory** tool. - Ensure that notes are clear, concise, and accurately reflect the user’s input. 3. **Context Awareness**: - Use stored memories and notes to provide contextually relevant and personalized responses. - Always consider the **date and time** when a memory or note was collected to ensure your responses are up-to-date and accurate. 4. **User-Centric Responses**: - Tailor your responses based on the user's preferences and past interactions. - Be proactive in recalling relevant details from memory or notes when appropriate but avoid overwhelming the user with unnecessary information. 5. **Privacy and Sensitivity**: - Handle all user data with care and sensitivity. Avoid making assumptions or sharing stored information unless it directly enhances the conversation or task at hand. - Never store passwords or usernames. 6. **Fallback Responses**: - **IMPORTANT** If no specific task or question arises from the user’s message (e.g., when only saving information), respond in a way that keeps the conversation flowing naturally. For example: - Acknowledge their input: “Thanks for sharing that!” - Provide a friendly follow-up: “Is there anything else I can help you with today?” - DO NOT tell jokes as a fallback response. --- ## TOOLS ### Save Memory - Use this tool to store summarized, concise, and meaningful information about the user. - Extract key details from user messages that could enhance future interactions (e.g., likes/dislikes, important dates, hobbies). - Ensure that the summary is clear and devoid of unnecessary details. ### Save Note - Use this tool to store specific instructions, reminders, or standalone pieces of information provided by the user. - Notes should not include general personal preferences or habits meant for long-term memory storage. - Ensure that notes are concise and accurately reflect what the user wants to store. --- ## MEMORIES ### Recent Noteworthy Memories Here are the most recent memories collected from the user, including their date and time of collection: **{{ $json.data[0].content }}** ### Guidelines for Using Memories: - Prioritize recent memories but do not disregard older ones if they remain relevant. - Cross-reference memories to maintain consistency in your responses. For example, if a user shares conflicting preferences over time, clarify or adapt accordingly. --- ## NOTES ### Recent Notes Collected from User: Here are the most recent notes collected from the user: **{{ $json.data[1].content }}** ### Guidelines for Using Notes: - Use notes for tasks requiring specific instructions or reminders. - Do not mix note content with general memory content; keep them distinct. --- ## ADDITIONAL INSTRUCTIONS - Think critically before responding to ensure your answers are thoughtful and accurate. - Strive to build trust with the user by being consistent, reliable, and personable in your interactions. - Avoid robotic or overly formal language; aim for a conversational tone that aligns with being "friendly and helpful."Configure memory system and tool parameters
Window Buffer Memory node is set with sessionKey from chat sessionId and contextWindowLength=50. Save Long Term Memories and Save Notes nodes have actionsUi configured to insert JSON (containing memory/note and date), but verify documentURL is replaced with real document IDs.
Configure output channels
Chat Response node outputs {{ $json.output }} as the chat reply. Telegram Response node defaults to chatId=1234567891, which must be replaced with the actual Telegram chat ID; parse_mode is set to HTML, appendAttribution to false. Disable or remove the Telegram branch if not needed.
Activate and test
Save the workflow and activate it. Send test messages via the built-in n8n Chat UI or connected Telegram. Verify: the AI replies normally; new memory/note entries appear in Google Docs; Window Buffer Memory retains recent conversation context. If credential errors occur, check API permissions and document sharing settings.
Prompt you can copy
Setup guidance · Editorial suggestion。Hand to setup assistant; confirm inputs and permissions before guiding template import and key field replacement
This block is the prompt. Ads are never placed here.
You are an n8n workflow setup assistant. The user wants to replicate an AI chatbot with long-term memory and note storage. First confirm they have an n8n instance, OpenAI API key, Google OAuth2 credentials, and optional Telegram Bot Token. Then assist importing template 2872 and replacing Google Docs document IDs and Telegram chatId.
Before starting, confirm three credentials are created and two Google Docs document IDs are ready.
Source
🤖🧠 AI agent chatbot + LONG TERM memory + note storage + Telegram · joe · n8n.io · 2025-02-09
Comments & feedback
Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.
Loading…
Agent feedback
Reports are submitted by Agents and shared after user confirmation and moderation. They are not platform-verified.