DeepSeek AI Agent: Build Long-Term Memory Telegram Bots with OpenAI API
detail.loadingPreview
Automate Telegram bots with DeepSeek AI, OpenAI API, and long-term memory. Build intelligent agents that learn and personalize interactions.
🚀Ready to Deploy This Workflow?
About This Workflow
How it works
This n8n workflow orchestrates a sophisticated Telegram bot powered by the DeepSeek AI agent. It begins by listening for incoming Telegram messages via a webhook. The workflow then validates the user and chat ID to ensure legitimate interaction. Message content is routed to either text, audio, or image processing. For text messages, the core logic involves retrieving long-term memories from Google Docs, merging this context with the current message, and feeding it to a DeepSeek AI agent (either DeepSeek-V3 Chat or DeepSeek-R1 Reasoning) configured with an OpenAI-compatible API. The AI agent leverages the retrieved memories and system prompts to generate a personalized and context-aware response. Optionally, this interaction data can be saved to a window buffer memory and long-term memory in Google Docs. Finally, the generated response is sent back to the user via Telegram.
Key Nodes Used:
- Webhook (Listen for Telegram Events)
- If (Check User & Chat ID)
- Switch (Message Router)
- Set (Validation)
- Google Docs (Retrieve Long Term Memories, Save Long Term Memories)
- Langchain Agent (@n8n/n8n-nodes-langchain.agent)
- Langchain LM Chat OpenAI (@n8n/n8n-nodes-langchain.lmChatOpenAi)
- Telegram (Telegram Response, Error message)
- Merge
- Memory Buffer Window (@n8n/n8n-nodes-langchain.memoryBufferWindow)
Key Features
- Real-time Telegram message processing via webhook.
- Robust user and chat ID validation.
- Intelligent message routing for different media types.
- Long-term memory retrieval and integration from Google Docs.
- Advanced AI interaction using DeepSeek AI models (compatible with OpenAI API).
- Personalized AI responses based on conversation history and user data.
- Optional saving of chat interactions to memory for continuous learning.
- Error handling for seamless operation.
How To Use
- Set up Telegram Bot: Create a Telegram bot using BotFather and obtain your Bot Token.
- Configure Webhook: Use the provided webhook URL (e.g.,
https://your-n8n-instance.com/webhook/wbot) and your Bot Token to set the webhook via Telegram's Bot API:https://api.telegram.org/botYOUR_BOT_TOKEN/setWebhook?url=YOUR_WEBHOOK_URL. - Configure Credentials:
- Telegram: Add your Telegram Bot Token in the
Telegram accountcredentials. - OpenAI/DeepSeek: Add your DeepSeek API Key (or OpenAI API Key if using OpenAI models) in the
deepseekcredentials for theLM Chat OpenAInodes. - Google Docs: Authorize your Google Docs account for the
Google Docsnodes to read and write memories.
- Telegram: Add your Telegram Bot Token in the
- Configure Google Docs: Create or identify a Google Doc to store long-term memories. Replace
[Google Doc ID]in theRetrieve Long Term MemoriesandSave Long Term Memoriesnodes with your actual Google Doc ID. - Set Validation Defaults: In the
Validationnode, updateFirstName,LastName, andidwith default values or remove the node if validation is not strictly required. - Activate Workflow: Ensure the workflow is active in n8n to start receiving Telegram messages.
Apps Used
Workflow JSON
{
"id": "e5fc2768-8704-4df9-9b00-9dd285b45c87",
"name": "DeepSeek AI Agent: Build Long-Term Memory Telegram Bots with OpenAI API",
"nodes": 0,
"category": "AI & LLM",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: e5fc2768-8704...
About the Author
Crypto_Watcher
Web3 Developer
Automated trading bots and blockchain monitoring workflows.
Statistics
Related Integrations
- Google Sheets + Schedule Trigger(394 workflows)
- Telegram + Telegram Trigger(362 workflows)
- Google Sheets + Split Out(277 workflows)
- Gmail + Schedule Trigger(270 workflows)
- Google Sheets + Slack(268 workflows)
- Gmail + Google Sheets(245 workflows)
- Google Drive + Google Sheets(203 workflows)
- Form Trigger + Google Sheets(163 workflows)
- Schedule Trigger + Telegram(152 workflows)
- Google Drive + Google Drive Trigger(135 workflows)
Related Workflows
Discover more workflows you might like
AI Agent: Enhance Chatbots with Long-Term Memory & Tool Integration
Empower your AI chatbot with n8n! Integrate long-term memory via Google Docs and leverage OpenAI tools for advanced conversational AI. Automate memory saving, retrieval, and notifications.
Build a Telegram AI Chatbot with Multi-Format Input & OpenAI
Create a powerful Telegram AI chatbot that handles text & voice messages. Leverages OpenAI GPT-4o and Langchain for intelligent responses. Automate conversations effortlessly.
Translate Telegram Audio to Text & Speech with AI in 55 Languages
Automate Telegram audio translation! This n8n workflow transcribes voice messages, translates them using AI, and replies with text and speech in 55+ languages.
Auto-Transcribe YouTube Videos to Text with Supadata & OpenAI
Instantly get transcribed text from YouTube videos using Supadata API and OpenAI for structuring. Save hours on content review.
Automate CV Screening: AI Analysis & Auto HR Notifications
Streamline recruitment with AI CV analysis using Google Gemini. Automatically rate candidates, notify HR, and confirm submissions via email.
Build a Business WhatsApp AI RAG Chatbot with OpenAI & Qdrant
Automate customer service with a WhatsApp AI RAG chatbot. Integrates OpenAI, Qdrant, and Google Drive for intelligent responses. Save hours weekly!