通过 OCR.Space、GPT-4 和 Google Drive 到 Gmail
高级
这是一个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": "Send Invoice to clients automatically",
"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": "Merge",
"type": "n8n-nodes-base.merge",
"position": [
-688,
144
],
"parameters": {
"mode": "combine",
"options": {},
"combineBy": "combineByPosition"
},
"typeVersion": 3
},
{
"id": "e10c62a4-8c0c-49e6-9672-68a0aee51b5a",
"name": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-2320,
464
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "5a37b5e5-40e8-4888-ac24-66367e65969a",
"name": "HTTP Request1",
"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 Chat Model",
"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": "Edit Fields",
"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": "Code",
"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": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"position": [
-2016,
128
],
"parameters": {},
"typeVersion": 1
},
{
"id": "999cb1c3-3ce1-44b1-bcdd-b6a7399e903a",
"name": "Merge1",
"type": "n8n-nodes-base.merge",
"position": [
-1504,
816
],
"parameters": {
"mode": "combine",
"options": {},
"combineBy": "combineByPosition"
},
"typeVersion": 3
},
{
"id": "944af94f-6a2a-4cd2-9334-5548e8645303",
"name": "No Operation, do nothing1",
"type": "n8n-nodes-base.noOp",
"position": [
-1728,
128
],
"parameters": {},
"typeVersion": 1
},
{
"id": "14ea1466-6532-42f8-a717-c716a92647dd",
"name": "Error",
"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": "Send Email",
"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": "Error1",
"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": "If",
"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": "Structured Output Parser1",
"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": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2608,
272
],
"parameters": {
"width": 176,
"height": 352,
"content": "### Here we set a google drive folder, where any time an invoice is added, the automation will be triggered automatically"
},
"typeVersion": 1
},
{
"id": "8f83d6d0-bc12-4cd9-9a3c-cc291400016a",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2352,
272
],
"parameters": {
"width": 160,
"height": 352,
"content": "### Here we loop over the items, because we may have more than 1 invoice placed in the folder"
},
"typeVersion": 1
},
{
"id": "4e45b1c4-0051-4cb9-bee7-a19819da906d",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2048,
272
],
"parameters": {
"width": 150,
"height": 352,
"content": "### Here we download the invoice to pass it on to the OCR from ocr space"
},
"typeVersion": 1
},
{
"id": "47c4d010-9870-4514-8879-a6a37c174663",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-3760,
80
],
"parameters": {
"width": 1056,
"height": 1232,
"content": "# Setting up the workflow\n\n## 1. Connect google drive to your account, and create a folder that will serve as the input. \n\n## 2. Connect your Gmail account to n8n. \n\n## 3. Create an OCR space account (free). For the authentication, choose Generic Credential Type, then Header Auth. In the Header Auth, create new credential, with the Name as apikey and the Value as YOUR-API-KEY\n\n## 4. Connect your preferred LLM credentials, and connect it to the AI Agent\n\n## 5. Create a copy of the Google Sheet Database, fill it with your list and connect it to the AI Agent\n\n# OCR Space: https://ocr.space\n\n# Google Sheet Database: https://docs.google.com/spreadsheets/d/1M0sS7KZzOn9Bu8Dy0lcrh2jWqVkLa0qFQfki1jecxeE/edit?usp=sharing (Make a copy)\n\n# Workflow Summary: This workflow takes in from a google drive folder, scanned pdf invoices. The workflow then extracts the text from the file using OCR space. Once the text is returned, the AI agent cross references the company name, with the database (excel sheet) to find the company name and the email of the recipient in the company. If it is found the email is sent with the invoice attached. "
},
"typeVersion": 1
},
{
"id": "ae882eb4-d4a9-4ffa-a49f-95e4d78b5cd8",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1776,
272
],
"parameters": {
"width": 150,
"height": 352,
"content": "### Here we are sending the downloaded file to OCR space, and getting the extracted information from the invoice"
},
"typeVersion": 1
},
{
"id": "2948912f-1bd6-42a9-a630-e3e24a00a45a",
"name": "Sticky Note6",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1568,
272
],
"parameters": {
"width": 150,
"height": 352,
"content": "### Assigning name to the text. "
},
"typeVersion": 1
},
{
"id": "518d1756-b601-4c9c-8b87-c5fc2d601370",
"name": "Sticky Note7",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1360,
272
],
"parameters": {
"width": 150,
"height": 352,
"content": "### Extracting company name. In this case after the billed to:"
},
"typeVersion": 1
},
{
"id": "c7f521dd-dc76-4be8-92db-b3de9bf2946e",
"name": "Sticky Note8",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1120,
272
],
"parameters": {
"width": 320,
"height": 352,
"content": "### AI Agent cross references name with Database and returns the recipients email address"
},
"typeVersion": 1
},
{
"id": "337d3670-0c2e-4507-8c75-eb235286e97c",
"name": "Sticky Note9",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1360,
688
],
"parameters": {
"width": 160,
"height": 272,
"content": "### If we have any errors, we send an email to the operator for manual review"
},
"typeVersion": 1
},
{
"id": "e8c25552-0d00-4285-858f-cc30348f33d3",
"name": "Sticky Note10",
"type": "n8n-nodes-base.stickyNote",
"position": [
-544,
672
],
"parameters": {
"width": 160,
"height": 256,
"content": "### If we have any errors, we send an email to the operator for manual review"
},
"typeVersion": 1
},
{
"id": "95716bac-97bd-4e1f-b7e6-9478cdf151dd",
"name": "Sticky Note11",
"type": "n8n-nodes-base.stickyNote",
"position": [
-192,
672
],
"parameters": {
"width": 150,
"height": 256,
"content": "### Send email to recipient with the invoice attached"
},
"typeVersion": 1
},
{
"id": "46d6e0ac-7555-48a8-b57d-e97a42bec8b0",
"name": "Google Drive Trigger1",
"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": {
"00a3bd30-62c6-40e5-ad29-89f9ec811aa5": {
"main": [
[
{
"node": "28926b1c-ce6a-4d1d-a42e-199d11d302f7",
"type": "main",
"index": 0
}
],
[
{
"node": "14ea1466-6532-42f8-a717-c716a92647dd",
"type": "main",
"index": 0
}
]
]
},
"a901f0d8-f5a5-4d01-9e86-73980cd74e47": {
"main": [
[
{
"node": "ebb1c8f5-cbf0-4d00-b171-1f6040c38300",
"type": "main",
"index": 0
}
],
[
{
"node": "999cb1c3-3ce1-44b1-bcdd-b6a7399e903a",
"type": "main",
"index": 0
}
]
]
},
"14ea1466-6532-42f8-a717-c716a92647dd": {
"main": [
[
{
"node": "e10c62a4-8c0c-49e6-9672-68a0aee51b5a",
"type": "main",
"index": 0
}
]
]
},
"43908db1-0163-41c4-8c0b-a127e575c058": {
"main": [
[
{
"node": "00a3bd30-62c6-40e5-ad29-89f9ec811aa5",
"type": "main",
"index": 0
}
]
]
},
"b0fcd4e0-2875-419e-b3e8-23082150e0a0": {
"main": [
[
{
"node": "e10c62a4-8c0c-49e6-9672-68a0aee51b5a",
"type": "main",
"index": 0
}
]
]
},
"999cb1c3-3ce1-44b1-bcdd-b6a7399e903a": {
"main": [
[
{
"node": "b0fcd4e0-2875-419e-b3e8-23082150e0a0",
"type": "main",
"index": 0
}
]
]
},
"ebb1c8f5-cbf0-4d00-b171-1f6040c38300": {
"main": [
[
{
"node": "43908db1-0163-41c4-8c0b-a127e575c058",
"type": "main",
"index": 1
}
],
[]
]
},
"28926b1c-ce6a-4d1d-a42e-199d11d302f7": {
"main": [
[
{
"node": "e10c62a4-8c0c-49e6-9672-68a0aee51b5a",
"type": "main",
"index": 0
}
]
]
},
"dd8d6365-6a12-4150-82d3-a3ee0bbb74d5": {
"main": [
[
{
"node": "a901f0d8-f5a5-4d01-9e86-73980cd74e47",
"type": "main",
"index": 0
}
]
]
},
"9e72ec12-aba0-474e-97f3-7d7958905e70": {
"main": [
[
{
"node": "5a37b5e5-40e8-4888-ac24-66367e65969a",
"type": "main",
"index": 0
},
{
"node": "999cb1c3-3ce1-44b1-bcdd-b6a7399e903a",
"type": "main",
"index": 1
},
{
"node": "944af94f-6a2a-4cd2-9334-5548e8645303",
"type": "main",
"index": 0
}
]
]
},
"73e4f62d-80c4-483f-8c00-f5fc7c8b9882": {
"ai_tool": [
[
{
"node": "ebb1c8f5-cbf0-4d00-b171-1f6040c38300",
"type": "ai_tool",
"index": 0
}
]
]
},
"5a37b5e5-40e8-4888-ac24-66367e65969a": {
"main": [
[
{
"node": "dd8d6365-6a12-4150-82d3-a3ee0bbb74d5",
"type": "main",
"index": 0
}
]
]
},
"e10c62a4-8c0c-49e6-9672-68a0aee51b5a": {
"main": [
[
{
"node": "a7ad5822-78d6-48cb-b9d8-b60017a52a30",
"type": "main",
"index": 0
}
],
[
{
"node": "9e72ec12-aba0-474e-97f3-7d7958905e70",
"type": "main",
"index": 0
}
]
]
},
"550dbd6b-b691-43eb-afbd-b3a16a7f59d0": {
"ai_languageModel": [
[
{
"node": "ebb1c8f5-cbf0-4d00-b171-1f6040c38300",
"type": "ai_languageModel",
"index": 0
},
{
"node": "5b9ce018-3103-4c30-ab83-bdb440eb9ae1",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"46d6e0ac-7555-48a8-b57d-e97a42bec8b0": {
"main": [
[
{
"node": "e10c62a4-8c0c-49e6-9672-68a0aee51b5a",
"type": "main",
"index": 0
}
]
]
},
"944af94f-6a2a-4cd2-9334-5548e8645303": {
"main": [
[
{
"node": "43908db1-0163-41c4-8c0b-a127e575c058",
"type": "main",
"index": 0
}
]
]
},
"5b9ce018-3103-4c30-ab83-bdb440eb9ae1": {
"ai_outputParser": [
[
{
"node": "ebb1c8f5-cbf0-4d00-b171-1f6040c38300",
"type": "ai_outputParser",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - AI 摘要总结, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
上下文混合RAG AI文案
Google Drive到Supabase上下文向量数据库同步用于RAG应用
If
Set
Code
+
If
Set
Code
76 节点Michael Taleb
AI RAG 检索增强
在可视化参考库中探索n8n节点
在可视化参考库中探索n8n节点
If
Ftp
Set
+
If
Ftp
Set
113 节点I versus AI
其他
🐶 宠物店预约 AI 代理
🐶 宠物店预约 AI 代理
If
Set
Code
+
If
Set
Code
187 节点Bruno Dias
人工智能
每日 WhatsApp 群组智能分析:GPT-4.1 分析与语音消息转录
每日 WhatsApp 群组智能分析:GPT-4.1 分析与语音消息转录
If
Set
Code
+
If
Set
Code
52 节点Daniel Lianes
杂项
🤖 餐厅与配送自动化的 AI 驱动 WhatsApp 助手
🤖 餐厅与配送自动化的 AI 驱动 WhatsApp 助手
If
Set
Code
+
If
Set
Code
152 节点Bruno Dias
✨🩷自动化社交媒体内容发布工厂 + 系统提示组合
基于动态系统提示和GPT-4o的AI驱动多平台社交媒体内容工厂
If
Set
Code
+
If
Set
Code
100 节点Amit Mehta
内容创作
工作流信息
难度等级
高级
节点数量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 查看 →
分享此工作流