DeepSeek AI Agent with Persistent Telegram Memory via Google Docs - n8n Workflow

Deploy a powerful n8n workflow that connects Telegram to a DeepSeek AI Agent, featuring long-term memory storage via Google Docs using specialized n8n templates and custom n8n nodes.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Developers and power users looking to implement sophisticated AI chat agents.
Anyone needing an n8n solution for persistent memory in conversational AI.
Users deploying Telegram bots that require customized, multi-turn context retention.
Organizations utilizing DeepSeek models via OpenAI-compatible API setups.

Overview

This complex n8n workflow addresses the challenge of creating a conversational AI that remembers past interactions over time—a key limitation of standard LLM calls. By leveraging a specific n8n trigger (Telegram Webhook) and integrating Google Docs as a long-term knowledge base, this n8n template empowers a DeepSeek Agent to retrieve and store personalized user data. The custom system prompt guides the AI to use the Save Memory tool when important information is shared, ensuring a personalized and contextually aware user experience within Telegram. This specialized n8n node setup is ideal for building highly reliable and stateful chatbots.

How it Works


  1. The n8n workflow starts with the Listen for Telegram Events n8n trigger, capturing incoming messages via a webhook on the /wbot path.

  2. A Validation set n8n node is followed by the Check User & Chat ID if n8n node, restricting access only to a predefined user based on name and ID for security.

  3. Valid text messages are routed by the Message Router switch n8n node, while non-text inputs result in an error response.

  4. The Retrieve Long Term Memories Google Docs n8n node fetches the current long-term context associated with the user from the specified document.

  5. This memory data is merged with the incoming message context using the Merge n8n node.

  6. The combined data feeds into the central AI Agent n8n node. This agent operates under a detailed system prompt, utilizing the memory context to decide its response and whether to employ the Save Long Term Memories tool. The agent uses a DeepSeek Language Model (DeepSeek-V3 Chat).

  7. If the agent decides to save data, the Save Long Term Memories Google Docs Tool n8n node inserts a new, summarized memory entry into the dedicated document, thus updating the long-term memory for this n8n workflow.

  8. Finally, the agent’s text output is sent back to the user via the Telegram Response n8n node, completing the automation cycle.

Installation Guide


  1. Import the n8n Workflow: Copy the provided n8n workflow JSON and paste it into your n8n instance using the "New" > "Import from JSON" option.

  2. Configure Credentials: Set up required credentials for:

Telegram: Provide your bot token to the Telegram API n8n node credentials.
DeepSeek (OpenAI API Compatibility): Create an OpenAI API credential, but configure it to use the DeepSeek API base URL (e.g., https://api.deepseek.com/v1) as noted in the sticky note.
* Google Docs: Authenticate your Google Docs OAuth2 API credential, ensuring it has read/write access to the documents.

  1. Set Up Validation: Modify the Validation set n8n node to include the exact firstname, lastname, and numerical id of the authorized Telegram user.

  2. Define Memory Location: Update the documentURL parameter in both the Retrieve Long Term Memories and Save Long Term Memories n8n nodes with the actual ID or URL of your dedicated Google Doc memory file.

  3. Activate Webhook: Enable the n8n workflow. Then, configure your Telegram bot to use the webhook path defined in the Listen for Telegram Events n8n trigger (Path: /wbot).

Node Details

Listen for Telegram Events (Webhook n8n trigger): The initial n8n node that acts as the webhook listener for incoming messages from the Telegram Bot API.
Validation (Set n8n node): Hardcodes the authorized user's personal details (firstname, lastname, and id) to ensure only authorized individuals can interact with the bot.
Check User & Chat ID (If n8n node): Compares the incoming Telegram sender details against the hardcoded validation data. It stops the n8n workflow if the user is unauthorized, directing them to an error message.
Retrieve Long Term Memories (Google Docs n8n node): Reads the entire contents of the specified Google Doc. This content is injected directly into the AI agent's system prompt as historical context.
AI Agent (LangChain Agent n8n node): The core intelligence of the n8n workflow. It is configured with a complex system prompt defining its persona and rules, receives context from retrieved memory, and has the ability to use the Google Docs Tool to save new memories.
DeepSeek-V3 Chat (LM Chat OpenAI n8n node): Configured as the underlying large language model for the agent (using the deepseek-chat model name), leveraging the OpenAI-compatible n8n node for execution.
Save Long Term Memories (Google Docs Tool n8n node): An agent tool accessible to the AI. When the AI determines information is noteworthy, it uses this tool to insert a new, timestamped memory entry into the Google Doc, facilitating long-term recall.
Telegram Response (Telegram n8n node): Sends the final, contextually aware response generated by the AI agent back to the originating Telegram chat, completing the n8n workflow execution.

Related n8n Workflows

Free

Nodes: 13 Nodes
Updated: December 26 2025
View all
Created by
Joseph LePage
Joseph LePage

As an AI Automation consultant based in Canada, I partner with forward-thinking organizations to implement AI solutions that streamline operations and drive growth.

Featured*