8
n8n 中文网amn8n.com

AI 代理限流器

高级

这是一个AI Chatbot, Multimodal AI领域的自动化工作流,包含 19 个节点。主要使用 Code, Switch, Telegram, GoogleSheets, Agent 等节点。 Telegram AI 助手:基于 Google Sheets 的限流与自动重置功能

前置要求
  • Telegram Bot Token
  • Google Sheets API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "fM5PRDQlmoaAlnBm",
  "meta": {
    "instanceId": "f1566d25fb5b1d5c0e46741caa587b4a4a6d9e642f3cd708cc55d43b881ce814",
    "templateCredsSetupCompleted": true
  },
  "name": "AI Agent 限流器",
  "tags": [
    {
      "id": "2GEineegHgFbbJ26",
      "name": "AI",
      "createdAt": "2025-08-04T12:39:26.962Z",
      "updatedAt": "2025-08-04T12:39:26.962Z"
    },
    {
      "id": "ewcMZyQBnLVMPImC",
      "name": "AI Agent",
      "createdAt": "2025-08-04T12:39:26.852Z",
      "updatedAt": "2025-08-04T12:39:26.852Z"
    }
  ],
  "nodes": [
    {
      "id": "6d351c55-6aad-4031-8456-0ea676d390b9",
      "name": "代理",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -880,
        464
      ],
      "parameters": {
        "text": "={{ $('Telegram').item.json.message.text }}",
        "options": {
          "systemMessage": "=You are a knowledgeable and helpful AI assistant designed to provide accurate, thoughtful, and actionable responses. Your role is to:\n\nCORE PRINCIPLES:\n- Provide clear, accurate information based on your knowledge\n- Admit uncertainty when you don't know something\n- Ask clarifying questions when requests are ambiguous\n- Prioritize user safety and well-being in all responses\n- Maintain a professional yet friendly tone\n\nRESPONSE GUIDELINES:\n- Structure longer responses with clear headings or bullet points\n- Provide step-by-step instructions for complex tasks\n- Include relevant examples when helpful\n- Suggest follow-up actions or resources when appropriate\n- Keep responses concise but comprehensive\n\nLIMITATIONS AWARENESS:\n- Acknowledge when tasks require real-time information you cannot access\n- Explain if requests fall outside your capabilities\n- Recommend human experts or specialized tools when appropriate\n\nRemember: Users have limited messages per session, so make each response valuable and complete. Focus on giving thorough, actionable help that addresses their needs efficiently."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "eb0afcd5-fcdb-4718-99e9-47fb932a7ae4",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        -1456,
        432
      ],
      "parameters": {
        "jsCode": "// Get the data from the lookup result\nconst currentRow = $input.first().json;\n\n// Get current message count from column B (if it doesn't exist, start at 0)\nconst currentCount = $input.first().json['Message Counter'] || 0;\n\n// Add 1 to the count\nconst newCount = parseInt(currentCount) + 1;\n\n// Return the data we need for the next step\nreturn {\n  json: {\n    session_id: currentRow.A,\n    message_count: newCount,\n    row_number: currentRow.__rowNum\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "334982a1-5681-4718-ac94-51d1ffe80bd4",
      "name": "在表格中追加或更新行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1792,
        432
      ],
      "parameters": {
        "columns": {
          "value": {
            " ID": "={{ $json.message.chat.id }}"
          },
          "schema": [
            {
              "id": " ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": " ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message Counter",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message Counter",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            " ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY/edit?usp=drivesdk",
          "cachedResultName": "Message Counter"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "MrUNOt069TFPf4Ot",
          "name": "uussamambuisnes Google Sheets account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "94d0cedf-8dc7-4f6a-905f-b8312a060f2b",
      "name": "获取表格中的行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1616,
        432
      ],
      "parameters": {
        "options": {
          "dataLocationOnSheet": {
            "values": {
              "range": "A:Z",
              "rangeDefinition": "specifyRangeA1"
            }
          }
        },
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $('Telegram').item.json.message.chat.id }}",
              "lookupColumn": " ID"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY/edit?usp=drivesdk",
          "cachedResultName": "Message Counter"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "MrUNOt069TFPf4Ot",
          "name": "uussamambuisnes Google Sheets account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "35755fa3-22db-4457-a54e-6b35cc3d0b8a",
      "name": "在 sheet1 中追加或更新行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1280,
        432
      ],
      "parameters": {
        "columns": {
          "value": {
            " ID": "={{ $('Telegram').item.json.message.chat.id }}",
            "Message Counter": "={{ $json.message_count }}"
          },
          "schema": [
            {
              "id": " ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": " ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message Counter",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message Counter",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            " ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY/edit?usp=drivesdk",
          "cachedResultName": "Message Counter"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "MrUNOt069TFPf4Ot",
          "name": "uussamambuisnes Google Sheets account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "012468ea-8550-40c1-a66c-10de42cc97f0",
      "name": "Azure",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        -880,
        640
      ],
      "parameters": {
        "model": "gpt-4.1-2",
        "options": {}
      },
      "credentials": {
        "azureOpenAiApi": {
          "id": "DrvHsJAXuggAha2Y",
          "name": "gpt-4.1-2"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2374ffee-2bbc-4d99-9b01-cd8c44510e43",
      "name": "计划触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1504,
        896
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7c7712f0-3fce-4be9-a5ab-e3266e7c8d78",
      "name": "获取工作表中的行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1504,
        1040
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY/edit?usp=drivesdk",
          "cachedResultName": "Message Counter"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "MrUNOt069TFPf4Ot",
          "name": "uussamambuisnes Google Sheets account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "b33dba91-644e-4a8e-b92e-24858e290561",
      "name": "在工作表中更新行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1504,
        1200
      ],
      "parameters": {
        "columns": {
          "value": {
            " ID": "={{ $json[' ID'] }}",
            "Message Counter": "0"
          },
          "schema": [
            {
              "id": " ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": " ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message Counter",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Message Counter",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            " ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hBZwpnCr_PZeiALke7ifgBjaUiPWS8Ml6zbbafQbavY/edit?usp=drivesdk",
          "cachedResultName": "Message Counter"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "MrUNOt069TFPf4Ot",
          "name": "uussamambuisnes Google Sheets account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "0a292f78-fd84-4b0f-9880-c0d84049a93f",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2032,
        832
      ],
      "parameters": {
        "color": 3,
        "width": 720,
        "height": 528,
        "content": "## 🔄 自动重置系统(独立工作流分支)"
      },
      "typeVersion": 1
    },
    {
      "id": "0533d580-8ce6-43b4-86a1-5f399b254829",
      "name": "分支",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1104,
        416
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "e34ecf3a-c51e-4cb3-9014-bfba185797f9",
                    "operator": {
                      "type": "number",
                      "operation": "gt"
                    },
                    "leftValue": "={{ $json['Message Counter'] }}",
                    "rightValue": 3
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c0a45d11-2dc9-4022-838d-677e77096020",
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json['Message Counter'] }}",
                    "rightValue": 3
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "e6dc0f88-a9b6-417b-917e-904ebbbeff2c",
                    "operator": {
                      "type": "number",
                      "operation": "lt"
                    },
                    "leftValue": "={{ $json['Message Counter'] }}",
                    "rightValue": 3
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "04b0a71c-ac0f-4781-a836-513fbc8658d5",
      "name": "无操作",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -576,
        208
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "7287f221-93fa-4ffe-96d4-e173b73a0554",
      "name": "限制消息",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -576,
        352
      ],
      "webhookId": "0b3f3531-1deb-4f90-a874-ccc8b5129b10",
      "parameters": {
        "text": "=Daily limit exceeded 🚫. Try again later ⏳.  ",
        "chatId": "={{ $('Telegram').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "tPNuBIAJhDGfrSaN",
          "name": "AI Agent 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a5c77b19-ee2f-46d0-afb8-bd37269611e8",
      "name": "代理回答",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -576,
        512
      ],
      "webhookId": "0b3f3531-1deb-4f90-a874-ccc8b5129b10",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "tPNuBIAJhDGfrSaN",
          "name": "AI Agent 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9f24f7b1-2971-4142-a5c7-99e6fbda7e17",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1968,
        432
      ],
      "webhookId": "583daf91-97ea-431f-b9b3-04c12b65da9e",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "tPNuBIAJhDGfrSaN",
          "name": "AI Agent 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f6ca6972-3c8e-4f05-b215-955786367b52",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2736,
        -128
      ],
      "parameters": {
        "color": 5,
        "width": 656,
        "height": 912,
        "content": "## 🤖 AI Agent 限流器"
      },
      "typeVersion": 1
    },
    {
      "id": "a674ef45-ee99-4625-ab47-789a0b2dc32c",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2032,
        -128
      ],
      "parameters": {
        "color": 4,
        "width": 1680,
        "height": 912,
        "content": "## 📊 智能消息跟踪"
      },
      "typeVersion": 1
    },
    {
      "id": "fae65b4d-9afa-432f-95f9-719d578eff33",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -944,
        -128
      ],
      "parameters": {
        "width": 592,
        "height": 912,
        "content": "## 💬 用户友好响应"
      },
      "typeVersion": 1
    },
    {
      "id": "d90f5c67-c8a2-43df-bbd9-d727788c59b9",
      "name": "记忆存储",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -784,
        640
      ],
      "parameters": {
        "sessionKey": "={{ $('Telegram').item.json.message.chat.id }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d84fb1e2-3d76-4eb6-b175-a8c6dab6daeb",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Append or update row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agent": {
      "main": [
        [
          {
            "node": "Agent Answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Azure": {
      "ai_languageModel": [
        [
          {
            "node": "Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Memory": {
      "ai_memory": [
        [
          {
            "node": "Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "No Operation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Limit Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet1": {
      "main": [
        [
          {
            "node": "Update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append or update row in sheet": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append or update row in sheet1": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - AI 聊天机器人, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量19
分类2
节点类型11
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Oussama

Oussama

@oussama

AI Agents Builder 🤖

外部链接
在 n8n.io 查看

分享此工作流