8
n8n 中文网amn8n.com

使用 Azure GPT-4.1 和人工验证自动处理 Gmail 中的发票

高级

这是一个Invoice Processing, AI Summarization领域的自动化工作流,包含 17 个节点。主要使用 If, Gmail, Merge, GmailTrigger, StopAndError 等节点。 通过 Azure GPT-4.1 和人工验证实现 Gmail 发票处理的自动化

前置要求
  • Google 账号和 Gmail API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "zZWPMtZ0TNebe1fI",
  "meta": {
    "instanceId": "9d85a8cf5ffde86dc8ca46087fd639ee7966eec2fa01c3b00004cfc2bd9c91b0"
  },
  "name": "使用 Azure GPT-4.1 和人工验证自动处理 Gmail 中的发票",
  "tags": [],
  "nodes": [
    {
      "id": "a6fd1034-16ac-48ce-a20e-5d00f9709d76",
      "name": "Gmail 触发器",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        40,
        220
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "sender": "youremail@gmail.com"
        },
        "options": {
          "downloadAttachments": true
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "T2T44GgzbxyaFB0y",
          "name": "Gmail account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b4829627-2c3e-477c-8ff0-9754f0010826",
      "name": "IF:AI 回答是",
      "type": "n8n-nodes-base.if",
      "position": [
        1020,
        260
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.output[0].insights[0].body }}",
              "value2": "Yes",
              "operation": "contains"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "14933a59-1cd2-4572-aa92-8968ffa03b8a",
      "name": "本地保存 PDF",
      "type": "n8n-nodes-base.writeBinaryFile",
      "position": [
        1640,
        220
      ],
      "parameters": {
        "options": {},
        "fileName": "=C:/Test/Invoices/invoice_{{ $now.toFormat('yyyyLLdd_HHmmss') }}.pdf",
        "dataPropertyName": "attachment_0"
      },
      "typeVersion": 1
    },
    {
      "id": "0a17eed9-be81-4576-b218-ad12b3ffac28",
      "name": "合并",
      "type": "n8n-nodes-base.merge",
      "position": [
        1480,
        220
      ],
      "parameters": {
        "mode": "chooseBranch"
      },
      "retryOnFail": false,
      "typeVersion": 3.2
    },
    {
      "id": "e577ce73-0505-45f0-80cb-aa6d241f1add",
      "name": "信息提取器",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "onError": "continueErrorOutput",
      "position": [
        660,
        280
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemPromptTemplate": "You are an expert reviewing invoices. Analyze the texts and say if it is an invoice. Just answer 'Yes' or 'No'"
        },
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"array\",\n  \"items\": {\n    \"type\": \"object\",\n     \"properties\": {\n       \"topic\": { \"type\": \"string\" },\n       \"insights\": {\n         \"type\": \"array\",\n         \"items\": {\n           \"type\": \"object\",\n           \"properties\": {\n             \"title\": { \"type\": \"string\" },\n             \"body\": { \"type\": \"string\" }\n           }\n         }\n       }\n     }\n  }\n}"
      },
      "typeVersion": 1.2,
      "alwaysOutputData": true
    },
    {
      "id": "861f5008-bd46-4091-b040-b7b2fe1e6f45",
      "name": "这是 PDF 文件吗?",
      "type": "n8n-nodes-base.if",
      "position": [
        260,
        220
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.subject }}",
              "value2": "Invoice",
              "operation": "contains"
            },
            {
              "value1": "={{ $binary.attachment_0 }}",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "e23bf999-1718-4489-a308-e244b22e14ad",
      "name": "发送消息",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1020,
        480
      ],
      "webhookId": "aaafea40-4fcd-4775-82bf-5302914a681b",
      "parameters": {
        "sendTo": "receiver@gmail.com",
        "message": "I had trouble parsing the recent invoice. Can you please confirm that it is an invoice?",
        "options": {
          "appendAttribution": false
        },
        "subject": "Approval Required!",
        "operation": "sendAndWait",
        "approvalOptions": {
          "values": {
            "approvalType": "double"
          }
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "T2T44GgzbxyaFB0y",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "bc2a8732-2e5f-421b-8df1-37a6ec2f7a2e",
      "name": "发票保存成功消息",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1800,
        220
      ],
      "webhookId": "aaafea40-4fcd-4775-82bf-5302914a681b",
      "parameters": {
        "sendTo": "receiver@gmail.com",
        "message": "=Hi there,\nInvoice '{{ $json.subject }}' from \"{{ $json.from.value[0].name }}\" has been saved successfully in your Local Folder!\n\n",
        "options": {
          "appendAttribution": false
        },
        "subject": "=Invoice Downloaded"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "T2T44GgzbxyaFB0y",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "c9155103-6c04-438a-8e90-edb63b9ffd1a",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        120
      ],
      "parameters": {
        "color": 7,
        "width": 200,
        "height": 300,
        "content": "当收到来自特定邮箱的新邮件时触发 Gmail"
      },
      "typeVersion": 1
    },
    {
      "id": "a7a4385d-f00e-493c-9757-fbd660a64354",
      "name": "便签 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        220,
        120
      ],
      "parameters": {
        "color": 7,
        "width": 180,
        "height": 300,
        "content": "检查邮件中是否有 PDF 附件,且主题包含\"发票\""
      },
      "typeVersion": 1
    },
    {
      "id": "da0c4d5e-9c24-4f3d-a17a-ca92d3299729",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 180,
        "height": 600,
        "content": "如果两者都为真,则从 PDF 中提取信息"
      },
      "typeVersion": 1
    },
    {
      "id": "2196f52f-9e5b-4acd-b173-86ff7e986b71",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        620,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 780,
        "height": 660,
        "content": "此节点检查从 PDF 提取的信息并分析是否为发票"
      },
      "typeVersion": 1
    },
    {
      "id": "ba5b7574-a2e1-401e-aab0-c7ca6b7856d8",
      "name": "Azure OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        660,
        440
      ],
      "parameters": {
        "model": "gpt-4.1",
        "options": {}
      },
      "credentials": {
        "azureOpenAiApi": {
          "id": "QvYBe8DtpxGloSPZ",
          "name": "Azure Open AI account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "42973f72-4ce9-4fff-90e5-9a09cc68f39b",
      "name": "人工验证",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1200,
        340
      ],
      "webhookId": "69f41f8b-bad8-4fe6-83db-b46e64f10e7f",
      "parameters": {
        "sendTo": "receiveremail@gmail.com",
        "message": "The latest invoice does not seem to be legit. Please verify it manually.",
        "options": {
          "appendAttribution": false
        },
        "subject": "Manual Verification Required"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "T2T44GgzbxyaFB0y",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "f1d15106-d677-4484-8602-7091c87be5c7",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1420,
        120
      ],
      "parameters": {
        "color": 7,
        "width": 560,
        "height": 300,
        "content": "确认文件为发票后,将其保存到本地目录。工作流完成后,向用户发送成功邮件"
      },
      "typeVersion": 1
    },
    {
      "id": "f589f451-3faf-4930-ab12-4796f219d066",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 400,
        "height": 100,
        "content": "## 使用此工作流自动保存邮件中收到的发票"
      },
      "typeVersion": 1
    },
    {
      "id": "3b021445-e52e-4191-a454-654ba26e1bba",
      "name": "错误处理器",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        460,
        440
      ],
      "parameters": {
        "errorMessage": "There is no pdf file!"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a74dc17a-a9fe-448e-a457-4b267ce63830",
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Save PDF Locally",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is this PDF?": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          },
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Handler",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Is this PDF?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF: AI Says Yes": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ],
        [
          {
            "node": "Manual Verification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save PDF Locally": {
      "main": [
        [
          {
            "node": "Invoice Saved Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Information Extractor": {
      "main": [
        [
          {
            "node": "IF: AI Says Yes",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Azure OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 发票处理, AI 摘要总结

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流