8
n8n 中文网amn8n.com

使用AI驱动的聊天助手管理Cloudflare DNS记录

高级

这是一个DevOps, AI Chatbot领域的自动化工作流,包含 20 个节点。主要使用 Code, Switch, SplitOut, HttpRequest, Agent 等节点。 使用AI驱动的聊天助手管理Cloudflare DNS记录

前置要求
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
  • PostgreSQL 数据库连接信息
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "fe41feb5409a7d5eb53f7743740840b086b13d9f15b9a1b3a5f34f2bb43129c3",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "053140b0-8397-40b4-877d-e784b7ff42d6",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        -96
      ],
      "parameters": {
        "color": 7,
        "width": 620,
        "height": 240,
        "content": "# 需求"
      },
      "typeVersion": 1
    },
    {
      "id": "94a62db1-db0f-41d6-b4ca-33c0afa77a77",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        160
      ],
      "parameters": {
        "color": 7,
        "width": 620,
        "height": 604,
        "content": "# 作者"
      },
      "typeVersion": 1
    },
    {
      "id": "ee3394d5-ac45-4561-b4c0-ec68961453b9",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        784
      ],
      "parameters": {
        "width": 620,
        "height": 140,
        "content": "# 需要帮助?"
      },
      "typeVersion": 1
    },
    {
      "id": "415e9c96-1bd0-472c-b92e-3ebc1e667a62",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        -256
      ],
      "parameters": {
        "color": 4,
        "width": 1480,
        "height": 140,
        "content": "确保您的表名与实际知识库结构匹配"
      },
      "typeVersion": 1
    },
    {
      "id": "d9fc97f1-30a6-4450-b976-8deb32d536e1",
      "name": "便签9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        -224
      ],
      "parameters": {
        "color": 4,
        "width": 700,
        "height": 80,
        "content": "# CloudFlare 聊天 ↪️️ 获取 / 设置 DNS 记录"
      },
      "typeVersion": 1
    },
    {
      "id": "11b2465a-9298-437d-b49d-b036e14479dc",
      "name": "注释1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        -96
      ],
      "parameters": {
        "color": 3,
        "width": 840,
        "height": 640,
        "content": "## 聊天步骤"
      },
      "typeVersion": 1
    },
    {
      "id": "50256a12-4a51-486e-a2be-a98e24b6f85f",
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        160,
        128
      ],
      "webhookId": "cb890e80-624b-4431-ab35-992849d95cd1",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "d0e313c9-3df3-4fcc-8dd6-8fa0838b812b",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        224,
        352
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "YLUlE1oeNyVmySg5",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fe26fbe4-bd00-446f-b738-84484b07ade4",
      "name": "聊天智能体",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        368,
        128
      ],
      "parameters": {
        "options": {
          "systemMessage": "=You are dns manager for CloudFlare\n\nYou have cf_tool that is your source for getting and setting DNS records.\nOnly return answers based from cf_tool.\n\nWhen calling cf_tool, data args to pass for actions are:\n\nIf you need to get dns record, call cf_tool and pass:\n- action: 'get_dns'\n- domain_id: domain id\n\nif you need to set dns record, call cf_tool and pass:\n- action: 'set_dns'\n- domain_id: domain id\n- record_id: id of a record\n- record_type: type of DNS record\n- new_record_content: new value\n\nIf you need to get domains available in CF, call cf_tool and pass:\n- action 'domain'\n\nBefore calling any user query action, first execute get all domains action."
        }
      },
      "typeVersion": 1.9
    },
    {
      "id": "7489f1c5-68dc-46c9-a80c-f104f661898e",
      "name": "获取顶级域名",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        608,
        608
      ],
      "parameters": {
        "url": "https://api.cloudflare.com/client/v4/zones",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpCustomAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "per_page",
              "value": "=100"
            }
          ]
        }
      },
      "credentials": {
        "httpCustomAuth": {
          "id": "6l2hwj0eyB10vHc2",
          "name": "CloudFlare headers"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.1
    },
    {
      "id": "2bfd5981-6511-4ce8-944e-f583e577519d",
      "name": "Json",
      "type": "n8n-nodes-base.code",
      "position": [
        160,
        944
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet inpt = $input.first().json.query;\nlet out = {};\ntry{\n  out = JSON.parse(inpt)\n} catch{}\nif( out.action ){\n  return {out};\n} else{\n  return {};\n}\n"
      },
      "typeVersion": 2
    },
    {
      "id": "a6d94bec-619d-4863-833d-479cfcac458b",
      "name": "注释2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        576
      ],
      "parameters": {
        "color": 6,
        "width": 840,
        "height": 544,
        "content": "## Cloudflare 操作"
      },
      "typeVersion": 1
    },
    {
      "id": "8c84645c-f5a8-41a2-9bad-c93d29f803fa",
      "name": "切换",
      "type": "n8n-nodes-base.switch",
      "position": [
        368,
        800
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a542a8cc-a11b-41c7-a288-fc0948d002d3",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.out.action }}",
                    "rightValue": "domain"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "6b5fa3fd-e4c2-4e01-bffd-f2ea364dc6a5",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.out.action }}",
                    "rightValue": "get_dns"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f3715811-47d8-4cee-b705-ea1ed4ddd0a3",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.out.action }}",
                    "rightValue": "set_dns"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "5980e4a6-805b-4266-9039-87ae6034dc66",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        400,
        384
      ],
      "parameters": {
        "tableName": "langchain_chat_histories",
        "contextWindowLength": 6
      },
      "credentials": {
        "postgres": {
          "id": "TxgFdIVuxITapbbG",
          "name": "Postgres account"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "24f1a023-b3b3-4c8c-8878-a008a4a05aba",
      "name": "CloudFlare 工具",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        608,
        384
      ],
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}",
          "cachedResultName": "={{ $workflow.id }}"
        },
        "description": "=调用此工具以执行 cloudflare 操作。",
        "workflowInputs": {
          "value": {},
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "1831596a-e9a6-4d64-a5b6-817c0a1f6c26",
      "name": "结束",
      "type": "n8n-nodes-base.noOp",
      "position": [
        704,
        128
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "d1d69661-c963-46aa-9f4e-2b5912a83d21",
      "name": "子调用",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        128,
        688
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "3645506b-0bae-4868-af6f-ffac27aa42db",
      "name": "主机详情",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        768,
        608
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "result"
      },
      "executeOnce": false,
      "typeVersion": 1
    },
    {
      "id": "51811193-5d44-4314-b9d7-a5bf317fc535",
      "name": "获取器",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        608,
        768
      ],
      "parameters": {
        "url": "=https://api.cloudflare.com/client/v4/zones/{{ $json.out.domain_id }}/dns_records",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpCustomAuth",
        "queryParameters": {
          "parameters": [
            {}
          ]
        }
      },
      "credentials": {
        "httpCustomAuth": {
          "id": "6l2hwj0eyB10vHc2",
          "name": "CloudFlare headers"
        }
      },
      "executeOnce": true,
      "typeVersion": 4.1
    },
    {
      "id": "d78642dd-e0bd-470e-9e0a-c602c80e8f5b",
      "name": "设置器",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        608,
        928
      ],
      "parameters": {
        "url": "=https://api.cloudflare.com/client/v4/zones/{{ $json.out.domain_id }}/dns_records/{{ $json.out.record_id }}",
        "method": "PATCH",
        "options": {},
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "content",
              "value": "={{ $json.out.new_record_content }}"
            }
          ]
        },
        "genericAuthType": "httpCustomAuth"
      },
      "credentials": {
        "httpCustomAuth": {
          "id": "6l2hwj0eyB10vHc2",
          "name": "CloudFlare headers"
        }
      },
      "typeVersion": 4.1
    }
  ],
  "pinData": {},
  "connections": {
    "Json": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Get TLDs",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Getter",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Setter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SubCall": {
      "main": [
        [
          {
            "node": "Json",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get TLDs": {
      "main": [
        [
          {
            "node": "Host details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat Agent": {
      "main": [
        [
          {
            "node": "End",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Host details": {
      "main": [
        []
      ]
    },
    "CloudFlare tool": {
      "ai_tool": [
        [
          {
            "node": "Chat Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Chat Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "Chat Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Chat Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 开发运维, AI 聊天机器人

需要付费吗?

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

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

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

作者
KPendic

KPendic

@kres

With 15 years on my back, carrying clients' web apps through the storms of bad code, tight deadlines, and ever-changing tech trends, I now do stuff as an AI Automation Engineer, with focus on streamlining backend services, making systems faster, smarter, and more sustainable.

外部链接
在 n8n.io 查看

分享此工作流