Telegram命令中心
高级
这是一个Support Chatbot, AI Chatbot领域的自动化工作流,包含 23 个节点。主要使用 If, Set, Code, Switch, Telegram 等节点。 使用Telegram机器人命令中心自动化工作流执行
前置要求
- •Telegram Bot Token
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "HSaX5xivT2KAYNcX",
"meta": {
"instanceId": "e9707613f506bdbcb79075f3617d27a010060d5fd1f76550283efabc82686f47",
"templateCredsSetupCompleted": true
},
"name": "Telegram命令中心",
"tags": [],
"nodes": [
{
"id": "1f10be35-1365-41cf-a310-d3b3a4a6f2d0",
"name": "Telegram触发器",
"type": "n8n-nodes-base.telegramTrigger",
"position": [
-224,
-768
],
"webhookId": "ee3d0945-bb90-4edb-aeec-a12981bf91c2",
"parameters": {
"updates": [
"message"
],
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "rftJijuNnjbeZjEv",
"name": "Telegram account - AmirStockBot"
}
},
"typeVersion": 1.2
},
{
"id": "5c258bb2-3ba3-44cf-bad0-7ed9c83754e0",
"name": "format_output_as_json",
"type": "n8n-nodes-base.code",
"onError": "continueRegularOutput",
"disabled": true,
"position": [
1456,
-384
],
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n// The input is an array of items. We'll work with the first item.\n\n\n// Access the string value from the 'output' field in the input JSON.\nconst rawStringWithMarkdown = item.json.output;\nconsole.log(item.json.output)\n// The JSON we want is nested inside a markdown code block (```json ... ```).\n// We need to extract just the JSON part.\n\n// Find the first occurrence of '{' to locate the start of the JSON object.\nconst jsonStartIndex = rawStringWithMarkdown.indexOf('{');\n\n// Find the last occurrence of '}' to locate the end of the JSON object.\nconst jsonEndIndex = rawStringWithMarkdown.lastIndexOf('}');\n\n// Slice the string from the start to the end to get only the clean JSON string.\n// We add +1 to jsonEndIndex because substring's second argument is exclusive.\nconst cleanJsonString = rawStringWithMarkdown.substring(jsonStartIndex, jsonEndIndex + 1);\n\n// Parse the cleaned string into a proper, usable JSON object.\nconst parsedJson = JSON.parse(cleanJsonString);\n\n// Return the parsed JSON object. The keys (symbol, sentiment_score, etc.)\n// will become individual fields in the n8n output for the next node to use.\nreturn parsedJson;}\n\n"
},
"executeOnce": false,
"retryOnFail": false,
"typeVersion": 2,
"alwaysOutputData": false
},
{
"id": "c2d15090-96f3-46f3-a39a-3d6b880feeaa",
"name": "通用输出",
"type": "n8n-nodes-base.telegram",
"position": [
1680,
-816
],
"webhookId": "9d8bc712-a61a-4508-a7c3-3c6ba6d723ab",
"parameters": {
"text": "={{ $json.output ?? \"\" }}\n{{ $json.text ?? \"\" }}\n{{ $json.html ?? \"\" }}\n---\nCommand:{{ $node[\"Seperate command and Parameter\"].json[\"command\"] }}\nParameter: {{ $node[\"Seperate command and Parameter\"].json[\"rest\"] }}\n",
"chatId": "={{ $node[\"Telegram Trigger\"].json[\"message\"][\"from\"][\"id\"] }}\n",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "rftJijuNnjbeZjEv",
"name": "Telegram account - AmirStockBot"
}
},
"typeVersion": 1.2
},
{
"id": "10b63b94-03f5-4728-9d9d-36b333eaa1fa",
"name": "处理已完成",
"type": "n8n-nodes-base.telegram",
"position": [
1680,
-1040
],
"webhookId": "e34df91c-d4bd-4773-b2a2-6643fc55979f",
"parameters": {
"text": "=Processing has finished.\n\nCommand:{{ $node[\"Seperate command and Parameter\"].json[\"command\"] }}\nParameter: {{ $node[\"Seperate command and Parameter\"].json[\"rest\"] }}\n",
"chatId": "={{ $node[\"Telegram Trigger\"].json[\"message\"][\"from\"][\"id\"] }}\n",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "rftJijuNnjbeZjEv",
"name": "Telegram account - AmirStockBot"
}
},
"typeVersion": 1.2
},
{
"id": "2ddf08dd-759d-4dad-81fd-4e7fad69a628",
"name": "Instagram帖子",
"type": "n8n-nodes-base.executeWorkflow",
"disabled": true,
"position": [
1248,
-816
],
"parameters": {
"options": {},
"workflowId": {
"__rl": true,
"mode": "id",
"value": ""
}
},
"typeVersion": 1.2
},
{
"id": "1b33a651-c6a9-4f4a-aa69-0a123866c0e7",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-272,
-1024
],
"parameters": {
"width": 448,
"height": 736,
"content": "1. Telegram消息触发器"
},
"typeVersion": 1
},
{
"id": "079c8a6b-0f36-4439-baf2-6e2e5fde033a",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
208,
-1024
],
"parameters": {
"width": 656,
"height": 736,
"content": "1. 分离命令和参数"
},
"typeVersion": 1
},
{
"id": "57fdb67c-d3ce-4620-b9a7-1de296f15534",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
896,
-1296
],
"parameters": {
"width": 1120,
"height": 1088,
"content": "为每个命令定义行为"
},
"typeVersion": 1
},
{
"id": "52b5bcbc-75a8-4aba-9686-1b1d7cfb02f2",
"name": "命令未找到",
"type": "n8n-nodes-base.telegram",
"position": [
640,
-464
],
"webhookId": "7eef257a-b05d-4b1c-a653-ab7705005f4a",
"parameters": {
"text": "=Error: Command is not valid!\n\n{{ $('Valid Commands').first().json.validCommands }}\n\n----\nCommand:{{ $node[\"Seperate command and Parameter\"].json[\"command\"] }}\nParameter: {{ $node[\"Seperate command and Parameter\"].json[\"rest\"] }}\n",
"chatId": "={{ $node[\"Telegram Trigger\"].json[\"message\"][\"from\"][\"id\"] }}\n",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "rftJijuNnjbeZjEv",
"name": "Telegram account - AmirStockBot"
}
},
"typeVersion": 1.2
},
{
"id": "663ebfab-5033-4483-a6e4-ab6d38be4413",
"name": "访问被拒绝",
"type": "n8n-nodes-base.telegram",
"position": [
-16,
-496
],
"webhookId": "2fd699ad-d69c-495f-b1a8-ca6783835a3d",
"parameters": {
"text": "=You don't have permission to use this bot!\nContact the administrator to obtain permission access.\n\nAccount ID:{{ $json.message.from.id }}",
"chatId": "={{ $node[\"Telegram Trigger\"].json[\"message\"][\"from\"][\"id\"] }}\n",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "rftJijuNnjbeZjEv",
"name": "Telegram account - AmirStockBot"
}
},
"typeVersion": 1.2
},
{
"id": "86c74341-8166-48bd-8e86-d4a694fe7ed4",
"name": "访问控制",
"type": "n8n-nodes-base.if",
"position": [
-16,
-768
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "6139880f-ae4a-43a0-836d-a1638795662d",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.message.from.id.toString() }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "317f4da6-707f-48c3-910a-4e50693b636a",
"name": "分离命令和参数",
"type": "n8n-nodes-base.code",
"position": [
448,
-784
],
"parameters": {
"jsCode": "const input = $('Telegram Trigger').first().json.message.text\nlet command, rest;\n\nif (input.startsWith('/')) {\n const splitIndex = input.indexOf(' ');\n if (splitIndex === -1) {\n // No space found, entire input is the command\n command = input;\n rest = \"\";\n } else {\n command = input.substring(0, splitIndex);\n rest = input.substring(splitIndex + 1);\n }\n} else {\n command = \"\";\n rest = input;\n}\n\nreturn [{\n json: {\n command: command,\n rest: rest\n }\n}];\n"
},
"typeVersion": 2
},
{
"id": "a9a338a4-2814-422c-b529-1d74edb1ecef",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-64,
-864
],
"parameters": {
"color": 3,
"width": 224,
"height": 80,
"content": "1.在此处添加账户ID以启用用户访问权限"
},
"typeVersion": 1
},
{
"id": "1f9f977c-3c06-404f-8c72-347afbd5255a",
"name": "有效命令",
"type": "n8n-nodes-base.set",
"position": [
240,
-784
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "4a5ded62-ca69-44fa-bce4-00ed3bf41ade",
"name": "validCommands",
"type": "string",
"value": "Valid Commands:\n /list (list all available commands)\n /instagram (generate instagram post - parameter: quote (optional))\n /social (check social media for the stock ticker - parameter: stock ticker)\n /sentiment: (do sentiment analysis for the stock ticker - parameter: stock ticker)\n"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "9aa0c015-27a3-4911-8c2e-3d863c031171",
"name": "切换到命令",
"type": "n8n-nodes-base.switch",
"position": [
640,
-832
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "sentiment",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "eb82524d-1fcd-4a19-a816-055de5c92e2e",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.command }}",
"rightValue": "/sentiment"
}
]
},
"renameOutput": true
},
{
"outputKey": "instagram",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "30940d5e-bdf9-471e-9684-b66244db9112",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.command }}",
"rightValue": "/instagram"
}
]
},
"renameOutput": true
},
{
"outputKey": "list",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "7f424524-1eee-4d02-9c9b-6c5be91defbe",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.command }}",
"rightValue": "/list"
}
]
},
"renameOutput": true
},
{
"outputKey": "social",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "7c466b2b-7759-493b-9a2f-8965e3d7224c",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.command }}",
"rightValue": "/social"
}
]
},
"renameOutput": true
}
]
},
"options": {
"fallbackOutput": "extra"
}
},
"typeVersion": 3.2
},
{
"id": "91779d6a-b7ac-4d77-8211-0528614147c9",
"name": "社交分析",
"type": "n8n-nodes-base.executeWorkflow",
"disabled": true,
"position": [
1248,
-384
],
"parameters": {
"options": {},
"workflowId": {
"__rl": true,
"mode": "id",
"value": "="
},
"workflowInputs": {
"value": {
"ticker": "={{ $json.rest }}"
},
"schema": [
{
"id": "ticker",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "ticker",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"ticker"
],
"attemptToConvertTypes": false,
"convertFieldsToString": true
}
},
"typeVersion": 1.2
},
{
"id": "0f762bb5-6a18-42eb-8528-ab39bbde3686",
"name": "社交分析输出",
"type": "n8n-nodes-base.telegram",
"position": [
1680,
-384
],
"webhookId": "0a425c4d-1693-4fc6-b1de-cba1d741d62d",
"parameters": {
"text": "=Symbol: {{ $json.symbol }}\n\nSentiment Score: {{ $json.sentiment_score }}\n\nRational: {{ $json.rationale }}\n---\nCommand:{{ $node[\"Seperate command and Parameter\"].json[\"command\"] }}\nParameter: {{ $node[\"Seperate command and Parameter\"].json[\"rest\"] }}\n",
"chatId": "={{ $node[\"Telegram Trigger\"].json[\"message\"][\"from\"][\"id\"] }}\n",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "rftJijuNnjbeZjEv",
"name": "Telegram account - AmirStockBot"
}
},
"typeVersion": 1.2
},
{
"id": "aa73de3b-23e0-4f78-8cc6-3e79bd836294",
"name": "sentimental_analysis",
"type": "n8n-nodes-base.executeWorkflow",
"disabled": true,
"position": [
1248,
-1040
],
"parameters": {
"options": {},
"workflowId": {
"__rl": true,
"mode": "id",
"value": ""
}
},
"typeVersion": 1.2
},
{
"id": "06fa30d0-7d38-41da-9edd-1c685ef8cc97",
"name": "通用输出1",
"type": "n8n-nodes-base.telegram",
"position": [
1680,
-592
],
"webhookId": "9d8bc712-a61a-4508-a7c3-3c6ba6d723ab",
"parameters": {
"text": "={{ $('Valid Commands').first().json.validCommands }}\n\n---\nCommand:{{ $node[\"Seperate command and Parameter\"].json[\"command\"] }}\nParameter: {{ $node[\"Seperate command and Parameter\"].json[\"rest\"] }}\n",
"chatId": "={{ $node[\"Telegram Trigger\"].json[\"message\"][\"from\"][\"id\"] }}\n",
"additionalFields": {
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "rftJijuNnjbeZjEv",
"name": "Telegram account - AmirStockBot"
}
},
"typeVersion": 1.2
},
{
"id": "541b48b2-1b86-4535-858c-5d4de3bde7ab",
"name": "便签4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-928,
-1136
],
"parameters": {
"width": 624,
"height": 848,
"content": "# Telegram命令中心"
},
"typeVersion": 1
},
{
"id": "e4c26f0f-deac-4f71-958a-15a4d44dc02e",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
224,
-624
],
"parameters": {
"color": 3,
"width": 224,
"height": 80,
"content": "2.在此处更新您可用的命令"
},
"typeVersion": 1
},
{
"id": "5fb4ea46-0f49-4b7f-be52-c7323a556337",
"name": "便签6",
"type": "n8n-nodes-base.stickyNote",
"position": [
608,
-928
],
"parameters": {
"color": 3,
"width": 224,
"height": 80,
"content": "3.在此处更新命令列表"
},
"typeVersion": 1
},
{
"id": "911c5ead-a29b-4c72-8f40-e12ab10ce3f4",
"name": "便签7",
"type": "n8n-nodes-base.stickyNote",
"position": [
1008,
-624
],
"parameters": {
"color": 3,
"width": 224,
"height": 80,
"content": "4.连接到相关子工作流并使用消息进行回复"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"callerPolicy": "workflowsFromSameOwner",
"executionOrder": "v1"
},
"versionId": "9b90b18a-1fa1-4104-b613-46c69ace0f04",
"connections": {
"Access Control": {
"main": [
[
{
"node": "Valid Commands",
"type": "main",
"index": 0
}
],
[
{
"node": "Access Denied",
"type": "main",
"index": 0
}
]
]
},
"Instagram post": {
"main": [
[
{
"node": "Generic Output",
"type": "main",
"index": 0
}
]
]
},
"Valid Commands": {
"main": [
[
{
"node": "Seperate command and Parameter",
"type": "main",
"index": 0
}
]
]
},
"Social Analysis": {
"main": [
[
{
"node": "format_output_as_json",
"type": "main",
"index": 0
}
]
]
},
"Telegram Trigger": {
"main": [
[
{
"node": "Access Control",
"type": "main",
"index": 0
}
]
]
},
"sentimental_analysis": {
"main": [
[
{
"node": "Processing has finished",
"type": "main",
"index": 0
}
]
]
},
"Switch to the Command": {
"main": [
[
{
"node": "sentimental_analysis",
"type": "main",
"index": 0
}
],
[
{
"node": "Instagram post",
"type": "main",
"index": 0
}
],
[
{
"node": "Generic Output1",
"type": "main",
"index": 0
}
],
[
{
"node": "Social Analysis",
"type": "main",
"index": 0
}
],
[
{
"node": "Command not found",
"type": "main",
"index": 0
}
]
]
},
"format_output_as_json": {
"main": [
[
{
"node": "Social Analysis Output",
"type": "main",
"index": 0
}
]
]
},
"Processing has finished": {
"main": [
[]
]
},
"Seperate command and Parameter": {
"main": [
[
{
"node": "Switch to the Command",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 客服机器人, AI 聊天机器人
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
J.A.R.V.I.S.
在Telegram上使用OpenAI、SERP和向量存储构建全面的多模态助手
If
Set
Code
+16
48 节点FabioInTech
客服机器人
Telegram支持交接自动化
使用GPT4和邮件提醒自动化Telegram支持从AI到人工的交接
If
Set
Switch
+12
40 节点Meelioo
客服机器人
多语言语音文本Telegram机器人(ElevenLabs TTS与LangChain代理)
集成ElevenLabs语音合成与LangChain代理的多语言语音文本Telegram机器人
If
Set
Switch
+10
18 节点IvanCore
客服机器人
我的工作流
集成 Google 日历和 Sheets 的 Telegram 预约调度机器人
If
Code
Switch
+5
32 节点Club de Inteligencia Artificial Politécnico CIAP
客服机器人
ESPOLBot日历|常见问题
基于Telegram、MongoDB和Gemini AI的大学常见问题与日历助手
Set
Code
Html
+14
91 节点Club de Inteligencia Artificial Politécnico CIAP
客服机器人
带有 Chatgpt Agent Prompt 检查的信用卡
AI驱动信用卡推荐系统,集成OpenAI GPT、Telegram和Google Sheets
If
Set
Code
+7
31 节点Nishant
AI 聊天机器人
工作流信息
难度等级
高级
节点数量23
分类2
节点类型8
作者
Amir
@amandegarPassionate AI Automation, Visualization and Data Fabric Consultant | Helping to Shape the Future of Business through Innovation
外部链接
在 n8n.io 查看 →
分享此工作流