8
n8n 中文网amn8n.com

模板_代码_智能感知

中级

这是一个Engineering领域的自动化工作流,包含 8 个节点。主要使用 N8n, Code, Form, FormTrigger 等节点。 使用JSDoc为代码节点添加TypeScript智能感知支持

前置要求
  • 无特殊前置要求,导入即可使用

分类

工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "CHfMFle2Ym5WrORl",
  "meta": {
    "instanceId": "87021cc08fe86f3c88c615ac7015b93e398b6bf953b85302471896e86cc798ef",
    "templateCredsSetupCompleted": true
  },
  "name": "模板_代码_智能感知",
  "tags": [],
  "nodes": [
    {
      "id": "4bb15488-9fbd-4233-a5fd-4ea336a28a04",
      "name": "获取此工作流",
      "type": "n8n-nodes-base.n8n",
      "position": [
        -300,
        -20
      ],
      "parameters": {
        "operation": "get",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "AtnwjrQQjpB80Z2Q",
          "name": "n8n unio API v1"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9e494c46-e9fc-40db-8a79-1329c46f30dc",
      "name": "带智能感知的代码",
      "type": "n8n-nodes-base.code",
      "position": [
        -20,
        -20
      ],
      "parameters": {
        "jsCode": "// ----------------------------------------------------------------\n\n// Define core classes you want intellisense for.\n\n/**\n * @typedef {Object} Node\n * @property {string} type\n * @property {number} typeVersion\n * @property {number} id\n * @property {string} name\n */\n\n/**\n * @typedef {Object} Workflow\n * @property {string} name\n * @property {number} id\n * @property {boolean} isArchived\n * @property {Array<Node>} nodes\n */\n\n// Use this inline casting to tell Intellisense what the variable is:\nconst wf = /** @type {Workflow} */ ($input.first().json);\n\nlet output = \"<p>Example:</p>\"; \n\n// Now check and see, wf will present Intellisense!\noutput += \"<p>Workflow.id: \" + wf.id + \"</p>\";\noutput += \"<p>Workflow.name: \" + wf.name + \"</p>\";\noutput += \"<p>Workflow.isArchived: \" + wf.isArchived + \"</p>\";\n\nfor (let i = 0; i < wf.nodes.length; i++) {\n  const node = wf.nodes[i];\n  // node will automatically know its type, Intellisense here\n  output += \"<p>Workflow.nodes[\" + i + \"]: \" + node.name + \"</p>\";\n  output += \"<p>Workflow.nodes[\" + i + \"]: \" + node.type + \"</p>\";\n}\n\nreturn [{ json: { result: output } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "6aeaf1f3-0eca-4f27-8a8e-62cae8e860c7",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -580,
        -140
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 320,
        "content": "## 设置"
      },
      "typeVersion": 1
    },
    {
      "id": "7fe8b7e9-0571-433f-b04a-4f2af8b69aa9",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        -140
      ],
      "parameters": {
        "color": 4,
        "width": 480,
        "height": 320,
        "content": "## 示例"
      },
      "typeVersion": 1
    },
    {
      "id": "74a61d70-17eb-44a5-a23c-c7f3035295e5",
      "name": "表单提交时",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -520,
        -20
      ],
      "webhookId": "d963f33b-cba8-4887-b9d1-65fe4bbc49ad",
      "parameters": {
        "options": {},
        "formTitle": "Test Code Node"
      },
      "typeVersion": 2.2
    },
    {
      "id": "758fcb50-9794-45c9-a9b1-c490fdd96fd8",
      "name": "显示结果",
      "type": "n8n-nodes-base.form",
      "position": [
        480,
        -20
      ],
      "webhookId": "a45895a4-717c-4542-8663-8d6352ba8d19",
      "parameters": {
        "options": {},
        "formFields": {
          "values": [
            {
              "html": "{{ $json.result }}\n\n",
              "fieldType": "html",
              "elementName": "output"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c938cf31-ea77-496a-8e73-a960ca41a586",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -140
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 320,
        "content": "## 输出"
      },
      "typeVersion": 1
    },
    {
      "id": "490fa90f-ca28-4046-a5b4-59db517c0c2d",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -580,
        -280
      ],
      "parameters": {
        "color": 7,
        "width": 1480,
        "height": 120,
        "content": "## 带智能感知的 Code 节点!"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5c08e162-982f-4332-83a1-bca1c87af241",
  "connections": {
    "Display Results": {
      "main": [
        []
      ]
    },
    "Get This Workflow": {
      "main": [
        [
          {
            "node": "Code With Intellisense",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Get This Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code With Intellisense": {
      "main": [
        [
          {
            "node": "Display Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 工程

需要付费吗?

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

工作流信息
难度等级
中级
节点数量8
分类1
节点类型5
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流