8
n8n 中文网amn8n.com

从PDF提取并整理合同详情至Slack、GPT-4o和Google Sheets

高级

这是一个Document Extraction, AI Summarization, Multimodal AI领域的自动化工作流,包含 19 个节点。主要使用 Slack, Switch, HttpRequest, GoogleSheets, SlackTrigger 等节点。 从PDF提取并整理合同详情至Slack、GPT-4o和Google Sheets

前置要求
  • Slack Bot Token 或 Webhook URL
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "e04cc86c30b0cecda8e6bbc7cc41459d9bf4d76816638a14d42d636b91913ebc",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "af0cd5b9-3301-4668-93ec-71e1033d3778",
      "name": "结构化输出",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        544,
        160
      ],
      "parameters": {
        "jsonSchemaExample": "[{\n\t\"Client\": \"XYZ Inc\",\n\t\"Service Provider\": \"ABC Inc\",\n  \"Effective Date\": \"2025/04/29\",\n  \"Expiration Date\" : \"2025/05/29\",\n  \"Signature Date\" : \"2025/05/29\",\n  \"Contract Value\": \"11,000\"\n}]"
      },
      "typeVersion": 1.3
    },
    {
      "id": "c02b6fd7-70d6-47ae-8ea5-2c1ead2e17da",
      "name": "AI 模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        400,
        160
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "vWYprn1xB4TGPXdo",
          "name": "OpenAi account 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c506d41b-aec6-48ad-a33e-15b02e256bb1",
      "name": "接收合同文件",
      "type": "n8n-nodes-base.slackTrigger",
      "position": [
        -640,
        32
      ],
      "webhookId": "0c333af6-a04b-489e-b267-e60cb4664128",
      "parameters": {
        "options": {},
        "trigger": [
          "message"
        ],
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09EG2EN9AA",
          "cachedResultName": "contract"
        }
      },
      "credentials": {
        "slackApi": {
          "id": "VLK4L2mMCF7UFZXF",
          "name": "Slack account 4"
        }
      },
      "notesInFlow": false,
      "typeVersion": 1
    },
    {
      "id": "df8d6f3e-4f5c-4c58-8967-87180c27c8b5",
      "name": "检查文件格式",
      "type": "n8n-nodes-base.switch",
      "position": [
        -400,
        16
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "PDF",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "3540ad45-eb8f-47c8-9942-c1670ec8acc0",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.files[0].filetype }}",
                    "rightValue": "pdf"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "WORD",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "659d35f5-0ae3-4a75-9744-8a776a6b0391",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.files[0].filetype }}",
                    "rightValue": "docx"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Others",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "1d14871d-5607-4315-b9c8-01eeacf2f916",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "6a259139-f6be-42f0-9018-8e3466a28742",
      "name": "下载 PDF",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -48,
        -160
      ],
      "parameters": {
        "url": "={{ $json.files[0].url_private_download }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        },
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "slackApi"
      },
      "credentials": {
        "slackApi": {
          "id": "gLK2woy6bUlX7kdV",
          "name": "Slack account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "0407b590-908d-4d11-8fbb-6ff8a8e93a30",
      "name": "从 PDF 提取文本",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        176,
        -160
      ],
      "parameters": {
        "options": {},
        "operation": "pdf",
        "binaryPropertyName": "=data"
      },
      "typeVersion": 1
    },
    {
      "id": "71b2b5e9-ea55-4985-8c56-561b14fb02df",
      "name": "将 Word 转换为 PDF",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -48,
        32
      ],
      "parameters": {
        "url": "={{ $json.files[0].converted_pdf }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        },
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "slackApi"
      },
      "credentials": {
        "slackApi": {
          "id": "gLK2woy6bUlX7kdV",
          "name": "Slack account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ab96f6e9-eb93-4b16-ae44-85eb8f3e0c77",
      "name": "从 PDF1 提取文本",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        176,
        32
      ],
      "parameters": {
        "options": {},
        "operation": "pdf",
        "binaryPropertyName": "=data"
      },
      "typeVersion": 1
    },
    {
      "id": "0050c560-3da1-4ad1-ae77-933bf857c780",
      "name": "发送错误消息",
      "type": "n8n-nodes-base.slack",
      "position": [
        -48,
        176
      ],
      "webhookId": "97cb885e-d1af-4a93-8e27-a4bf6000ca99",
      "parameters": {
        "text": "=Only PDF or Word format contracts can be uploaded.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09EG2EN9AA",
          "cachedResultName": "contract"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "id": "VLK4L2mMCF7UFZXF",
          "name": "Slack account 4"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "ca620d80-1959-4d72-95a1-2df99125b248",
      "name": "分析合同内容",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        400,
        -64
      ],
      "parameters": {
        "text": "=please read and understand the input data({{ $json.text }}). I would like you to extract Client, Service Provider, Effective Date, Expiration Date, Signature Date and Contract Value. ",
        "options": {
          "systemMessage": ""
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "ff81dc90-bc72-4b4f-9751-432399ddfedf",
      "name": "保存到 Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        752,
        -64
      ],
      "parameters": {
        "columns": {
          "value": {
            "Client": "={{ $json.output[0].Client }}",
            "Contract Value": "={{ $json.output[0]['Contract Value'] }}",
            "Effective Date": "={{ $json.output[0]['Effective Date'] }}",
            "Signature Date": "={{ $json.output[0]['Signature Date'] }}",
            "Expiration Date": "={{ $json.output[0]['Expiration Date'] }}",
            "Service Provider": "={{ $json.output[0]['Service Provider'] }}"
          },
          "schema": [
            {
              "id": "Client",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Client",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Service Provider",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Service Provider",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Effective Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Effective Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Expiration Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Expiration Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Signature Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Signature Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Contract Value",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Contract Value",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ggkr6gOWmzcIbqBVuh-HVkKVvBaFj-WuYsprlMPMfOk/edit#gid=0",
          "cachedResultName": "sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1ggkr6gOWmzcIbqBVuh-HVkKVvBaFj-WuYsprlMPMfOk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ggkr6gOWmzcIbqBVuh-HVkKVvBaFj-WuYsprlMPMfOk/edit?usp=drivesdk",
          "cachedResultName": "contract_management_sheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "OADOUEa3B96W0iqk",
          "name": "Google Sheets account 2"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "1b8f9d44-5c0a-4eb9-aace-509fec6337fc",
      "name": "在 Slack 上通知",
      "type": "n8n-nodes-base.slack",
      "position": [
        976,
        -64
      ],
      "webhookId": "d443ab23-594e-48f7-bf05-b85e81c967f7",
      "parameters": {
        "text": "=---\nClient: {{ $json.Client }}\nService Provider: {{ $json['Service Provider'] }}\nExpiration Date: {{ $json['Expiration Date'] }}\nEffective Date: {{ $json['Effective Date'] }}\nSignature Date: {{ $json['Signature Date'] }}\nContract Value: {{ $json['Contract Value'] }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09EG2EN9AA",
          "cachedResultName": "contract"
        },
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "id": "VLK4L2mMCF7UFZXF",
          "name": "Slack account 4"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "1c065db0-d6b2-40ae-a2e3-5c5581be0db6",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        -240
      ],
      "parameters": {
        "width": 288,
        "height": 480,
        "content": "## 2. 检查文件格式"
      },
      "typeVersion": 1
    },
    {
      "id": "d3422fd9-df2d-48bb-bada-b631843758b4",
      "name": "便签 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -832,
        -240
      ],
      "parameters": {
        "width": 288,
        "height": 480,
        "content": "## 1. 接收合同文件"
      },
      "typeVersion": 1
    },
    {
      "id": "3f441264-8120-43ea-ad29-4e8de52b9b39",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        -240
      ],
      "parameters": {
        "width": 416,
        "height": 576,
        "content": "## 3. 将文件转换为文本"
      },
      "typeVersion": 1
    },
    {
      "id": "f14068f8-e327-4bcd-8c72-d684faba5dd4",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        -240
      ],
      "parameters": {
        "width": 304,
        "height": 576,
        "content": "## 4. 分析合同内容"
      },
      "typeVersion": 1
    },
    {
      "id": "b38f1853-a844-43ae-92fb-c4169a495541",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        688,
        -240
      ],
      "parameters": {
        "width": 224,
        "height": 368,
        "content": "## 5. 保存到 Google Sheets"
      },
      "typeVersion": 1
    },
    {
      "id": "d55089f4-7887-4875-852c-e740db02344c",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        928,
        -240
      ],
      "parameters": {
        "width": 256,
        "height": 368,
        "content": "## 6. 在 Slack 上通知"
      },
      "typeVersion": 1
    },
    {
      "id": "013d03b1-ebc7-41cf-973b-49fb6968f7eb",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1456,
        -496
      ],
      "parameters": {
        "width": 576,
        "height": 1392,
        "content": "## 使用 Slack、GPT-4o 和 Google Sheets 提取和管理合同。"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "AI model": {
      "ai_languageModel": [
        [
          {
            "node": "Analyze Contract Content",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Download PDF": {
      "main": [
        [
          {
            "node": "Extract Text from PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify on Slack": {
      "main": [
        []
      ]
    },
    "Structure Output": {
      "ai_outputParser": [
        [
          {
            "node": "Analyze Contract Content",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Check File Format": {
      "main": [
        [
          {
            "node": "Download PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Convert Word to PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Error Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Error Message": {
      "main": [
        []
      ]
    },
    "Convert Word to PDF": {
      "main": [
        [
          {
            "node": "Extract Text from PDF1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text from PDF": {
      "main": [
        [
          {
            "node": "Analyze Contract Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Contract File": {
      "main": [
        [
          {
            "node": "Check File Format",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Google Sheets": {
      "main": [
        [
          {
            "node": "Notify on Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text from PDF1": {
      "main": [
        [
          {
            "node": "Analyze Contract Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Contract Content": {
      "main": [
        [
          {
            "node": "Save to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 文档提取, AI 摘要总结, 多模态 AI

需要付费吗?

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

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

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

作者
Toshiki Hirao

Toshiki Hirao

@hirao

dTosh Inc., CEO Nara Institute of Science and Technology, Assistant Professor

外部链接
在 n8n.io 查看

分享此工作流