自动向客户发送发票
高级
这是一个AI Summarization, Multimodal AI领域的自动化工作流,包含 29 个节点。主要使用 If, Set, Code, Gmail, Merge 等节点。 通过 OCR.Space、GPT-4 和 Google Drive 到 Gmail 实现发票处理的自动化
前置要求
- •Google 账号和 Gmail API 凭证
- •Google Drive API 凭证
- •可能需要目标 API 的认证凭证
- •Google Sheets API 凭证
- •OpenAI API Key
使用的节点 (29)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "Invzq7tJ1X0LQ3rb",
"meta": {
"instanceId": "00761fd5aea81495387b0889e15912dcc912b73b7bf62f5ca3898afbd7a79723",
"templateCredsSetupCompleted": true
},
"name": "自动向客户发送发票",
"tags": [
{
"id": "j0SNhalFSbPAhdWo",
"name": "n8n creator",
"createdAt": "2025-09-02T01:40:23.866Z",
"updatedAt": "2025-09-02T01:40:23.866Z"
}
],
"nodes": [
{
"id": "43908db1-0163-41c4-8c0b-a127e575c058",
"name": "合并",
"type": "n8n-nodes-base.merge",
"position": [
-688,
144
],
"parameters": {
"mode": "combine",
"options": {},
"combineBy": "combineByPosition"
},
"typeVersion": 3
},
{
"id": "e10c62a4-8c0c-49e6-9672-68a0aee51b5a",
"name": "遍历项目",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-2320,
464
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "5a37b5e5-40e8-4888-ac24-66367e65969a",
"name": "HTTP 请求",
"type": "n8n-nodes-base.httpRequest",
"position": [
-1744,
464
],
"parameters": {
"url": "https://api.ocr.space/parse/image",
"method": "POST",
"options": {},
"sendBody": true,
"contentType": "multipart-form-data",
"authentication": "genericCredentialType",
"bodyParameters": {
"parameters": [
{
"name": "language",
"value": "eng"
},
{
"name": "file",
"parameterType": "formBinaryData",
"inputDataFieldName": "data"
}
]
},
"genericAuthType": "httpHeaderAuth"
},
"credentials": {
"httpHeaderAuth": {
"id": "qh2jhNdxpHOM9SGZ",
"name": "PiAPI"
}
},
"typeVersion": 4.2
},
{
"id": "9e72ec12-aba0-474e-97f3-7d7958905e70",
"name": "Google Drive",
"type": "n8n-nodes-base.googleDrive",
"position": [
-2016,
464
],
"parameters": {
"fileId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Google Drive Trigger').item.json.id }}"
},
"options": {},
"operation": "download"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "KZY6CHPvoIbIxMKd",
"name": "Google Drive account"
}
},
"typeVersion": 3
},
{
"id": "73e4f62d-80c4-483f-8c00-f5fc7c8b9882",
"name": "Google Sheets",
"type": "n8n-nodes-base.googleSheetsTool",
"position": [
-1024,
688
],
"parameters": {
"options": {},
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1UDlHvLgcZn714etZxtgm7bJCATvDcutVyugrvqM2kaM/edit#gid=0",
"cachedResultName": "Feuille 1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1UDlHvLgcZn714etZxtgm7bJCATvDcutVyugrvqM2kaM",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1UDlHvLgcZn714etZxtgm7bJCATvDcutVyugrvqM2kaM/edit?usp=drivesdk",
"cachedResultName": "list of company names and emails"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "6UWtW8DQlbmfYbkk",
"name": "Google Sheets account"
}
},
"typeVersion": 4.5
},
{
"id": "550dbd6b-b691-43eb-afbd-b3a16a7f59d0",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-1120,
864
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "QsPyEUltWeliSiFb",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "ebb1c8f5-cbf0-4d00-b171-1f6040c38300",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"onError": "continueRegularOutput",
"position": [
-1088,
480
],
"parameters": {
"text": "={{ $json.company }}",
"options": {
"systemMessage": "=You will receive a company name as plain text.\n\nYour task is to:\n\t1.\tCross-reference the given name against a Google Sheet database.\n\t2.\tThe database contains two columns: Company Name and Email.\n\t3.\tPerform a case-insensitive search to find an exact match for the company name.\n\t4.\tIf a match is found, return a JSON object \n{\n \"company_name\": \"Matched Company Name\",\n \"email\": \"matched@email.com\"\n}\n\n5. If no match is found, return a JSON object with an error message:\n{\n \"error\": \"Company not found in the database.\"\n}",
"returnIntermediateSteps": false
},
"promptType": "define",
"hasOutputParser": true
},
"retryOnFail": true,
"typeVersion": 1.7,
"waitBetweenTries": 5000
},
{
"id": "dd8d6365-6a12-4150-82d3-a3ee0bbb74d5",
"name": "编辑字段",
"type": "n8n-nodes-base.set",
"position": [
-1536,
464
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "32dbf33f-9c71-4d84-ab7c-cdb1df189210",
"name": "text",
"type": "string",
"value": "={{ $json.ParsedResults[0].ParsedText}}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "a901f0d8-f5a5-4d01-9e86-73980cd74e47",
"name": "代码",
"type": "n8n-nodes-base.code",
"onError": "continueErrorOutput",
"position": [
-1328,
464
],
"parameters": {
"jsCode": "const inputText = $json[\"text\"];\nconst lines = inputText.split(/\\r?\\n/);\n\nlet factureIndex = lines.findIndex(line => line.toLowerCase().includes(\"billed to\"));\nlet name = null;\n\nif (factureIndex >= 0) {\n const lineAfter = lines[factureIndex + 1]?.trim();\n const nextLine = lines[factureIndex + 2]?.trim();\n\n const isProbablyName = (line) => (\n /[a-z]/.test(line) && // has lowercase\n line.length >= 5 && // not too short\n line !== line.toUpperCase() // not all uppercase\n );\n\n if (isProbablyName(lineAfter)) {\n name = lineAfter;\n } else if (isProbablyName(nextLine)) {\n name = nextLine;\n }\n}\n\nif (!name) {\n throw new Error(\"No company name found after 'Billed to'\");\n}\n\nreturn [{ company: name }];"
},
"typeVersion": 2
},
{
"id": "a7ad5822-78d6-48cb-b9d8-b60017a52a30",
"name": "无操作,不执行任何操作",
"type": "n8n-nodes-base.noOp",
"position": [
-2016,
128
],
"parameters": {},
"typeVersion": 1
},
{
"id": "999cb1c3-3ce1-44b1-bcdd-b6a7399e903a",
"name": "合并1",
"type": "n8n-nodes-base.merge",
"position": [
-1504,
816
],
"parameters": {
"mode": "combine",
"options": {},
"combineBy": "combineByPosition"
},
"typeVersion": 3
},
{
"id": "944af94f-6a2a-4cd2-9334-5548e8645303",
"name": "无操作,不执行任何操作1",
"type": "n8n-nodes-base.noOp",
"position": [
-1728,
128
],
"parameters": {},
"typeVersion": 1
},
{
"id": "14ea1466-6532-42f8-a717-c716a92647dd",
"name": "错误",
"type": "n8n-nodes-base.gmail",
"position": [
-512,
816
],
"webhookId": "7c52b689-dd98-44dd-969d-6c8d45d975bb",
"parameters": {
"sendTo": "Email Here",
"message": "The error in the workflow pertains to the attached document. Please check if it has not been sent and manually send it. Also check the database to make sure the name of the corresponding company is in the database. ",
"options": {
"attachmentsUi": {
"attachmentsBinary": [
{}
]
},
"appendAttribution": false
},
"subject": "Error in Workflow",
"emailType": "text"
},
"credentials": {
"gmailOAuth2": {
"id": "aMOyqTwb2YTJyW5F",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "28926b1c-ce6a-4d1d-a42e-199d11d302f7",
"name": "发送邮件",
"type": "n8n-nodes-base.gmail",
"position": [
-160,
816
],
"webhookId": "7c52b689-dd98-44dd-969d-6c8d45d975bb",
"parameters": {
"sendTo": "Email Here",
"message": "The error in the workflow pertains to the attached document. Please check if it has not been sent and manually send it. Also check the database to make sure the name of the corresponding company is in the database. ",
"options": {
"attachmentsUi": {
"attachmentsBinary": [
{}
]
},
"appendAttribution": false
},
"subject": "Error in Workflow",
"emailType": "text"
},
"credentials": {
"gmailOAuth2": {
"id": "aMOyqTwb2YTJyW5F",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "b0fcd4e0-2875-419e-b3e8-23082150e0a0",
"name": "错误1",
"type": "n8n-nodes-base.gmail",
"position": [
-1328,
816
],
"webhookId": "5ae6fbe2-35d9-4482-9ca9-9d579460f356",
"parameters": {
"sendTo": "Email Here",
"message": "The error in the workflow pertains to the attached document. Please check if it has not been sent and manually send it. Also check the database to make sure the name of the corresponding company is in the database. ",
"options": {},
"subject": "Error in workflow",
"emailType": "text"
},
"credentials": {
"gmailOAuth2": {
"id": "aMOyqTwb2YTJyW5F",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "00a3bd30-62c6-40e5-ad29-89f9ec811aa5",
"name": "条件判断",
"type": "n8n-nodes-base.if",
"position": [
-512,
144
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "dcfbe432-fc35-438e-8e4b-4fa109107376",
"operator": {
"type": "object",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $('AI Agent').item.json.output }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "5b9ce018-3103-4c30-ab83-bdb440eb9ae1",
"name": "结构化输出解析器1",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
-896,
704
],
"parameters": {
"autoFix": true,
"jsonSchemaExample": "{\n\t\"email\":\"email of recipient\",\n \"name\":\"name of recipient\"\n}"
},
"typeVersion": 1.3
},
{
"id": "c34d9478-0acb-492b-807e-a57bfb269a23",
"name": "便签说明1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2608,
272
],
"parameters": {
"width": 176,
"height": 352,
"content": "### 这里我们设置一个 Google Drive 文件夹,当有任何发票添加时,自动化流程将自动触发"
},
"typeVersion": 1
},
{
"id": "8f83d6d0-bc12-4cd9-9a3c-cc291400016a",
"name": "便签说明2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2352,
272
],
"parameters": {
"width": 160,
"height": 352,
"content": "### 这里我们对项目进行循环处理,因为文件夹中可能放置了多张发票"
},
"typeVersion": 1
},
{
"id": "4e45b1c4-0051-4cb9-bee7-a19819da906d",
"name": "便签说明3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2048,
272
],
"parameters": {
"width": 150,
"height": 352,
"content": "### 这里我们下载发票,将其传递给 OCR space 进行光学字符识别"
},
"typeVersion": 1
},
{
"id": "47c4d010-9870-4514-8879-a6a37c174663",
"name": "便签说明4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-3760,
80
],
"parameters": {
"width": 1056,
"height": 1232,
"content": "# 设置工作流"
},
"typeVersion": 1
},
{
"id": "ae882eb4-d4a9-4ffa-a49f-95e4d78b5cd8",
"name": "便签说明5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1776,
272
],
"parameters": {
"width": 150,
"height": 352,
"content": "### 这里我们将下载的文件发送到 OCR space,并从发票中获取提取的信息"
},
"typeVersion": 1
},
{
"id": "2948912f-1bd6-42a9-a630-e3e24a00a45a",
"name": "便签 6",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1568,
272
],
"parameters": {
"width": 150,
"height": 352,
"content": "### 为文本分配名称"
},
"typeVersion": 1
},
{
"id": "518d1756-b601-4c9c-8b87-c5fc2d601370",
"name": "便签 7",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1360,
272
],
"parameters": {
"width": 150,
"height": 352,
"content": "### 提取公司名称。在此情况下,在\"开票给:\"之后"
},
"typeVersion": 1
},
{
"id": "c7f521dd-dc76-4be8-92db-b3de9bf2946e",
"name": "便签8",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1120,
272
],
"parameters": {
"width": 320,
"height": 352,
"content": "### AI Agent 将名称与数据库进行交叉引用,并返回收件人的电子邮件地址"
},
"typeVersion": 1
},
{
"id": "337d3670-0c2e-4507-8c75-eb235286e97c",
"name": "便签 9",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1360,
688
],
"parameters": {
"width": 160,
"height": 272,
"content": "### 如果有任何错误,我们会向操作员发送电子邮件进行手动审核"
},
"typeVersion": 1
},
{
"id": "e8c25552-0d00-4285-858f-cc30348f33d3",
"name": "便签10",
"type": "n8n-nodes-base.stickyNote",
"position": [
-544,
672
],
"parameters": {
"width": 160,
"height": 256,
"content": "### 如果有任何错误,我们会向操作员发送电子邮件进行手动审核"
},
"typeVersion": 1
},
{
"id": "95716bac-97bd-4e1f-b7e6-9478cdf151dd",
"name": "便签11",
"type": "n8n-nodes-base.stickyNote",
"position": [
-192,
672
],
"parameters": {
"width": 150,
"height": 256,
"content": "### 向收件人发送带有发票附件的电子邮件"
},
"typeVersion": 1
},
{
"id": "46d6e0ac-7555-48a8-b57d-e97a42bec8b0",
"name": "Google Drive 触发器1",
"type": "n8n-nodes-base.googleDriveTrigger",
"position": [
-2576,
464
],
"parameters": {
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"triggerOn": "specificFolder",
"folderToWatch": {
"__rl": true,
"mode": "list",
"value": ""
}
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "KZY6CHPvoIbIxMKd",
"name": "Google Drive account"
}
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "1fb1901c-362e-41f9-8f14-2ac208b59826",
"connections": {
"If": {
"main": [
[
{
"node": "Send Email",
"type": "main",
"index": 0
}
],
[
{
"node": "Error",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
],
[
{
"node": "Merge1",
"type": "main",
"index": 0
}
]
]
},
"Error": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Merge": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"Error1": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Merge1": {
"main": [
[
{
"node": "Error1",
"type": "main",
"index": 0
}
]
]
},
"AI Agent": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 1
}
],
[]
]
},
"Send Email": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Google Drive": {
"main": [
[
{
"node": "HTTP Request1",
"type": "main",
"index": 0
},
{
"node": "Merge1",
"type": "main",
"index": 1
},
{
"node": "No Operation, do nothing1",
"type": "main",
"index": 0
}
]
]
},
"Google Sheets": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"HTTP Request1": {
"main": [
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
],
[
{
"node": "Google Drive",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
},
{
"node": "Structured Output Parser1",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Google Drive Trigger1": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"No Operation, do nothing1": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser1": {
"ai_outputParser": [
[
{
"node": "AI Agent",
"type": "ai_outputParser",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - AI 摘要总结, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
上下文混合RAG AI文案
Google Drive到Supabase上下文向量数据库同步用于RAG应用
If
Set
Code
+25
76 节点Michael Taleb
AI RAG 检索增强
在可视化参考库中探索n8n节点
在可视化参考库中探索n8n节点
If
Ftp
Set
+93
113 节点I versus AI
其他
宠物店 4
🐶 宠物店预约 AI 代理
If
Set
Code
+41
187 节点Bruno Dias
人工智能
HR候选人解析与评估 - 使用GPT-4.1和LinkedIn数据的CSV/XLSX
HR候选人解析与评估 - 使用GPT-4.1和LinkedIn数据的CSV/XLSX
Set
Code
Gmail
+15
33 节点Elay Guez
内容创作
每日 WhatsApp 群组智能分析:GPT-4.1 分析与语音消息转录
每日 WhatsApp 群组智能分析:GPT-4.1 分析与语音消息转录
If
Set
Code
+20
52 节点Daniel Lianes
杂项
交付汉堡店MVP
🤖 餐厅与配送自动化的 AI 驱动 WhatsApp 助手
If
Set
Code
+37
152 节点Bruno Dias
工作流信息
难度等级
高级
节点数量29
分类2
节点类型15
作者
Michael Taleb
@michaeltalebn8n developer helping businesses save time and scale by automating complex business processes with n8n and smart integrations.
外部链接
在 n8n.io 查看 →
分享此工作流