Vorlage für den Supervisor

Experte

Dies ist ein AI Chatbot, Multimodal AI-Bereich Automatisierungsworkflow mit 20 Nodes. Hauptsächlich werden If, Code, Switch, Postgres, Telegram und andere Nodes verwendet. Dynamischer Kryptowährungs-Marktüberwachungs mit Gemini AI und Telegram-Bot erstellen

Voraussetzungen
  • PostgreSQL-Datenbankverbindungsdaten
  • Telegram Bot Token
  • Möglicherweise sind Ziel-API-Anmeldedaten erforderlich
Workflow-Vorschau
Visualisierung der Node-Verbindungen, mit Zoom und Pan
Workflow exportieren
Kopieren Sie die folgende JSON-Konfiguration und importieren Sie sie in n8n
{
  "id": "Ny9z9pagXSVaZDRt",
  "meta": {
    "instanceId": "0ebffe66be2ea4fbaaa1bf139c315512a2543884e5ce6d776f31c748d2d8c005",
    "templateCredsSetupCompleted": true
  },
  "name": "Supervisor template",
  "tags": [],
  "nodes": [
    {
      "id": "ac10d615-30a7-42c1-ba26-95e1910a2574",
      "name": "Error Authorization",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -144,
        -160
      ],
      "webhookId": "ec13ff32-9853-4b09-882d-8674e1db92a5",
      "parameters": {
        "text": "=Hi ~ {{ $json.message.chat.username }}\nYou are not authorized, thk !",
        "chatId": "={{ $json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $json.message.message_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "WDgUm2xLk6YE4vSG",
          "name": "Tg-Watch-Dog"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e183e45c-cdb1-47d3-ba39-3f663f4ae235",
      "name": "Schalter",
      "type": "n8n-nodes-base.switch",
      "position": [
        96,
        -512
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "start",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "032f2ecc-3100-43cc-82db-aa44866cdf4d",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.command }}",
                    "rightValue": "start"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "help",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d73cb511-1cef-488c-b5b8-13d31f900f97",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.command }}",
                    "rightValue": "help"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "add",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "8d2cbba2-dbf6-43e7-a2ea-7bb4c0d52627",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.command }}",
                    "rightValue": "add"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "list",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "29a24cc8-d341-40a7-bf1d-660e078bca25",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.command }}",
                    "rightValue": "list"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "delete",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "953a9f37-fd41-4b60-b9da-c88a3d15c02c",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.command }}",
                    "rightValue": "delete"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "fc2c866e-b1fb-4a93-b87d-204dcc90b2a2",
      "name": "Test return success",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        -880
      ],
      "webhookId": "c3f5afb5-cdfe-402c-b864-7fa69a793991",
      "parameters": {
        "text": "=Hi ~ {{ $json.message.chat.username }}\nTest return Success !",
        "chatId": "={{ $('Authorization').first().json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $('Authorization').first().json.message.message_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "WDgUm2xLk6YE4vSG",
          "name": "Tg-Watch-Dog"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "82274131-1eb2-4cde-9211-3883d0879ce9",
      "name": "Parse user text",
      "type": "n8n-nodes-base.code",
      "position": [
        -144,
        -464
      ],
      "parameters": {
        "jsCode": "// 从输入数据中获取消息的核心信息\nconst message = $input.item.json.message;\nconst text = message.text.trim(); // 使用 trim() 移除首尾多余空格\nconst chatId = message.chat.id;\n\n// 初始化一个标准的结果对象\nconst result = {\n  chatId: chatId,\n  command: null,\n  symbol: null,\n  interval: null,\n  prompt: null,\n  error: null\n};\n\n// 使用正则表达式来捕获指令和其后的所有内容\nconst baseRegex = /^\\/(\\w+)\\s*(.*)$/;\nconst baseMatch = text.match(baseRegex);\n\n// 如果连基础的 /<command> 格式都匹配不上,直接返回错误\nif (!baseMatch) {\n  result.error = \"无法识别的指令格式。\";\n  return result;\n}\n\n// 提取指令和参数部分\nconst command = baseMatch[1].toLowerCase();\nconst argsString = baseMatch[2]; // 指令后面的所有参数字符串\n\nresult.command = command;\n\n// 使用 switch 语句来根据不同的指令进行解析\nswitch (command) {\n  case 'add':\n    // 解析 /add SYMBOL INTERVAL PROMPT\n    const addArgs = argsString.match(/^([A-Z0-9]+)\\s+([a-zA-Z0-9]+)\\s+(.*)$/);\n    if (addArgs) {\n      result.symbol = addArgs[1];\n      result.interval = addArgs[2];\n      result.prompt = addArgs[3];\n    } else {\n      result.error = \"`/add` 指令格式错误。正确格式: /add <SYMBOL> <INTERVAL> <PROMPT>\";\n    }\n    break;\n\n  case 'search':\n    // 解析 /search SYMBOL INTERVAL\n    const searchArgs = argsString.match(/^([A-Z0-9]+)\\s+([a-zA-Z0-9]+)$/);\n    if (searchArgs) {\n      result.symbol = searchArgs[1];\n      result.interval = searchArgs[2];\n    } else {\n      result.error = \"`/search` 指令格式错误。正确格式: /search <SYMBOL> <INTERVAL>\";\n    }\n    break;\n\n  case 'start':\n  case 'help':\n    // 这两个指令没有参数,所以不需要额外解析\n    // 如果 argsString 不是空的,说明用户多输入了内容,但我们选择忽略\n    break;\n  case 'list':\n    break;\n  case 'delete':\n    // 解析 /delete SYMBOL\n    // 正则表达式只匹配一个参数 (交易对)\n    const deleteArgs = argsString.match(/^([A-Z0-9]+)$/);\n    if (deleteArgs) {\n      result.symbol = deleteArgs[1];\n    } else {\n      result.error = \"`/delete` 指令格式错误。正确格式: /delete <SYMBOL>\";\n    }\n    break;\n\n  default:\n    // 如果指令不在我们的处理列表里\n    result.error = `未知的指令: /${command}`;\n    break;\n}\n\n// 返回最终解析的结果\nreturn result;"
      },
      "typeVersion": 2
    },
    {
      "id": "7e9596ad-49ee-40f5-84de-6d589a51e939",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        880,
        -528
      ],
      "parameters": {
        "jsCode": "// 从输入数据中获取参数\nconst symbol = $('Switch').first().json.symbol || 'BTCUSDT';\nconst interval = $('Switch').first().json.interval || '1h';\nconst prompt = $('Switch').first().json.prompt || '跌破新低';\n\n// 根据 interval 设置调度规则\nlet scheduleRule;\nif (interval === '1h') {\n  scheduleRule = {\n    \"interval\": [\n      {\n        \"field\": \"hours\",\n        \"hoursInterval\": 1\n      }\n    ]\n  };\n} else if (interval === '15m') {\n  scheduleRule = {\n    \"interval\": [\n      {\n        \"field\": \"minutes\",\n        \"minutesInterval\": 15\n      }\n    ]\n  };\n} else if (interval === '1d') {\n  scheduleRule = {\n    \"interval\": [\n      {\n        \"field\": \"days\",\n        \"daysInterval\": 1\n      }\n    ]\n  };\n} else {\n  scheduleRule = {\n    \"interval\": [\n      {\n        \"field\": \"hours\",\n        \"hoursInterval\": 1\n      }\n    ]\n  };\n}\n\n// 修复 Code 节点的 JavaScript 代码 - 去掉双重转义\nconst codeNodeJS = \"// --- 我们只修改了这一行 ---\\n// 获取 AI 节点输出的、嵌套较深的原始字符串\\nconst aiRawOutput = $json.content.parts[0].text;\\n\\n// --- 后续代码与之前完全相同,无需改动 ---\\n\\n// 使用正则表达式来提取被 ´´´ 包裹的 JSON 字符串部分\\nconst jsonMatch = aiRawOutput.match(/\\\\{[\\\\s\\\\S]*\\\\}/);\\n\\n// 检查是否成功找到了 JSON 字符串\\nif (jsonMatch && jsonMatch[0]) {\\n  try {\\n    // 将提取出来的纯 JSON 字符串,解析成一个真正的 JSON 对象\\n    const parsedData = JSON.parse(jsonMatch[0]);\\n    \\n    // 将这个解析后的对象作为本节点的输出\\n    return {\\n      json: parsedData\\n    };\\n  } catch (error) {\\n    // 如果解析失败,返回错误信息\\n    return { json: { error: \\\"解析JSON失败\\\", details: error.message } };\\n  }\\n}\\n\\n// 如果连 JSON 字符串都找不到,也返回错误信息\\nreturn { json: { error: \\\"在AI输出中未找到JSON块\\\" } };\";\n\n// 生成符合 n8n API 要求的 workflow JSON\nconst workflowJson = {\n  \"name\": \"WatchDog-\" + symbol,\n  \"nodes\": [\n    {\n      \"parameters\": {\n        \"operation\": \"executeQuery\",\n        \"query\": \"SELECT * FROM watchdog WHERE symbol = '\" + symbol + \"';\",\n        \"options\": {}\n      },\n      \"type\": \"n8n-nodes-base.postgres\",\n      \"typeVersion\": 2,\n      \"position\": [-176, -80],\n      \"name\": \"Execute a SQL query\",\n      \"credentials\": {\n        \"postgres\": {\n          \"id\": \"cOj0Kt9xrVLHTEvg\",\n          \"name\": \"Self-PostgreSQL\"\n        }\n      }\n    },\n    {\n      \"parameters\": {\n        \"rule\": scheduleRule\n      },\n      \"type\": \"n8n-nodes-base.scheduleTrigger\",\n      \"typeVersion\": 1,\n      \"position\": [-864, -80],\n      \"name\": \"Schedule Trigger\"\n    },\n    {\n      \"parameters\": {\n        \"assignments\": {\n          \"assignments\": [\n            {\n              \"id\": \"7931ff5e-f133-4a07-b81a-7a2c3251e73d\",\n              \"name\": \"symbol\",\n              \"value\": \"=\" + symbol,\n              \"type\": \"string\"\n            }\n          ]\n        },\n        \"options\": {}\n      },\n      \"type\": \"n8n-nodes-base.set\",\n      \"typeVersion\": 3.4,\n      \"position\": [-416, -80],\n      \"name\": \"Symbol\"\n    },\n    {\n      \"parameters\": {\n        \"method\": \"GET\",\n        \"url\": \"https://api.chart-img.com/v1/tradingview/advanced-chart/storage\",\n        \"authentication\": \"genericCredentialType\",\n        \"genericAuthType\": \"httpHeaderAuth\",\n        \"sendQuery\": true,\n        \"queryParameters\": {\n          \"parameters\": [\n            {\n              \"name\": \"symbol\",\n              \"value\": \"BINANCE:\" + symbol\n            },\n            {\n              \"name\": \"interval\",\n              \"value\": interval\n            }\n          ]\n        },\n        \"options\": {}\n      },\n      \"type\": \"n8n-nodes-base.httpRequest\",\n      \"typeVersion\": 4,\n      \"position\": [32, -80],\n      \"name\": \"Get Image URL\",\n      \"alwaysOutputData\": true,\n      \"retryOnFail\": true,\n      \"credentials\": {\n        \"httpHeaderAuth\": {\n          \"id\": \"9UoBK15KWPsdtqWd\",\n          \"name\": \"Chart-Image-1\"\n        }\n      }\n    },\n    {\n      \"parameters\": {\n        \"resource\": \"image\",\n        \"operation\": \"analyze\",\n        \"modelId\": {\n          \"__rl\": true,\n          \"value\": \"models/gemini-2.5-flash\",\n          \"mode\": \"list\",\n          \"cachedResultName\": \"models/gemini-2.5-flash\"\n        },\n        \"text\": \"={{ $('Prompt').item.json.prompt }}\\n这是用户prompt:{{ $('Execute a SQL query').item.json.user_prompt }}\\n\",\n        \"imageUrls\": \"={{ $json.url }}\",\n        \"options\": {}\n      },\n      \"type\": \"@n8n/n8n-nodes-langchain.googleGemini\",\n      \"typeVersion\": 1,\n      \"position\": [240, -80],\n      \"name\": \"Analyze image\",\n      \"retryOnFail\": true,\n      \"credentials\": {\n        \"googlePalmApi\": {\n          \"id\": \"cDsR8cQyCG3zNb4H\",\n          \"name\": \"ad-7\"\n        }\n      }\n    },\n    {\n      \"parameters\": {\n        \"mode\": \"runOnceForEachItem\",\n        \"jsCode\": codeNodeJS\n      },\n      \"type\": \"n8n-nodes-base.code\",\n      \"typeVersion\": 2,\n      \"position\": [464, -80],\n      \"name\": \"Code\"\n    },\n    {\n      \"parameters\": {\n        \"rules\": {\n          \"values\": [\n            {\n              \"conditions\": {\n                \"options\": {\n                  \"caseSensitive\": true,\n                  \"leftValue\": \"\",\n                  \"typeValidation\": \"strict\",\n                  \"version\": 2\n                },\n                \"conditions\": [\n                  {\n                    \"leftValue\": \"={{ $json.is_alert }}\",\n                    \"rightValue\": \"N\",\n                    \"operator\": {\n                      \"type\": \"string\",\n                      \"operation\": \"equals\"\n                    }\n                  }\n                ],\n                \"combinator\": \"and\"\n              },\n              \"renameOutput\": true,\n              \"outputKey\": \"N\"\n            },\n            {\n              \"conditions\": {\n                \"options\": {\n                  \"caseSensitive\": true,\n                  \"leftValue\": \"\",\n                  \"typeValidation\": \"strict\",\n                  \"version\": 2\n                },\n                \"conditions\": [\n                  {\n                    \"leftValue\": \"={{ $json.is_alert }}\",\n                    \"rightValue\": \"Y\",\n                    \"operator\": {\n                      \"type\": \"string\",\n                      \"operation\": \"equals\"\n                    }\n                  }\n                ],\n                \"combinator\": \"and\"\n              },\n              \"renameOutput\": true,\n              \"outputKey\": \"Y\"\n            }\n          ]\n        },\n        \"options\": {}\n      },\n      \"type\": \"n8n-nodes-base.switch\",\n      \"typeVersion\": 3,\n      \"position\": [-608, 176],\n      \"name\": \"Switch\"\n    },\n    {\n      \"parameters\": {\n        \"chatId\": \"-10011111\",\n        \"text\": \"=<b>内容分析:</b>\\n{{ $json.alert_content }}\",\n        \"additionalFields\": {\n          \"appendAttribution\": false,\n          \"parse_mode\": \"HTML\",\n          \"message_thread_id\": 162\n        }\n      },\n      \"type\": \"n8n-nodes-base.telegram\",\n      \"typeVersion\": 1,\n      \"position\": [-400, 272],\n      \"name\": \"Send a text message\",\n      \"credentials\": {\n        \"telegramApi\": {\n          \"id\": \"WeVmUCGtDb8kVLoc\",\n          \"name\": \"Tg N8N bot\"\n        }\n      }\n    },\n    {\n      \"parameters\": {\n        \"operation\": \"sendPhoto\",\n        \"chatId\": \"-1001111111\",\n        \"file\": \"={{ $('Get Image URL').item.json.url }}\",\n        \"additionalFields\": {\n          \"message_thread_id\": 162\n        }\n      },\n      \"type\": \"n8n-nodes-base.telegram\",\n      \"typeVersion\": 1,\n      \"position\": [-176, 272],\n      \"name\": \"Send a photo message\",\n      \"credentials\": {\n        \"telegramApi\": {\n          \"id\": \"WeVmUCGtDb8kVLoc\",\n          \"name\": \"Tg N8N bot\"\n        }\n      }\n    },\n    {\n      \"parameters\": {\n        \"assignments\": {\n          \"assignments\": [\n            {\n              \"id\": \"2921ed36-5239-41fa-8f5c-6728de9eba65\",\n              \"name\": \"prompt\",\n              \"value\": \"=角色\\n你是一个顶级的 K 线量化分析引擎。你的唯一任务是基于图表(Image)和用户条件(User Prompt),对市场信号进行客观裁决。\\n\\n指令\\n解析: 解析 User Prompt。\\n\\n提取: 从图表(Image)中提取所有关键数据(如最新价、均线值、高/低点)。\\n\\n裁决: 将提取的数据与解析后的条件进行比对,得出 True/False 结果。\\n\\n输出: 生成一个纯净的 JSON 对象作为你唯一的最终回复。不要包含任何解释。\\n\\n词库 (唯一的释义标准)\\n行为:\\n\\n突破: 收盘价 > 参考价。\\n\\n跌破: 收盘价 < 参考价。\\n\\n站上: 当前价/收盘价 > 参考价。\\n\\n触及: K 线的最高价或最低价达到参考价。\\n\\n参考:\\n\\n均线 (MA): 例如 MA20,指简单移动平均线。\\n\\n前高/前低: 可视范围内的显著波段高/低点。\\n\\n新高/新低: 在指定周期内(如 1小时、20根K线内)的最高/最低价。\\n\\n修饰:\\n\\n放量: 成交量显著高于近期平均值(如 > 5周期均量)。\\n\\n输出格式 (严格遵守)\\n你的全部输出必须且只能是以下 JSON 对象:\\n{\\n\\\"is_alert\\\": \\\"Y | N\\\",\\n\\\"alert_content\\\": \\\"触发或未触发的具体原因描述,并包含关键数据。\\\"\\n}\",\n              \"type\": \"string\"\n            }\n          ]\n        },\n        \"options\": {}\n      },\n      \"type\": \"n8n-nodes-base.set\",\n      \"typeVersion\": 3.4,\n      \"position\": [-656, -80],\n      \"name\": \"Prompt\"\n    }\n  ],\n  \"connections\": {\n    \"Schedule Trigger\": {\n      \"main\": [\n        [\n          {\n            \"node\": \"Prompt\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    },\n    \"Symbol\": {\n      \"main\": [\n        [\n          {\n            \"node\": \"Execute a SQL query\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    },\n    \"Execute a SQL query\": {\n      \"main\": [\n        [\n          {\n            \"node\": \"Get Image URL\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    },\n    \"Get Image URL\": {\n      \"main\": [\n        [\n          {\n            \"node\": \"Analyze image\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    },\n    \"Analyze image\": {\n      \"main\": [\n        [\n          {\n            \"node\": \"Code\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    },\n    \"Code\": {\n      \"main\": [\n        [\n          {\n            \"node\": \"Switch\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    },\n    \"Switch\": {\n      \"main\": [\n        [],\n        [\n          {\n            \"node\": \"Send a text message\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    },\n    \"Send a text message\": {\n      \"main\": [\n        [\n          {\n            \"node\": \"Send a photo message\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    },\n    \"Prompt\": {\n      \"main\": [\n        [\n          {\n            \"node\": \"Symbol\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    }\n  },\n  \"settings\": {}\n};\n\n// 返回生成的 workflow JSON\nreturn { json: workflowJson };"
      },
      "retryOnFail": true,
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "a408b5d8-43c4-4695-bc5a-78a2d9e6f8ea",
      "name": "Create Workflow",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1104,
        -528
      ],
      "parameters": {
        "url": "http://localhost:5678/api/v1/workflows",
        "method": "POST",
        "options": {
          "allowUnauthorizedCerts": true
        },
        "jsonBody": "={{ $json}}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "pvkTsOFr2OoC9RpW",
          "name": "N8N-API-KEY"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "e68d5c6d-9f97-41c2-a6af-fd1bc383c10e",
      "name": "Activate",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1360,
        -528
      ],
      "parameters": {
        "url": "=http://localhost:5678/api/v1/workflows/{{ $json.id }}/activate",
        "method": "POST",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "pvkTsOFr2OoC9RpW",
          "name": "N8N-API-KEY"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "9a90e49a-e992-45f9-8f5b-eb51eacc495a",
      "name": "Add Data",
      "type": "n8n-nodes-base.postgres",
      "position": [
        656,
        -528
      ],
      "parameters": {
        "query": "INSERT INTO watchdog (symbol, user_prompt)\nVALUES ('{{ $json.symbol }}', '{{ $json.prompt }}')\nON CONFLICT (symbol)\nDO UPDATE SET user_prompt = EXCLUDED.user_prompt;",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "id": "cOj0Kt9xrVLHTEvg",
          "name": "Self-PostgreSQL"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "61a33fa9-3e54-4106-b6be-ecd4e3cdff33",
      "name": "Zusammenführen All list",
      "type": "n8n-nodes-base.code",
      "position": [
        880,
        -352
      ],
      "parameters": {
        "jsCode": "// 获取上一个节点传来的所有 item 数组\nconst items = $input.all();\n\n// 创建一个空数组,用来存放格式化后的每一行文本\nconst formattedLines = [];\n\n// 遍历每一个 item\nfor (const item of items) {\n  // 从每个 item 的 json 数据中提取 symbol 和 user_prompt\n  const symbol = item.json.symbol;\n  const user_prompt = item.json.user_prompt;\n\n  // 【修改点】使用 Markdown 的反引号(`)将 symbol 包裹起来\n  // 这会让它在 Telegram 中显示为蓝色可复制的等宽字体\n  const line = `\\`${symbol}\\`: ${user_prompt}`;\n  \n  // 将这行文本添加到数组中\n  formattedLines.push(line);\n}\n\n// 将数组中的所有行用换行符(\\n)连接成一个完整的、多行的字符串\nconst listAsText = formattedLines.join('\\n');\n\n// 返回包含这个最终字符串的单个 item\nreturn {\n  json: {\n    listText: listAsText\n  }\n};\n"
      },
      "typeVersion": 2
    },
    {
      "id": "5ee9424f-b554-4d67-b477-ab32676a82ba",
      "name": "Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -752,
        -352
      ],
      "webhookId": "86422a87-0120-4420-9d5d-ad0492aee2b8",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "WDgUm2xLk6YE4vSG",
          "name": "Tg-Watch-Dog"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "cc2bac2d-06ef-4b2f-ae98-b4ae4e48e9f2",
      "name": "WatchDog Success",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1600,
        -528
      ],
      "webhookId": "08db187e-b8fb-48a3-b958-7b0ba3811eb9",
      "parameters": {
        "text": "=Wtach Dog for {{ $('Parse user text').item.json.symbol }} Return success !",
        "chatId": "={{ $('Authorization').first().json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $('Authorization').first().json.message.message_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "WDgUm2xLk6YE4vSG",
          "name": "Tg-Watch-Dog"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1.2,
      "alwaysOutputData": false
    },
    {
      "id": "f697a327-159e-467a-aa5f-bd1cfb7f6aee",
      "name": "Get list",
      "type": "n8n-nodes-base.postgres",
      "position": [
        656,
        -352
      ],
      "parameters": {
        "query": "SELECT * FROM watchdog;",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "id": "cOj0Kt9xrVLHTEvg",
          "name": "Self-PostgreSQL"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "9a64d1fe-e297-4c77-a9a0-7a9014942edc",
      "name": "Send list",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1104,
        -352
      ],
      "webhookId": "4cbf7622-ef90-44e1-a913-4ea917880aee",
      "parameters": {
        "text": "=List\n{{ $json.listText }}",
        "chatId": "={{ $('Authorization').first().json.message.chat.id }}",
        "additionalFields": {
          "parse_mode": "MarkdownV2",
          "appendAttribution": false,
          "reply_to_message_id": "={{ $('Authorization').first().json.message.message_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "WDgUm2xLk6YE4vSG",
          "name": "Tg-Watch-Dog"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1.2,
      "alwaysOutputData": false
    },
    {
      "id": "5d6add8d-fa73-4d30-a490-47a624628669",
      "name": "Return help manu",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        -704
      ],
      "webhookId": "e346b005-4523-4e39-b370-0c1c9bc219f6",
      "parameters": {
        "text": "=This is the command list\n/help - Get the help list\n/start - Test bot authorized?\n/add - Add symbol to watchdog SQL\n/delete - Delete a symbol in watchdog SQL\n/search - Search the status of a symbol",
        "chatId": "={{ $('Authorization').first().json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $('Authorization').first().json.message.message_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "WDgUm2xLk6YE4vSG",
          "name": "Tg-Watch-Dog"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d999e630-582a-43a0-869b-bd19b2bef00f",
      "name": "Update workflow id",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1360,
        -704
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "watchdog",
          "cachedResultName": "watchdog"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "symbol": "={{ $('Parse user text').first().json.symbol }}",
            "workflow_id": "={{$json.id}}"
          },
          "schema": [
            {
              "id": "id",
              "type": "number",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "symbol",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "symbol",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "user_prompt",
              "type": "string",
              "display": true,
              "removed": true,
              "required": true,
              "displayName": "user_prompt",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "workflow_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "workflow_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "symbol"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update"
      },
      "credentials": {
        "postgres": {
          "id": "cOj0Kt9xrVLHTEvg",
          "name": "Self-PostgreSQL"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "8e6c050d-270c-405a-bc06-3cb0fa052b1c",
      "name": "Get workflow id",
      "type": "n8n-nodes-base.postgres",
      "position": [
        656,
        -144
      ],
      "parameters": {
        "query": "SELECT * FROM watchdog Where symbol = '{{ $json.symbol }}'",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "id": "cOj0Kt9xrVLHTEvg",
          "name": "Self-PostgreSQL"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "d054f258-5a8b-4061-9bea-90d619900cf8",
      "name": "Delete the Workflow",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        880,
        -144
      ],
      "parameters": {
        "url": "=http://localhost:5678/api/v1/workflows/{{ $json.workflow_id }}",
        "method": "DELETE",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "pvkTsOFr2OoC9RpW",
          "name": "N8N-API-KEY"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "807d9c1c-f2c9-44f5-bc63-7d6a19bb8304",
      "name": "Delete the row",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1120,
        -144
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "watchdog",
          "cachedResultName": "watchdog"
        },
        "where": {
          "values": [
            {
              "value": "={{ $('Get workflow id').item.json.symbol }}",
              "column": "symbol"
            }
          ]
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "options": {},
        "operation": "deleteTable",
        "deleteCommand": "delete"
      },
      "credentials": {
        "postgres": {
          "id": "cOj0Kt9xrVLHTEvg",
          "name": "Self-PostgreSQL"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "0ef67cc9-1d5e-406a-8736-ee07777bf741",
      "name": "WatchDog Success1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1328,
        -144
      ],
      "webhookId": "90cabb38-5d4b-4afe-8caf-713280264e73",
      "parameters": {
        "text": "=Delete for {{ $('Parse user text').item.json.symbol }} Success ",
        "chatId": "={{ $('Authorization').first().json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $('Authorization').first().json.message.message_id }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "WDgUm2xLk6YE4vSG",
          "name": "Tg-Watch-Dog"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fd74a0fa-717b-41fa-9a12-92063b2dc82a",
      "name": "Authorization",
      "type": "n8n-nodes-base.if",
      "position": [
        -416,
        -352
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7374aeb6-2a79-474b-90ee-783e412f5247",
              "operator": {
                "type": "number",
                "operation": "equals"
              },
              "leftValue": "={{ $json.message.from.id }}",
              "rightValue": 111111
            },
            {
              "id": "6de78c03-587a-47e9-9b91-452183a83982",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.message.entities[0].type }}",
              "rightValue": "bot_command"
            }
          ]
        }
      },
      "typeVersion": 2.2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ad97ca01-b134-4410-830b-430415ea98da",
  "connections": {
    "7e9596ad-49ee-40f5-84de-6d589a51e939": {
      "main": [
        [
          {
            "node": "a408b5d8-43c4-4695-bc5a-78a2d9e6f8ea",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "fc2c866e-b1fb-4a93-b87d-204dcc90b2a2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "5d6add8d-fa73-4d30-a490-47a624628669",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "9a90e49a-e992-45f9-8f5b-eb51eacc495a",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "f697a327-159e-467a-aa5f-bd1cfb7f6aee",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "8e6c050d-270c-405a-bc06-3cb0fa052b1c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5ee9424f-b554-4d67-b477-ab32676a82ba": {
      "main": [
        [
          {
            "node": "fd74a0fa-717b-41fa-9a12-92063b2dc82a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e68d5c6d-9f97-41c2-a6af-fd1bc383c10e": {
      "main": [
        [
          {
            "node": "cc2bac2d-06ef-4b2f-ae98-b4ae4e48e9f2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "9a90e49a-e992-45f9-8f5b-eb51eacc495a": {
      "main": [
        [
          {
            "node": "7e9596ad-49ee-40f5-84de-6d589a51e939",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "f697a327-159e-467a-aa5f-bd1cfb7f6aee": {
      "main": [
        [
          {
            "node": "Merge All list",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "fd74a0fa-717b-41fa-9a12-92063b2dc82a": {
      "main": [
        [
          {
            "node": "82274131-1eb2-4cde-9211-3883d0879ce9",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "ac10d615-30a7-42c1-ba26-95e1910a2574",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "807d9c1c-f2c9-44f5-bc63-7d6a19bb8304": {
      "main": [
        [
          {
            "node": "0ef67cc9-1d5e-406a-8736-ee07777bf741",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge All list": {
      "main": [
        [
          {
            "node": "9a64d1fe-e297-4c77-a9a0-7a9014942edc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "a408b5d8-43c4-4695-bc5a-78a2d9e6f8ea": {
      "main": [
        [
          {
            "node": "e68d5c6d-9f97-41c2-a6af-fd1bc383c10e",
            "type": "main",
            "index": 0
          },
          {
            "node": "d999e630-582a-43a0-869b-bd19b2bef00f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "8e6c050d-270c-405a-bc06-3cb0fa052b1c": {
      "main": [
        [
          {
            "node": "d054f258-5a8b-4061-9bea-90d619900cf8",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "82274131-1eb2-4cde-9211-3883d0879ce9": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d054f258-5a8b-4061-9bea-90d619900cf8": {
      "main": [
        [
          {
            "node": "807d9c1c-f2c9-44f5-bc63-7d6a19bb8304",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Häufig gestellte Fragen

Wie verwende ich diesen Workflow?

Kopieren Sie den obigen JSON-Code, erstellen Sie einen neuen Workflow in Ihrer n8n-Instanz und wählen Sie "Aus JSON importieren". Fügen Sie die Konfiguration ein und passen Sie die Anmeldedaten nach Bedarf an.

Für welche Szenarien ist dieser Workflow geeignet?

Experte - KI-Chatbot, Multimodales KI

Ist es kostenpflichtig?

Dieser Workflow ist völlig kostenlos. Beachten Sie jedoch, dass Drittanbieterdienste (wie OpenAI API), die im Workflow verwendet werden, möglicherweise kostenpflichtig sind.

Workflow-Informationen
Schwierigkeitsgrad
Experte
Anzahl der Nodes20
Kategorie2
Node-Typen7
Schwierigkeitsbeschreibung

Für fortgeschrittene Benutzer, komplexe Workflows mit 16+ Nodes

Externe Links
Auf n8n.io ansehen

Diesen Workflow teilen

Kategorien

Kategorien: 34