8
n8n 中文网amn8n.com

使用AI与Google表格对话

高级

这是一个AI领域的自动化工作流,包含 19 个节点。主要使用 Set, Code, Filter, Switch, GoogleSheets 等节点,结合人工智能技术实现智能自动化。 使用AI与Google表格对话

前置要求
  • Google Sheets API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "408f9fb9940c3cb18ffdef0e0150fe342d6e655c3a9fac21f0f644e8bedabcd9",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "f3f7546a-8bb3-484c-b0a1-750a8d7d3a74",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        520
      ],
      "parameters": {
        "color": 7,
        "width": 1549,
        "height": 612,
        "content": "### 子工作流:自定义工具"
      },
      "typeVersion": 1
    },
    {
      "id": "a5afaa40-0b68-4d7c-8f78-5cb176fde81d",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -40
      ],
      "parameters": {
        "color": 7,
        "width": 1068,
        "height": 547,
        "content": "### 主工作流:使用自定义工具的 AI 智能体"
      },
      "typeVersion": 1
    },
    {
      "id": "2dc0ce2f-a09c-4804-9962-f542ec78eb87",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        40
      ],
      "parameters": {
        "width": 185.9375,
        "height": 183.85014518022527,
        "content": "## 试用一下"
      },
      "typeVersion": 1
    },
    {
      "id": "8fc97d52-1c18-47ed-ba6f-4c7c9ce8b7d4",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        240
      ],
      "parameters": {
        "color": 7,
        "width": 572,
        "height": 219,
        "content": "这些工具都调用下面的子工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "60cafb69-818f-49fe-b75e-e770304a6aa9",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        260,
        740
      ],
      "parameters": {
        "width": 179.99762227826224,
        "height": 226.64416053838073,
        "content": "在此处更改 Google Sheets 的 URL"
      },
      "typeVersion": 1
    },
    {
      "id": "cd8d92fa-f7ef-47d8-a1a7-5b5aa6faaa96",
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        120,
        40
      ],
      "webhookId": "7668b567-b983-479f-a3e0-ad945707ae6b",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "72ac3bdb-56dc-4634-a0ab-0b1c82e2b23d",
      "name": "OpenAI 聊天模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        160,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "8gccIjcuf3gvaoEr",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "37e5bca6-4274-4714-a9e7-a8e4b7d732e5",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        340,
        320
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "81bf7de8-c4c6-49ce-a2cf-4afca5dce7e2",
      "name": "当由另一个工作流执行时",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        80,
        800
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "operation"
            },
            {
              "name": "query"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "24e5a49d-8f1f-4569-8072-c35f059ebd46",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        480,
        40
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.8
    },
    {
      "id": "8cc35cb9-3371-4034-86b6-3d125d70d81b",
      "name": "列出列工具",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        540,
        320
      ],
      "parameters": {
        "name": "list_columns",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "列出客户数据中的所有列名",
        "workflowInputs": {
          "value": {
            "query": "none",
            "operation": "column_names"
          },
          "schema": [
            {
              "id": "query",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "query",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "operation",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "operation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2
    },
    {
      "id": "acf19978-dd84-4cfb-8034-eb9f14dd9c86",
      "name": "获取列值工具",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        720,
        320
      ],
      "parameters": {
        "name": "column_values",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "获取所有客户的指定列值",
        "workflowInputs": {
          "value": {
            "query": "none",
            "operation": "column_values"
          },
          "schema": [
            {
              "id": "operation",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "operation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "query",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "query",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "operation"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2
    },
    {
      "id": "acd8dad6-2ce5-4a53-9909-da7bc03cf0e2",
      "name": "获取客户工具",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        900,
        320
      ],
      "parameters": {
        "name": "get_customer",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}",
          "cachedResultName": "={{ $workflow.id }}"
        },
        "description": "获取给定客户的所有列",
        "workflowInputs": {
          "value": {
            "query": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('query', ``, 'string') }}",
            "operation": "row"
          },
          "schema": [
            {
              "id": "operation",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "operation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "query",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "query",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "operation"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2
    },
    {
      "id": "43988dff-2270-4d09-a091-8b719c281faf",
      "name": "设置 Google Sheets URL",
      "type": "n8n-nodes-base.set",
      "position": [
        300,
        800
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a96650f2-3a0c-45cb-afdd-ef7ca90b21cc",
              "name": "sheetUrl",
              "type": "string",
              "value": "https://docs.google.com/spreadsheets/d/1GjFBV8HpraNWG_JyuaQAgTb3zUGguh0S_25nO0CMd8A/edit#gid=736425281"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "536225e9-e33c-4819-a2dc-994d8f7c3f30",
      "name": "获取 Google Sheets 内容",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        520,
        800
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "customer_data"
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "={{ $json.sheetUrl }}"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "XHvC7jIRR8A2TlUl",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "a5668364-8824-44cc-8a0f-516906d8f821",
      "name": "检查操作",
      "type": "n8n-nodes-base.switch",
      "position": [
        740,
        800
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Column Names",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "db07e0a3-0a1d-44bd-84a7-59a9442e63a6",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('When Executed by Another Workflow').item.json.operation }}",
                    "rightValue": "column_names"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Column Values",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "96c82351-de4a-4299-903d-8b9b3a3bb931",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('When Executed by Another Workflow').item.json.operation }}",
                    "rightValue": "column_values"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Rows",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "fbc2afd0-361f-4181-94e3-4addc65a9086",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('When Executed by Another Workflow').item.json.operation }}",
                    "rightValue": "row"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "46c3a8c4-ffaf-4373-b421-4d7ee65567b2",
      "name": "获取列名",
      "type": "n8n-nodes-base.set",
      "position": [
        1040,
        620
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "36a7be13-e792-4c0a-9997-f61fe2a7b225",
              "name": "response",
              "type": "array",
              "value": "={{ Object.keys($json) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "190c48e8-4d4b-4e95-a694-49ab76b730da",
      "name": "准备列数据",
      "type": "n8n-nodes-base.set",
      "position": [
        1040,
        800
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bcb75b32-3253-4a31-9771-4faaf12cc2ed",
              "name": "row_number",
              "type": "number",
              "value": "={{ $json.row_number }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9c65e5e6-a3ac-4ed7-8546-b7f2b09b4f96",
      "name": "筛选",
      "type": "n8n-nodes-base.filter",
      "position": [
        1040,
        980
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "dbe89d36-e411-4765-8d4e-91a6425350ac",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.row_number.toString() }}",
              "rightValue": "={{ $('When Executed by Another Workflow').item.json.query }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "39265f3e-a2ea-4174-952a-3665747ff856",
      "name": "准备输出",
      "type": "n8n-nodes-base.code",
      "position": [
        1340,
        800
      ],
      "parameters": {
        "jsCode": "return {\n  'response': JSON.stringify($input.all().map(x => x.json))\n}"
      },
      "executeOnce": true,
      "typeVersion": 2
    }
  ],
  "pinData": {},
  "connections": {
    "Filter": {
      "main": [
        [
          {
            "node": "Prepare output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Check operation": {
      "main": [
        [
          {
            "node": "Get column names",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare column data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get column names": {
      "main": [
        [
          {
            "node": "Prepare output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get customer tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "List columns tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Prepare column data": {
      "main": [
        [
          {
            "node": "Prepare output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Google Sheet URL": {
      "main": [
        [
          {
            "node": "Get Google sheet contents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get column values tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Google sheet contents": {
      "main": [
        [
          {
            "node": "Check operation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Set Google Sheet URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 人工智能

需要付费吗?

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

工作流信息
难度等级
高级
节点数量19
分类1
节点类型11
难度说明

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

外部链接
在 n8n.io 查看

分享此工作流