Qualify new leads in Google Sheets via OpenAI's GPT-4
工作流概述
这是一个包含9个节点的复杂工作流,主要用于自动化处理各种任务。
工作流源代码
{
"id": "8FLJK1NsduFL0Y5P",
"meta": {
"instanceId": "fb924c73af8f703905bc09c9ee8076f48c17b596ed05b18c0ff86915ef8a7c4a"
},
"name": "Qualify new leads in Google Sheets via OpenAI's GPT-4",
"tags": [
{
"id": "y9tvM3hISJKT2jeo",
"name": "Ted's Tech Talks",
"createdAt": "2023-08-15T22:12:34.260Z",
"updatedAt": "2023-08-15T22:12:34.260Z"
}
],
"nodes": [
{
"id": "1f179325-0bec-4e5c-8ebd-0a2bb3ebefaa",
"name": "Merge",
"type": "n8n-nodes-base.merge",
"position": [
1440,
340
],
"parameters": {
"mode": "combine",
"options": {},
"combinationMode": "mergeByPosition"
},
"typeVersion": 2.1
},
{
"id": "7b548661-2b32-451f-ba52-91ca86728f1e",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
358,
136.3642172523962
],
"parameters": {
"width": 442,
"height": 360.6357827476038,
"content": "### 1. Create a Google Sheet document
* This template uses Google Sheet document connected to Google Forms, but a standalone Sheet document will work too
* Adapt initial trigger to your needs: check for new entries periodically or add a manual trigger
[Link to the Google Sheet template](https://docs.google.com/spreadsheets/d/1jk8ZbfOMObvHGGImc0sBJTZB_hracO4jRqfbryMgzEs)"
},
"typeVersion": 1
},
{
"id": "308b4dce-4656-47bd-b217-69565b1c34f6",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
820,
420
],
"parameters": {
"width": 471,
"height": 322,
"content": "### 2. Provide lead qualification instructions
* Create a __system message__ with overall instructions
* Add a __user message__ with the JSON variables
* Set node parses the resulting JSON object, but you can also request a plain string response in the system message"
},
"typeVersion": 1
},
{
"id": "c00442ca-98cf-4296-b084-f0881ce4fd39",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1320,
222.18785942492013
],
"parameters": {
"width": 355,
"height": 269.81214057507987,
"content": "### 3. Combine the initial data with GPT response
* This Merge node puts together original records from the google sheet and responses from the OpenAI"
},
"typeVersion": 1
},
{
"id": "62643a4c-a69c-4351-9960-20413285ff33",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1700,
220
],
"parameters": {
"width": 398,
"height": 265,
"content": "### 4. Update the Google Sheet document
* Provide __Column to Match On__ (usually a timestamp in case of Google Forms)
* Enter the result from GPT into a separate column"
},
"typeVersion": 1
},
{
"id": "4cd58340-81c4-46c7-b346-25a9b6ef2910",
"name": "Update lead status",
"type": "n8n-nodes-base.googleSheets",
"position": [
1860,
340
],
"parameters": {
"columns": {
"value": {
"Rating": "={{ $json.reply.rating }}",
"Timestamp": "={{ $json.Timestamp }}"
},
"schema": [
{
"id": "Timestamp",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Timestamp",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Email Address",
"type": "string",
"display": true,
"removed": true,
"required": false,
"displayName": "Email Address",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Your name",
"type": "string",
"display": true,
"removed": true,
"required": false,
"displayName": "Your name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Your business area",
"type": "string",
"display": true,
"removed": true,
"required": false,
"displayName": "Your business area",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Your team size",
"type": "string",
"display": true,
"removed": true,
"required": false,
"displayName": "Your team size",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Rating",
"type": "string",
"display": true,
"required": false,
"displayName": "Rating",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "row_number",
"type": "string",
"display": true,
"removed": true,
"readOnly": true,
"required": false,
"displayName": "row_number",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"Timestamp"
]
},
"options": {},
"operation": "update",
"sheetName": {
"__rl": true,
"mode": "list",
"value": 72739218,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1jk8ZbfOMObvHGGImc0sBJTZB_hracO4jRqfbryMgzEs/edit#gid=72739218",
"cachedResultName": "Form Responses 1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1jk8ZbfOMObvHGGImc0sBJTZB_hracO4jRqfbryMgzEs",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1jk8ZbfOMObvHGGImc0sBJTZB_hracO4jRqfbryMgzEs/edit?usp=drivesdk",
"cachedResultName": "Join Community (Responses)"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "RtRiRezoxiWkzZQt",
"name": "Ted's Tech Talks Google account"
}
},
"typeVersion": 4.2
},
{
"id": "fea0acee-13b6-441a-8cf9-c8fedbc4617d",
"name": "Extract JSON reply",
"type": "n8n-nodes-base.set",
"position": [
1120,
580
],
"parameters": {
"fields": {
"values": [
{
"name": "reply",
"type": "objectValue",
"objectValue": "={{ JSON.parse($json.message.content) }}"
}
]
},
"include": "selected",
"options": {}
},
"typeVersion": 3.2
},
{
"id": "0a0608fe-894f-4eb5-b690-233c6dfc0428",
"name": "Qualify leads with GPT",
"type": "n8n-nodes-base.openAi",
"position": [
900,
580
],
"parameters": {
"prompt": {
"messages": [
{
"role": "system",
"content": "Your task is to qualify incoming leads. Leads are form submissions to a closed community group. Use the following criteria for a quality lead:
1. We are looking for decision makers who run companies or who have some teams. The bigger the team - the better. Basically, everyone with some level of responsibility should be accepted. This is the main criterion.
2. Email from a non-standard domain. Ideally this should be a corporate domain, but this is a secondary criterion.
Please thing step by step whether a lead is quality or not?
If at least one of the criteria satisfy, reply with \"qualified\" in response. Otherwise reply \"not qualified\". Reply with a JSON of the following structure: {\"rating\":\"string\",\"explanation\":\"string\"}. Reply only with with the JSON and nothing more!"
},
{
"content": "=Here's a lead info:
Name: {{ $json['Your name'] }}
Email: {{ $json['Email Address'] }}
Business area: {{ $json['Your business area'] }}
Size of the team: {{ $json['Your team size'] }}"
}
]
},
"options": {
"temperature": 0.3
},
"resource": "chat",
"chatModel": "gpt-4-turbo-preview"
},
"credentials": {
"openAiApi": {
"id": "rveqdSfp7pCRON1T",
"name": "Ted's Tech Talks OpenAi"
}
},
"typeVersion": 1.1
},
{
"id": "22fdec69-a4a9-430d-9950-79195799ae7a",
"name": "Check for new entries",
"type": "n8n-nodes-base.googleSheetsTrigger",
"position": [
520,
340
],
"parameters": {
"event": "rowAdded",
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"sheetName": {
"__rl": true,
"mode": "list",
"value": 72739218,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1jk8ZbfOMObvHGGImc0sBJTZB_hracO4jRqfbryMgzEs/edit#gid=72739218",
"cachedResultName": "Form Responses 1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1jk8ZbfOMObvHGGImc0sBJTZB_hracO4jRqfbryMgzEs",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1jk8ZbfOMObvHGGImc0sBJTZB_hracO4jRqfbryMgzEs/edit?usp=drivesdk",
"cachedResultName": "Join Community (Responses)"
}
},
"credentials": {
"googleSheetsTriggerOAuth2Api": {
"id": "m33qCYf9eEvSgo0x",
"name": "Ted's Tech Talks Google Sheets Trigger"
}
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"callerPolicy": "workflowsFromSameOwner",
"executionOrder": "v1",
"saveManualExecutions": true,
"saveExecutionProgress": true,
"saveDataSuccessExecution": "all"
},
"versionId": "ffad0998-1a6b-469d-9297-6d7fd88387b9",
"connections": {
"Merge": {
"main": [
[
{
"node": "Update lead status",
"type": "main",
"index": 0
}
]
]
},
"Extract JSON reply": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 1
}
]
]
},
"Check for new entries": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 0
},
{
"node": "Qualify leads with GPT",
"type": "main",
"index": 0
}
]
]
},
"Qualify leads with GPT": {
"main": [
[
{
"node": "Extract JSON reply",
"type": "main",
"index": 0
}
]
]
}
}
}
功能特点
- 自动检测新邮件
- AI智能内容分析
- 自定义分类规则
- 批量处理能力
- 详细的处理日志
技术分析
节点类型及作用
- Merge
- Stickynote
- Googlesheets
- Set
- Openai
复杂度评估
配置难度:
维护难度:
扩展性:
实施指南
前置条件
- 有效的Gmail账户
- n8n平台访问权限
- Google API凭证
- AI分类服务订阅
配置步骤
- 在n8n中导入工作流JSON文件
- 配置Gmail节点的认证信息
- 设置AI分类器的API密钥
- 自定义分类规则和标签映射
- 测试工作流执行
- 配置定时触发器(可选)
关键参数
| 参数名称 | 默认值 | 说明 |
|---|---|---|
| maxEmails | 50 | 单次处理的最大邮件数量 |
| confidenceThreshold | 0.8 | 分类置信度阈值 |
| autoLabel | true | 是否自动添加标签 |
最佳实践
优化建议
- 定期更新AI分类模型以提高准确性
- 根据邮件量调整处理批次大小
- 设置合理的分类置信度阈值
- 定期清理过期的分类规则
安全注意事项
- 妥善保管API密钥和认证信息
- 限制工作流的访问权限
- 定期审查处理日志
- 启用双因素认证保护Gmail账户
性能优化
- 使用增量处理减少重复工作
- 缓存频繁访问的数据
- 并行处理多个邮件分类任务
- 监控系统资源使用情况
故障排除
常见问题
邮件未被正确分类
检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。
Gmail认证失败
确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。
调试技巧
- 启用详细日志记录查看每个步骤的执行情况
- 使用测试邮件验证分类逻辑
- 检查网络连接和API服务状态
- 逐步执行工作流定位问题节点
错误处理
工作流包含以下错误处理机制:
- 网络超时自动重试(最多3次)
- API错误记录和告警
- 处理失败邮件的隔离机制
- 异常情况下的回滚操作