使用Telegram、AIMLAPI和Google表格创建多模型AI聊天机器人
高级
这是一个Personal Productivity, AI Chatbot领域的自动化工作流,包含 25 个节点。主要使用 If, Set, Code, Switch, Telegram 等节点。 使用Telegram、AIMLAPI和Google表格创建多模型AI聊天机器人
前置要求
- •Telegram Bot Token
- •可能需要目标 API 的认证凭证
- •Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "58e06bfa452afe2836b2ce0aa089999394af0b93c2a455035675d99d83112fa1",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "8db98853-bc69-4139-a08a-e0df3a6a0187",
"name": "📩 接收 Telegram 消息",
"type": "n8n-nodes-base.telegramTrigger",
"position": [
-320,
1616
],
"webhookId": "3ceea664-fd53-4141-8bc6-4fdaca0a661d",
"parameters": {
"updates": [
"message"
],
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "bb70IQruLtlUfyRb",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "1fd92fc6-1992-4ba9-ac35-404d99b6aa46",
"name": "📊 获取使用日志",
"type": "n8n-nodes-base.googleSheets",
"position": [
144,
1792
],
"parameters": {
"options": {},
"filtersUI": {
"values": [
{
"lookupValue": "={{ $json.message.from.id }}",
"lookupColumn": "user_id"
},
{
"lookupValue": "={{ new Date().toISOString().slice(0,10) }}",
"lookupColumn": "date"
}
]
},
"sheetName": {
"__rl": true,
"mode": "list",
"value": 2060422727,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/19rsFwln4KMpGjOzxOdz7OC_-kRH8_qD4Agx5lXlDD9k/edit#gid=2060422727",
"cachedResultName": "Sheet1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "19rsFwln4KMpGjOzxOdz7OC_-kRH8_qD4Agx5lXlDD9k",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/19rsFwln4KMpGjOzxOdz7OC_-kRH8_qD4Agx5lXlDD9k/edit?usp=drivesdk",
"cachedResultName": "AI bot usage statistic"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "kID0866UxrCrODzt",
"name": "Google Sheets account"
}
},
"typeVersion": 4.6,
"alwaysOutputData": true
},
{
"id": "3ff699b8-5db7-40fb-be90-69f0c1052aad",
"name": "📈 统计今日请求数",
"type": "n8n-nodes-base.aggregate",
"position": [
368,
1792
],
"parameters": {
"options": {},
"aggregate": "aggregateAllItemData"
},
"typeVersion": 1
},
{
"id": "c0db9e37-dd77-469d-a055-b1e7f097293d",
"name": "🔢 设置每日限制",
"type": "n8n-nodes-base.set",
"position": [
592,
1792
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "1514c5a1-1bd4-4ba2-8bb9-30c679ae4f8e",
"name": "daily_limit",
"type": "number",
"value": 5
}
]
}
},
"typeVersion": 3.4
},
{
"id": "f5421fea-d1a1-4701-9c71-7cf6b5f3df18",
"name": "🚦 检查是否超出限制?",
"type": "n8n-nodes-base.if",
"position": [
848,
1792
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "08e8aac4-9f6a-4fc0-b1ad-7d8493ff74bf",
"operator": {
"type": "number",
"operation": "lt"
},
"leftValue": "={{$('📈 Count Today’s Requests').item.json.data.length }}",
"rightValue": "={{ $json.daily_limit }}"
}
]
}
},
"executeOnce": false,
"typeVersion": 2.2
},
{
"id": "7a6ba155-4fb2-49bd-ba87-762dc0d564b8",
"name": "🚫 通知:超出限制",
"type": "n8n-nodes-base.telegram",
"position": [
1120,
1808
],
"webhookId": "bb58ce7a-45e5-42d1-a780-7cc47f7402b1",
"parameters": {
"text": "=Sorry! Your *daily limit of {{ $('🔢 Set Daily Limit').item.json.daily_limit }} generations* is exceeded!",
"chatId": "={{ $('📩 Receive Telegram Message').item.json.message.chat.id }}",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "bb70IQruLtlUfyRb",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "89bf72a1-41f0-45bf-832d-9603c525c5ee",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-352,
1424
],
"parameters": {
"color": 4,
"width": 432,
"height": 464,
"content": "## 传入消息"
},
"typeVersion": 1
},
{
"id": "62dbe03c-45eb-4353-9c96-83eeaf0bd750",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
96,
1696
],
"parameters": {
"width": 1200,
"height": 288,
"content": "## 使用限制检查"
},
"typeVersion": 1
},
{
"id": "b74b4b6c-caa2-49d0-aa93-c564f5e99716",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
752,
1360
],
"parameters": {
"color": 4,
"width": 1664,
"height": 320,
"content": "## 交付与记录"
},
"typeVersion": 1
},
{
"id": "1df08c50-f38d-430a-8d0b-db6df1461265",
"name": "便签8",
"type": "n8n-nodes-base.stickyNote",
"position": [
-48,
-400
],
"parameters": {
"color": 5,
"width": 560,
"height": 672,
"content": "# 🧠 AI 聊天与模型选择器机器人 — Telegram + AIMLAPI(通过 n8n)"
},
"typeVersion": 1
},
{
"id": "1510f325-a221-4880-b198-8696b2e47329",
"name": "便签9",
"type": "n8n-nodes-base.stickyNote",
"position": [
-48,
288
],
"parameters": {
"color": 5,
"width": 560,
"height": 784,
"content": "## ⚙️ 自定义选项:"
},
"typeVersion": 1
},
{
"id": "84cd9c4f-7e93-4859-8025-2bc23815420e",
"name": "便签10",
"type": "n8n-nodes-base.stickyNote",
"position": [
528,
-400
],
"parameters": {
"color": 5,
"width": 560,
"height": 976,
"content": "# 🛠 部署设置指南"
},
"typeVersion": 1
},
{
"id": "72dc8e96-7dac-435c-815b-17e898432a63",
"name": "便利贴11",
"type": "n8n-nodes-base.stickyNote",
"position": [
528,
592
],
"parameters": {
"color": 5,
"width": 560,
"height": 480,
"content": "## 📁 记录到 Google Sheets 的数据:"
},
"typeVersion": 1
},
{
"id": "aa89ce2b-a680-4c1a-b4a5-455a81030814",
"name": "Send a chat action",
"type": "n8n-nodes-base.telegram",
"position": [
1104,
1472
],
"webhookId": "88ac9fb3-ee4b-49ce-bd69-68aca1fae929",
"parameters": {
"chatId": "={{ $('📩 Receive Telegram Message').item.json.message.chat.id }}",
"operation": "sendChatAction"
},
"credentials": {
"telegramApi": {
"id": "bb70IQruLtlUfyRb",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "cae25ff0-5690-43f0-8245-0ed7d97b66dc",
"name": "Get Models List",
"type": "n8n-nodes-base.httpRequest",
"position": [
144,
1504
],
"parameters": {
"url": "https://api.aimlapi.com/v1/models",
"options": {}
},
"typeVersion": 4.2
},
{
"id": "bf1b163d-58e4-4cc0-b8cd-4317fe0c5e42",
"name": "发送短信",
"type": "n8n-nodes-base.telegram",
"position": [
592,
1504
],
"webhookId": "3f0e254e-74a7-4c06-b3ee-7aa0eca216d7",
"parameters": {
"text": "={{ $json.content }}",
"chatId": "={{ $('📩 Receive Telegram Message').item.json.message.chat.id }}",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "bb70IQruLtlUfyRb",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "7d506e29-9e47-4e24-8354-a1a311e6bdff",
"name": "代码",
"type": "n8n-nodes-base.code",
"position": [
368,
1504
],
"parameters": {
"language": "python",
"pythonCode": "data = _input.first().json['data']\n\ngrouped_models = {}\n\nfor item in data:\n if item.get('type') != 'chat-completion':\n continue\n\n developer = item.get('info', {}).get('developer', 'Unknown')\n model_entry = {\n 'id': item.get('id'),\n 'name': item.get('info', {}).get('name', item.get('id'))\n }\n\n if developer not in grouped_models:\n grouped_models[developer] = []\n\n grouped_models[developer].append(model_entry)\n\n# Формируем список объектов для вывода\noutput_items = []\n\nfor developer, models in grouped_models.items():\n lines = [f\"🧑💻 *{developer}*\"]\n for model in models:\n lines.append(f\"• `{model['id']}` — {model['name']}\")\n \n content = \"\\n\".join(lines)\n output_items.append({'json': {'content': content}})\n\nreturn output_items\n"
},
"typeVersion": 2
},
{
"id": "5e370157-362d-407d-95bf-b9345d6e99e6",
"name": "发送短信",
"type": "n8n-nodes-base.telegram",
"position": [
2032,
1488
],
"webhookId": "5aee0c67-4828-4a12-93a1-5b2f24397464",
"parameters": {
"text": "={{ $json.content }}",
"chatId": "={{ $('📩 Receive Telegram Message').item.json.message.chat.id }}",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "bb70IQruLtlUfyRb",
"name": "Telegram account"
}
},
"typeVersion": 1.2
},
{
"id": "b0e40f9a-e30d-4fd8-a23d-61bc3bca8d5a",
"name": "📝 记录成功生成1",
"type": "n8n-nodes-base.googleSheets",
"position": [
2224,
1488
],
"parameters": {
"columns": {
"value": {
"date": "={{ new Date().toISOString().slice(0,10) }}",
"query": "={{ $('📩 Receive Telegram Message').item.json.message.text }}",
"result": "={{ $json.result.text }}",
"user_id": "={{ $('📩 Receive Telegram Message').item.json.message.from.id }}"
},
"schema": [
{
"id": "user_id",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "user_id",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "date",
"type": "string",
"display": true,
"required": false,
"displayName": "date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "query",
"type": "string",
"display": true,
"required": false,
"displayName": "query",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "result",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "result",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"user_id"
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": 2060422727,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RHgZNdT0whop0JY3vrj83yLtmVluG73NIfLBBa8ckPg/edit#gid=2060422727",
"cachedResultName": "Sheet1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "19rsFwln4KMpGjOzxOdz7OC_-kRH8_qD4Agx5lXlDD9k",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/19rsFwln4KMpGjOzxOdz7OC_-kRH8_qD4Agx5lXlDD9k/edit?usp=drivesdk",
"cachedResultName": "AI bot usage statistic"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "kID0866UxrCrODzt",
"name": "Google Sheets account"
}
},
"typeVersion": 4.6
},
{
"id": "e7b00f33-4464-4567-97d6-cef34ad9c33f",
"name": "便签6",
"type": "n8n-nodes-base.stickyNote",
"position": [
96,
1360
],
"parameters": {
"width": 640,
"height": 320,
"content": "## 使用限制检查"
},
"typeVersion": 1
},
{
"id": "16f0d8de-fcee-44e7-b5ef-e28980d3395c",
"name": "Get Models Or Process Message?",
"type": "n8n-nodes-base.switch",
"position": [
-128,
1616
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "Get Models",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "efff9014-b37a-443e-b888-fd9a8eb97f3f",
"operator": {
"type": "string",
"operation": "contains"
},
"leftValue": "={{ $json.message.text }}",
"rightValue": "/models"
}
]
},
"renameOutput": true
},
{
"outputKey": "Process Message",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "8b39b996-fd2e-4070-9800-1a7b0bdc5f76",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $json.message.text }}",
"rightValue": ""
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "7163b2e1-96ff-4965-a3ab-91e2d68a6a33",
"name": "🧠 生成消息 (AI/ML API | GPT-4o)",
"type": "n8n-nodes-aimlapi.aimlApi",
"position": [
1712,
1536
],
"parameters": {
"model": "openai/gpt-4o",
"prompt": "={{ $('📩 Receive Telegram Message').item.json.message.text }}",
"options": {},
"requestOptions": {}
},
"credentials": {
"aimlApi": {
"id": "6Z9fP7Dy0ZkIBXXw",
"name": "AI/ML account"
}
},
"typeVersion": 1
},
{
"id": "b942da4d-2dc2-4773-b3a9-3b700d8838c6",
"name": "🧠 生成消息 (AI/ML API | 自定义模型)",
"type": "n8n-nodes-aimlapi.aimlApi",
"position": [
1824,
1376
],
"parameters": {
"model": "={{ $json.model_id }}",
"prompt": "={{ $json.message }}",
"options": {},
"requestOptions": {}
},
"credentials": {
"aimlApi": {
"id": "6Z9fP7Dy0ZkIBXXw",
"name": "AI/ML account"
}
},
"typeVersion": 1
},
{
"id": "2bbb1df7-7035-475c-ae62-e8996f22bea1",
"name": "Group Models By Providers",
"type": "n8n-nodes-base.code",
"position": [
1616,
1376
],
"parameters": {
"jsCode": "const text = $('📩 Receive Telegram Message').first().json.message.text;\n\nif (!text.startsWith('#')) {\n throw new Error('Message must start with a #model_tag');\n}\n\nconst parts = text.split(' ', 2);\n\nif (parts.length < 2) {\n throw new Error('Message must contain both #model_tag and prompt text.');\n}\n\nconst model_id = parts[0].substring(1); // Убираем #\nconst message = parts[1];\n\nreturn [\n {\n json: {\n model_id,\n message\n }\n }\n];\n"
},
"typeVersion": 2
},
{
"id": "214a99db-facf-4515-9a62-111d8eedbe84",
"name": "Set Custom Model?",
"type": "n8n-nodes-base.if",
"position": [
1392,
1472
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "8f4473af-8528-4286-a12f-d51d70615e3b",
"operator": {
"type": "string",
"operation": "startsWith"
},
"leftValue": "={{ $('📩 Receive Telegram Message').item.json.message.text }}",
"rightValue": "#"
}
]
}
},
"typeVersion": 2.2
}
],
"pinData": {},
"connections": {
"Code": {
"main": [
[
{
"node": "Send a text message",
"type": "main",
"index": 0
}
]
]
},
"Get Models List": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Set Custom Model?": {
"main": [
[
{
"node": "Group Models By Providers",
"type": "main",
"index": 0
}
],
[
{
"node": "🧠 Generate Msg (AI/ML API | GPT-4o)",
"type": "main",
"index": 0
}
]
]
},
"Send a chat action": {
"main": [
[
{
"node": "Set Custom Model?",
"type": "main",
"index": 0
}
]
]
},
"Send a text message1": {
"main": [
[
{
"node": "📝 Log Successful Generation1",
"type": "main",
"index": 0
}
]
]
},
"🔢 Set Daily Limit": {
"main": [
[
{
"node": "🚦 Check Limit Exceeded?",
"type": "main",
"index": 0
}
]
]
},
"📊 Fetch Usage Logs": {
"main": [
[
{
"node": "📈 Count Today’s Requests",
"type": "main",
"index": 0
}
]
]
},
"Group Models By Providers": {
"main": [
[
{
"node": "🧠 Generate Msg (AI/ML API | Custom Model)",
"type": "main",
"index": 0
}
]
]
},
"🚦 Check Limit Exceeded?": {
"main": [
[
{
"node": "Send a chat action",
"type": "main",
"index": 0
}
],
[
{
"node": "🚫 Notify: Limit Exceeded",
"type": "main",
"index": 0
}
]
]
},
"📈 Count Today’s Requests": {
"main": [
[
{
"node": "🔢 Set Daily Limit",
"type": "main",
"index": 0
}
]
]
},
"📩 Receive Telegram Message": {
"main": [
[
{
"node": "Get Models Or Process Message?",
"type": "main",
"index": 0
}
]
]
},
"Get Models Or Process Message?": {
"main": [
[
{
"node": "Get Models List",
"type": "main",
"index": 0
}
],
[
{
"node": "📊 Fetch Usage Logs",
"type": "main",
"index": 0
}
]
]
},
"🧠 Generate Msg (AI/ML API | GPT-4o)": {
"main": [
[
{
"node": "Send a text message1",
"type": "main",
"index": 0
}
]
]
},
"🧠 Generate Msg (AI/ML API | Custom Model)": {
"main": [
[
{
"node": "Send a text message1",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 个人效率, AI 聊天机器人
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
使用Gemini、语音和图像生成构建多模态Telegram AI助手
使用Gemini、语音和图像生成构建多模态Telegram AI助手
If
Set
Code
+19
95 节点Iniyavan JC
个人效率
在 Telegram 中使用 GPT-4o 增强和 Flux Pro 生成 AI 图像
在 Telegram 中使用 GPT-4o 增强和 Flux Pro 生成 AI 图像
If
Set
Telegram
+6
22 节点AI/ML API | D1m7asis
内容创作
通过 Telegram(语音、文本)使用 AI 跟踪和查询费用到 Google Sheets
通过 Telegram 使用 GPT-4.1 Mini 和 Google Sheets 跟踪和查询费用
If
Code
Wait
+11
32 节点Sridevi Edupuganti
个人效率
演示邮件分享
通过AI、Telegram机器人和网站爬取创建个性化邮件外联
If
Set
Xml
+20
58 节点Michael A Putra
客户培育
构建基于GPT-4o的Telegram心理健康支持机器人
构建基于GPT-4o的Telegram心理健康支持机器人
Set
Switch
Telegram
+3
15 节点AI/ML API | D1m7asis
客服机器人
多模态费用追踪:Telegram、Gemini AI 与 Google Sheets
使用 Telegram、Gemini AI 和 Google Sheets 的多模态费用追踪系统
If
Set
Switch
+10
25 节点OwenLee
个人效率