DeepSeek AI Agent: Telegram Bot with Google Docs Long-Term Memory
Integrates with:
Overview
Unlock Personalized & Context-Aware Interactions with this AI Agent
This n8n workflow deploys a sophisticated AI Agent on Telegram, powered by DeepSeek AI models (deepseek-chat
or deepseek-reasoner
). It's designed for rich, ongoing conversations by leveraging a unique long-term memory system built with Google Docs. The agent can recall past user interactions, preferences, and key information, delivering truly personalized and contextually relevant responses.
This AI Agent excels at:
- Intelligent Conversation: Engaging users naturally on Telegram, understanding intent, and providing helpful answers using DeepSeek's advanced language capabilities.
- Personalized Memory: Automatically identifying and saving noteworthy information from conversations into a designated Google Doc. This 'memory' is then retrieved in subsequent interactions to tailor responses.
- Contextual Understanding: Using both recent conversation history and long-term stored memories to maintain coherent and relevant dialogue.
Key Features & Benefits
- DeepSeek AI Integration: Utilizes powerful and cost-effective DeepSeek LLMs (OpenAI API compatible) for high-quality text generation and reasoning.
- Persistent Long-Term Memory: Connects to Google Docs to store and retrieve user-specific information, enabling conversations that evolve over time.
- Telegram Bot: Interacts with users directly within Telegram, a popular messaging platform.
- User-Specific Context: The AI Agent is prompted to remember the user's first name and use stored memories to personalize interactions.
- Memory Management Tool: Includes a 'Save Memory' tool (via Google Docs) that the AI Agent can invoke to store crucial details.
- Customizable System Prompt: Define the AI Agent's personality, rules, and how it should use memories and tools.
- Message Routing: Basic routing for different message types (text, audio, image), with text messages processed by the AI.
- Optional Short-Term Memory: Includes a 'Window Buffer Memory' node (can be connected for session-specific memory, if needed).
- User Validation (Placeholder): A basic mechanism to check user ID, which can be customized for specific user access or removed.
Use Cases
- Building a personal knowledge assistant on Telegram that learns about your interests and projects over time.
- Automating initial customer support for e-commerce businesses on Telegram, where the agent remembers customer history for tailored help.
- Creating an internal FAQ bot for SaaS companies that stores and recalls solutions to common employee queries, improving internal efficiency.
- Developing a coaching or mentoring bot that tracks progress and preferences shared by users in past Telegram sessions.
Prerequisites
- An n8n instance (Cloud or self-hosted).
- DeepSeek API Key (or other OpenAI-compatible API key and endpoint if adapting).
- Telegram Bot Token (obtain from BotFather) and a publicly accessible n8n webhook URL for Telegram updates.
- Google Cloud Project with Google Docs API enabled, OAuth 2.0 credentials, and the ID of a Google Doc to be used for storing memories.
- (Optional) Customize the 'Validation' node values or logic if specific user restriction is needed.
Setup Instructions
- Download the n8n workflow JSON file.
- Import the workflow into your n8n instance.
- Telegram Setup:
- In the 'Listen for Telegram Events' (Webhook) node, copy the TEST webhook URL. Register this URL with your Telegram Bot using the method described in the workflow's 'How to set up a Telegram Bot WebHook' sticky note (requires your Bot Token).
- Configure the 'Telegram Response', 'Error message', and 'Response Error message' nodes with your Telegram API credentials.
- User Validation (Optional):
- Modify the 'Validation' node: update the
first_name
,last_name
, andid
values to match the authorized Telegram user. Alternatively, remove or adapt this validation logic as needed.
- Modify the 'Validation' node: update the
- DeepSeek AI Configuration:
- In n8n, create new 'OpenAI API' credentials, naming it (e.g., 'DeepSeek API').
- Enter your DeepSeek API Key.
- Set the 'Base URL' to
https://api.deepseek.com
(orhttps://api.deepseek.com/v1
). - Select these credentials in the 'DeepSeek-V3 Chat' (or 'DeepSeek-R1 Reasoning' if you switch) node. This node is connected to the 'AI Agent'.
- Google Docs Long-Term Memory:
- Create or identify a Google Doc to store memories. Note its Document ID (from the URL).
- Configure the 'Retrieve Long Term Memories' (Google Docs node) with your Google Docs API credentials and the Document ID/URL.
- Configure the 'Save Long Term Memories' (Google Docs Tool node) with the same credentials and Document ID/URL. Ensure the tool description is set (e.g., 'Save memories').
- AI Agent Configuration:
- Review and customize the
systemMessage
in the 'AI Agent' node to define its personality, rules, and how it interacts with memories. Pay attention to the{{ $('Retrieve Long Term Memories').item.json.content }}
expression which injects memories.
- Review and customize the
- (Optional) Short-Term Memory: If you wish to use session-specific short-term memory, connect the 'Window Buffer Memory' node's output to the 'AI Agent' node's 'Memory' input. Configure the 'Window Buffer Memory' node (e.g., session key like
{{ $('Listen for Telegram Events').item.json.body.message.from.id }}
). - Activate the workflow. After activation, use the PRODUCTION webhook URL from the 'Listen for Telegram Events' node for your Telegram bot.
Want your own unique AI agent?
Talk to us - we know how to build custom AI agents for your specific needs.
Schedule a Consultation