DeepSeek AI Agent + Telegram + LONG TERM Memory n8n Workflow Template

n8n workflow template · 15 nodes · Telegram

DeepSeek AI Agent + Telegram + LONG TERM Memory is a free n8n workflow template that starts when its webhook receives an HTTP request and works with Telegram, Google Docs and OpenAI. It has 15 nodes, 5 of them AI nodes (AI Agent, Window Buffer Memory, Chat Trigger and OpenAI Chat Model). To run it, you add your own credentials for Google Docs OAuth2, OpenAI API and Telegram Bot API.

At a glance

Trigger
Webhook (Listen for Telegram Events)
Nodes
15
Apps
Telegram, Google Docs and OpenAI
AI nodes
5
Credentials
3 types
Category
Chatbots and messaging

Apps and integrations

  • Telegram
  • Google Docs
  • OpenAI

Node types used

  • If
  • Telegram
  • Webhook
  • Edit Fields (Set)
  • Switch
  • AI Agent
  • Merge
  • Window Buffer Memory
  • Chat Trigger
  • Google Docs Tool
  • Google Docs
  • OpenAI Chat Model

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Receive Telegram Message with Webhook

Retrieve Long Term Memories

Save To Current Chat Memory (Optional)

Save Long Term Memories

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

How to set up a Telegram Bot WebHook

WebHook Setup Process

Basic Concept A WebHook allows your Telegram bot to automatically receive updates instead of manually polling the Bot API.

Setup Method To set a WebHook, make a GET request using this URL format

  • my_bot_token: Your bot token from BotFather
  • url_to_send_updates_to: Your HTTPS endpoint that handles bot updates

Verification To verify the WebHook setup, use

A successful response looks like

This method provides a simple and efficient way to handle Telegram bot updates automatically through webhooks rather than manual polling.

DeepSeek API Call

The DeepSeek API uses an API format compatible with OpenAI. By modifying the configuration, you can use the OpenAI SDK or softwares compatible with the OpenAI API to access the DeepSeek API.

Configuration Parameters

Parameter | Value | |-----------|--------| | base_url | | | api_key

Important Notes

  • To be compatible with OpenAI, you can also use as the base_url. Note that the v1 here has NO relationship with the model's version.
  • The deepseek-chat model has been upgraded to DeepSeek-V3. The API remains unchanged. You can invoke DeepSeek-V3 by specifying model='deepseek-chat'.
  • deepseek-reasoner is the latest reasoning model, DeepSeek-R1, released by DeepSeek. You can invoke DeepSeek-R1 by specifying model='deepseek-reasoner'.

Nodes in this workflow

The 15 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. Check User & Chat ID (If)
  2. Error message (Telegram)
  3. Listen for Telegram Events (Webhook)
  4. Validation (Edit Fields (Set))
  5. Message Router (Switch)
  6. AI Agent (AI Agent)
  7. Merge (Merge)
  8. Window Buffer Memory (Window Buffer Memory)
  9. When chat message received (Chat Trigger)
  10. Telegram Response (Telegram)
  11. Save Long Term Memories (Google Docs Tool)
  12. Retrieve Long Term Memories (Google Docs)
  13. Response Error message (Telegram)
  14. DeepSeek-R1 Reasoning (OpenAI Chat Model)
  15. DeepSeek-V3 Chat (OpenAI Chat Model)

Credentials you need

  • Google Docs OAuth2 – used by Retrieve Long Term Memories and Save Long Term Memories
  • OpenAI API – used by DeepSeek-R1 Reasoning and DeepSeek-V3 Chat
  • Telegram Bot API – used by Error message, Response Error message and Telegram Response

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us