DeepSeek创意写作AI 评分 · 待评分AI 辅助编辑·未发现明显提示词注入风险n8n.io

DeepSeek AI 代理 + Telegram + 长期记忆 n8n 模板

Telegram 消息 → 用户校验 → 消息路由 → 检索 Google Docs 长期记忆 → DeepSeek AI 生成回复 → Telegram 回传 + 保存新记忆

有一点经验步骤流程提示词贴士
给谁
已在 n8n 有基础经验、需要为 Telegram 机器人增加 AI 对话与长期记忆的用户
你会得到
得到一个可自动接收 Telegram 消息、校验用户、用 DeepSeek 模型生成个性化回复、并在 Google Docs 存取长期记忆的 n8n 工作流
你需要
n8n · telegram

硬约束

前置条件:n8n 实例(可访问公网以接收 Telegram webhook)、Telegram Bot Token(从 BotFather 获取)、DeepSeek API Key(https://platform.deepseek.com/api_keys)、Google Docs OAuth2 凭证与一份用于存记忆的 Google Doc。费用:DeepSeek API 按调用计费,Google Docs 一般免费额度内,n8n 自托管或云实例费用视方案而定。已知限制:Window Buffer Memory 节点在 workflow.json 中未实际连接(ai_memory 连线为空);Google Doc ID 需手动替换占位符;仅 text 消息进入 AI 处理,audio/image 走错误分支。

他们做了什么

作者 joe 在 n8n 上发布了一个工作流模板,将 Telegram Bot 通过 webhook 接入 n8n,实现用户身份校验、消息类型路由、DeepSeek AI 模型(V3/R1)对话生成,以及基于 Google Docs 的长期记忆存取。工作流包含 23 个节点,核心链路为:Webhook 接收 → Set/If 校验 → Switch 路由 → Google Docs 检索记忆 → Merge 合并 → AI Agent(含完整 system prompt)→ Telegram 回复;同时 AI Agent 可调用 Google Docs Tool 保存新记忆。

效果如何

模板在 n8n.io 上获得 34,222 次查看(author_report,截至 2026-10-24)。来源未提供实际运行成功率、延迟数据或用户反馈。

值得知道

1. Window Buffer Memory 节点存在于工作流中但 ai_memory 端口未连接(workflow.json 中连线为空数组),因此当前模板实际未启用该短期记忆;长期记忆完全依赖 Google Docs。2. Google Doc ID 在模板中为占位符 '[Google Doc ID]',必须手动替换。3. 仅 text 消息进入 AI 处理,audio/image 被路由到错误分支;如需多媒体支持需自行扩展。4. DeepSeek API 兼容 OpenAI 格式,但 base_url 和 model 名称需按 Sticky Note12 说明配置。5. 用户校验采用硬编码的 first_name/last_name/id,适合单用户或少量固定用户场景;多用户动态授权需改造 Validation 节点。6. 本站未实测该工作流(reproduction=not_tested),搭建时建议先用测试 Bot 和独立 Google Doc 验证。

n8n 工作流模板

结构已检查 · 未实际运行

下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。

配置与测试清单

需要绑定的凭证

  • Error message 节点:绑定Telegram API 凭证。
  • Telegram Response 节点:绑定Telegram API 凭证。
  • Save Long Term Memories 节点:绑定googleDocsOAuth2Api 凭证。
  • Retrieve Long Term Memories 节点:绑定googleDocsOAuth2Api 凭证。
  • Response Error message 节点:绑定Telegram API 凭证。
  • DeepSeek-R1 Reasoning 节点:绑定OpenAI API 凭证。
  • DeepSeek-V3 Chat 节点:绑定OpenAI API 凭证。

需要替换的配置

  • 源模板来自 n8n 公开库 #2864(约 23 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
  • Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。

测试输入与预期结果

  • 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
  • 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。

模板处理说明

  • 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
  • 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。

模板获取日期: 2026-10-24

步骤

  1. 配置 Telegram Webhook 接收消息

    在 n8n 中配置 Webhook 节点(路径设为 wbot,方法 POST),使工作流能接收 Telegram 推送。然后向 Telegram Bot API 注册 webhook:将 {my_bot_token} 替换为你的 Bot Token,{url_to_send_updates_to} 替换为 n8n 提供的 webhook URL,访问以下地址完成注册: https://api.telegram.org/bot{my_bot_token}/setWebhook?url={url_to_send_updates_to} 验证是否成功: https://api.telegram.org/bot{my_bot_token}/getWebhookInfo 成功响应示例包含 url、has_custom_certificate、pending_update_count、max_connections 等字段。

    搭建指导 · 来源原文。整体模板说明与快速启动指南

    This n8n workflow template is designed to integrate a DeepSeek AI agent with Telegram, incorporating long-term memory capabilities for personalized and context-aware responses. Here's a detailed breakdown:
    
    ---
    
    ## Core Features
    **Telegram Integration**  
    - Uses a webhook to receive messages from Telegram users.
    - Validates user identity and message content before processing.
    
    **AI-Powered Responses**  
    - Employs DeepSeek's AI models for conversational interactions.
    - Includes memory capabilities to personalize responses based on past interactions.
    
    **Error Handling**  
    - Sends an error message if the input cannot be processed.
    
    ---
    
    ## Model Options 🧠
    - **DeepSeek-V3 Chat**: Handles general conversational tasks.
    - **DeepSeek-R1 Reasoning**: Provides advanced reasoning capabilities for complex queries.
    - **Memory Buffer Window**: Maintains session context for ongoing conversations.
    
    ---
    
    ## Quick Setup 🛠️
    ### Telegram Webhook Configuration
    1. Set up a webhook using the Telegram Bot API:
       ```
       https://api.telegram.org/bot{my_bot_token}/setWebhook?url={url_to_send_updates_to}
       ```
       Replace `{my_bot_token}` with your bot's token and `{url_to_send_updates_to}` with your n8n webhook URL.
    2. Verify the webhook setup using:
       ```
       https://api.telegram.org/bot{my_bot_token}/getWebhookInfo
       ```
    
    ### DeepSeek API Configuration
    1. Base URL: `https://api.deepseek.com`
    2. Obtain your API key from the DeepSeek platform.
    
    ---
    
    ## Implementation Details 🔧
    ### User Validation
    - The workflow validates the user's first name, last name, and ID using data from incoming Telegram messages.
    - Only authorized users proceed to the next steps.
    
    ### Message Routing
    - Routes messages based on their type (text, audio, or image) using a switch node.
    - Ensures appropriate handling for each message format.
    
    ### AI Agent Interaction
    - Processes text input using DeepSeek-V3 or DeepSeek-R1 models.
    - Customizable system prompts define the AI's behavior and rules, ensuring user-centric and context-aware responses.
    
    ### Memory Management
    - Retrieves long-term memories stored in Google Docs to enhance personalization.
    - Saves new memories based on user interactions, ensuring continuity across sessions.

    搭建指导 · 来源原文。Sticky Note1 节点:Telegram webhook 配置说明

    # 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:
    ```
    https://api.telegram.org/bot{my_bot_token}/setWebhook?url={url_to_send_updates_to}
    ```
    Where:
    - `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:
    ```
    https://api.telegram.org/bot{my_bot_token}/getWebhookInfo
    ```
    
    A successful response looks like:
    ```json
    {
     "ok": true,
     "result": {
       "url": "https://www.example.com/my-telegram-bot/",
       "has_custom_certificate": false,
       "pending_update_count": 0,
       "max_connections": 40
     }
    }
    ```
    
    
    This method provides a simple and efficient way to handle Telegram bot updates automatically through webhooks rather than manual polling.
  2. 设置用户校验规则

    在 n8n 工作流中,'Validation' 节点(Edit Fields/Set)预设授权用户的 first_name、last_name 和 id(示例值为占位符,需替换为真实用户数据)。'Check User & Chat ID' 节点(If)将 incoming Telegram 消息中的 from.first_name、from.last_name、from.id 与预设值逐一比对(全等匹配,区分大小写)。三项全部匹配才进入后续处理;任一不匹配则走向错误分支,向用户发送 'Unable to process your message.'。

  3. 配置消息路由

    'Message Router' 节点(Switch)按消息类型分流:检查 body.message.text 是否存在(text 分支)、body.message.voice 是否存在(audio 分支)、body.message.photo 是否存在(image 分支)。当前模板中,仅 text 分支连接到后续 AI 处理;audio 与 image 分支走向错误处理节点。若需支持多媒体,需自行扩展对应分支的处理逻辑。

  4. 连接 Google Docs 长期记忆

    'Retrieve Long Term Memories' 节点(Google Docs)通过 documentURL 指定记忆文档(workflow.json 中当前为 '[Google Doc ID]' 占位符,需替换为真实文档 ID)。该节点获取文档内容后,经 'Merge' 节点合并到 AI Agent 的输入流,使 AI 在生成回复时能参考历史记忆。同时需配置 'Save Long Term Memories' 节点(Google Docs Tool)用于后续写入新记忆,同样需替换 documentURL 为同一或另一文档 ID。

  5. 配置 AI Agent 与 DeepSeek 模型

    'AI Agent' 节点使用 LangChain Agent,其 User Message 字段填入表达式 ={{ $('Message Router').item.json.body.message.text }},提取用户文本输入。System Message 字段填入完整系统提示词(见下方 source 提示词),定义 AI 角色、记忆管理规则、上下文使用方式、隐私与回退策略。模型端连接 'DeepSeek-V3 Chat' 或 'DeepSeek-R1 Reasoning' 节点(OpenAI Chat Model 兼容节点),参数如下:base_url = https://api.deepseek.com(或 https://api.deepseek.com/v1),model = deepseek-chat(对应 V3)或 deepseek-reasoner(对应 R1),API Key 填入 DeepSeek 平台获取的密钥。凭证类型使用 openAiApi 节点但指向 DeepSeek 端点。

    运行提示词 · 来源原文。AI Agent 节点的 User Message / text 参数字段

    ={{ $('Message Router').item.json.body.message.text }}

    运行提示词 · 来源原文。AI Agent 节点的 System Message / options.systemMessage 字段

    =## ROLE  
    You are a friendly, attentive, and helpful AI assistant. Your primary goal is to assist the user while maintaining a personalized and engaging interaction. The current user's first name is **{{ $json.body.message.from.first_name }}**.
    
    ---
    
    ## RULES  
    
    1. **Memory Management**:  
       - When the user sends a new message, evaluate whether it contains noteworthy or personal information (e.g., preferences, habits, goals, or important events).  
       - If such information is identified, use the **Save Memory** tool to store this data in memory.  
       - Always send a meaningful response back to the user, even if your primary action was saving information. This response should not reveal that information was stored but should acknowledge or engage with the user’s input naturally.
    
    2. **Context Awareness**:  
       - Use stored memories to provide contextually relevant and personalized responses.  
       - Always consider the **date and time** when a memory was collected to ensure your responses are up-to-date and accurate.
    
    3. **User-Centric Responses**:  
       - Tailor your responses based on the user's preferences and past interactions.  
       - Be proactive in recalling relevant details from memory when appropriate but avoid overwhelming the user with unnecessary information.
    
    4. **Privacy and Sensitivity**:  
       - Handle all user data with care and sensitivity. Avoid making assumptions or sharing stored information unless it directly enhances the conversation or task at hand.
    
    5. **Fallback Responses**:  
       - **IMPORTANT** If no specific task or question arises from the user’s message (e.g., when only saving information), respond in a way that keeps the conversation flowing naturally. For example:
         - Acknowledge their input: “Thanks for sharing that!” 
         - Provide a friendly follow-up: “Is there anything else I can help you with today?”
       - DO NOT tell Jokes as a fall back response.
    
    ---
    
    ## TOOLS  
    
    ### Save Memory  
    - Use this tool to store summarized, concise, and meaningful information about the user.  
    - Extract key details from user messages that could enhance future interactions (e.g., likes/dislikes, important dates, hobbies).  
    - Ensure that the summary is clear and devoid of unnecessary details.
    
    ---
    
    ## MEMORIES  
    
    ### Recent Noteworthy Memories  
    Here are the most recent memories collected from the user, including their date and time of collection:  
    
    **{{ $('Retrieve Long Term Memories').item.json.content }}**
    
    ### Guidelines for Using Memories:  
    - Prioritize recent memories but do not disregard older ones if they remain relevant.  
    - Cross-reference memories to maintain consistency in your responses. For example, if a user shares conflicting preferences over time, clarify or adapt accordingly.
    
    ---
    
    ## ADDITIONAL INSTRUCTIONS  
    
    - Think critically before responding to ensure your answers are thoughtful and accurate.  
    - Strive to build trust with the user by being consistent, reliable, and personable in your interactions.  
    - Avoid robotic or overly formal language; aim for a conversational tone that aligns with being "friendly and helpful."

    搭建指导 · 来源原文。Sticky Note12 节点:DeepSeek API 配置参考

    # 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.
    
    https://api-docs.deepseek.com/
    
    ## Configuration Parameters
    
    | Parameter | Value |
    |-----------|--------|
    | base_url | https://api.deepseek.com |
    | api_key | https://platform.deepseek.com/api_keys |
    
    
    
    ## Important Notes
    
    - To be compatible with OpenAI, you can also use `https://api.deepseek.com/v1` 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'`.
  6. 设置 Telegram 回复与错误处理

    'Telegram Response' 节点将 AI Agent 的输出($json.output)发送回用户原始聊天,使用 HTML parse_mode。若 AI Agent 或上游节点出错,'Response Error message' 节点发送 'Unable to process your message.'。用户校验失败时,'Error message' 节点也会发送相同错误文本。三个 Telegram 节点均需配置 telegramApi 凭证。

  7. 配置长期记忆保存

    'Save Long Term Memories' 节点(Google Docs Tool)被 AI Agent 作为工具调用,用于将新记忆写入 Google Docs。节点参数中,documentURL 需替换为真实 Google Doc ID;插入文本表达式为 '= Memory: {{ $fromAI('memory') }} - Date: {{ $now }} ',其中 $fromAI('memory') 由 AI Agent 在决定保存记忆时传入。工具描述(toolDescription)为 'Save memories',帮助 AI 理解何时调用。

可复制提示词

搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限

这一段是提示词,页面不会在这里插入广告。

请根据以下材料搭建并配置 n8n 工作流:
1. 导入模板 workflow JSON(来源:https://n8n.io/workflows/2864/)。
2. 按步骤配置 Telegram Bot Webhook、用户校验字段、DeepSeek API 凭证(base_url=https://api.deepseek.com,model=deepseek-chat 或 deepseek-reasoner)。
3. 替换 Google Docs 节点中的 [Google Doc ID] 为真实文档 ID,并授权 Google Docs OAuth2。
4. 测试 webhook 连通性:向 Bot 发送文本消息,观察是否能收到 AI 回复;检查 Google Doc 是否有新记忆写入。
5. 如需调整 AI 人格或记忆策略,修改 AI Agent 的 System Message(保持原有变量表达式不变)。

先替换所有凭证与占位符,再用测试消息验证端到端流程;AI Agent 的 system prompt 含 {{ $json.body.message.from.first_name }} 和 {{ $('Retrieve Long Term Memories').item.json.content }} 等 n8n 表达式,勿直接修改其语法。

来源

🐋🤖 DeepSeek AI agent + Telegram + LONG TERM memory 🧠 · joe · n8n.io · 2025-02-08

留言与反馈

试过这个方法吗?分享效果、遇到的问题或改进建议。留言审核后公开,请勿填写敏感信息。

正在加载…

    相关用例