Build DeepSeek AI Agent with Telegram & Long-Term Memory in n8n

Discover how to create a personalized AI assistant using DeepSeek, Telegram, and Google Docs for long-term memory storage. This workflow solves user interaction continuity by managing AI memory effectively with n8n automation.
webhook
agent
googleDocs
+8
Workflow Identifier: 2270
NODES in Use: webhook, set, if, switch, merge, telegram, agent, googleDocs, googleDocsTool, lmChatOpenAi, memoryBufferWindow
Automate AI assistant with Telegram and n8n

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

Learn how to Build this Workflow with AI:

What This Automation Does

This workflow listens for Telegram messages, checks if the sender is allowed, and sorts message types like text, audio, or images.
It then fetches past chat memories from Google Docs and combines them with the new message.
An AI chat model from DeepSeek makes replies based on the full context.
New useful info found is saved back to Google Docs.
Users get smart answers that remember history and fit their needs.

This stops repeated questions and saves hours spent looking back at old chats.
Errors are handled with polite Telegram messages.


Who Should Use This Workflow

This workflow fits anyone managing Telegram groups or channels who wants quick, smart replies with remembered context.
It helps people tired of manual chat memory checks and wanting better personalization.


Tools and Services Used

  • Telegram Bot API: Receives user messages.
  • Google Docs API: Stores and retrieves chat memories.
  • DeepSeek AI Agent: Processes messages and generates replies using long-term memory.
  • n8n Automation Platform: Orchestrates the workflow nodes.

How The Workflow Works: Input → Process → Output

Input

  • Telegram messages sent to the bot.
  • User details to check authorization.

Processing Steps

  • Webhook nodes catch the Telegram messages.
  • Validation nodes check if user ID and name match authorized users.
  • Message Router separates text, audio, or images for handling.
  • Google Docs node reads stored memories.
  • Merge node adds memory content to current message.
  • AI Agent node runs DeepSeek model to create replies using full context.
  • Google Docs node appends new memory text with timestamps.
  • Telegram node sends the AI reply back.
  • Error handling nodes send polite messages if issues happen.

Output

  • Telegram messages with smart, personalized replies.
  • Updated Google Docs with new conversation memories.

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

Step 1: Import the Workflow

  1. Download the workflow JSON file from this page.
  2. Open the n8n editor and choose “Import from File”.
  3. Select the downloaded workflow file and load it.

Step 2: Add Credentials

  1. Provide the Telegram Bot API token in the Telegram nodes.
  2. Connect Google Docs account in the Google Docs nodes with OAuth2.
  3. Set API key for DeepSeek AI Agent node.

Step 3: Update IDs and Settings

  1. Check and edit authorized user IDs and names in the Validation node.
  2. Change Google Docs document ID to your memory document.

Step 4: Test the Workflow

  1. Send a message to your Telegram bot and confirm it replies properly.
  2. Make sure memories load, responses are relevant, and errors handled politely.

Step 5: Activate for Production

  1. Turn on the workflow toggle in n8n editor.
  2. Ensure the webhook URL remains reachable for Telegram.
  3. If you self host n8n, keep the server running for reliable operation. See self-host n8n.

Edge Cases and Error Handling

  • If unauthorized users message the bot, a polite refusal reply is sent.
  • Messages types other than text, audio, and images are routed to error messages.
  • If Google Docs fails to load memory, AI replies without past context.
  • General errors trigger friendly Telegram notifications without technical details.

Customization Ideas

  • Allow more users by adding their IDs to the Validation node.
  • Add support for videos or documents in the Message Router node.
  • Switch AI models in the AI Agent node to DeepSeek “deepseek-reasoner” for different AI behavior.
  • Store memories in Google Sheets or a database instead of Google Docs.

Summary and Results

✓ The workflow gives clear, remembered responses on Telegram.
✓ It cuts down hours spent on manual chat checks.
✓ Users get replies that fit their conversation history.
→ More engagement and less repeated questions happen.
→ The AI keeps learning for future chats.


Automate AI assistant with Telegram and n8n

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

The workflow uses the Validation node and an If node to compare incoming user data with stored authorized user details.
If Google Docs memory fails to load, the AI still replies but without past conversation context.
Yes, the workflow allows switching the AI Agent node to other OpenAI-compatible models like DeepSeek’s “deepseek-reasoner”.
Add their exact IDs and names in the Validation node and adjust the If node conditions accordingly.

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.