Dialpad to Syncro
工作流概述
这是一个包含22个节点的复杂工作流,主要用于自动化处理各种任务。
工作流源代码
{
"id": "1",
"name": "Dialpad to Syncro",
"nodes": [
{
"name": "GetCustomer",
"type": "n8n-nodes-base.httpRequest",
"position": [
350,
180
],
"parameters": {
"url": "={{$node[\"EnvVariables\"].json[\"syncro_baseurl\"]}}/api/v1/search?query={{$json[\"body\"][\"external_number\"].replace(/\+/g, '').replace(/^[01]/, '')}}",
"options": {},
"authentication": "headerAuth"
},
"credentials": {
"httpHeaderAuth": "Syncro"
},
"typeVersion": 1
},
{
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"position": [
-60,
180
],
"webhookId": "ec452bb5-58d9-4e0d-9cd2-c6df1c2cd957",
"parameters": {
"path": "moezdialpad",
"options": {},
"httpMethod": "POST",
"responseData": "allEntries",
"responseMode": "lastNode"
},
"typeVersion": 1
},
{
"name": "CreateTicket",
"type": "n8n-nodes-base.httpRequest",
"position": [
1190,
110
],
"parameters": {
"url": "={{$node[\"EnvVariables\"].json[\"syncro_baseurl\"]}}/api/v1/tickets",
"options": {
"bodyContentType": "json"
},
"requestMethod": "POST",
"authentication": "headerAuth",
"bodyParametersUi": {
"parameter": [
{
"name": "customer_id",
"value": "={{$node[\"Contacts\"].json[\"contacts\"][0][\"customer_id\"]}}"
},
{
"name": "subject",
"value": "=Phone call from {{$node[\"Function\"].json[\"contacts\"][0][\"firstname\"]}} {{$node[\"Function\"].json[\"contacts\"][0][\"lastname\"]}} ({{$node[\"Webhook\"].json[\"body\"][\"contact\"][\"phone\"]}})"
},
{
"name": "status",
"value": "In Progress"
},
{
"name": "contact_id",
"value": "={{$node[\"Contacts\"].json[\"contacts\"][0][\"id\"]}}"
},
{
"name": "user_id",
"value": "={{$node[\"EnvVariables\"].parameter[\"values\"][\"string\"][1][\"value\"]}}"
}
]
}
},
"credentials": {
"httpHeaderAuth": "Syncro"
},
"typeVersion": 1
},
{
"name": "GetTicket",
"type": "n8n-nodes-base.httpRequest",
"position": [
860,
40
],
"parameters": {
"url": "={{$node[\"EnvVariables\"].json[\"syncro_baseurl\"]}}/api/v1/tickets?contact_id={{$json[\"contacts\"][0][\"id\"]}}&status=Not%20Closed",
"options": {},
"authentication": "headerAuth"
},
"credentials": {
"httpHeaderAuth": "Syncro"
},
"typeVersion": 1
},
{
"name": "IFMoreThanOne",
"type": "n8n-nodes-base.if",
"position": [
1000,
40
],
"parameters": {
"conditions": {
"number": [
{
"value1": "={{$node[\"GetTicket\"].json[\"tickets\"].length}}",
"value2": 1,
"operation": "equal"
}
],
"boolean": [
{
"value1": "={{$json[\"tickets\"]}}",
"value2": true
}
]
},
"combineOperation": "any"
},
"typeVersion": 1
},
{
"name": "Google Sheets",
"type": "n8n-nodes-base.googleSheets",
"position": [
1480,
-40
],
"parameters": {
"range": "A:B",
"options": {
"valueInputMode": "USER_ENTERED"
},
"sheetId": "xxx",
"operation": "append"
},
"credentials": {
"googleApi": "Google"
},
"typeVersion": 1
},
{
"name": "ForGoogle",
"type": "n8n-nodes-base.set",
"position": [
1340,
-40
],
"parameters": {
"values": {
"string": [
{
"name": "Call",
"value": "={{$node[\"Webhook\"].json[\"body\"][\"call_id\"]}}"
},
{
"name": "Ticket",
"value": "={{$node[\"GetTicket\"].json[\"tickets\"][0][\"id\"]}}"
}
]
},
"options": {},
"keepOnlySet": true
},
"typeVersion": 1
},
{
"name": "UpdateTicket",
"type": "n8n-nodes-base.httpRequest",
"position": [
1190,
-40
],
"parameters": {
"url": "={{$node[\"EnvVariables\"].json[\"syncro_baseurl\"]}}/api/v1/tickets/{{$json[\"tickets\"][0][\"id\"]}}/comment",
"options": {},
"requestMethod": "POST",
"authentication": "headerAuth",
"bodyParametersUi": {
"parameter": [
{
"name": "subject",
"value": "=Phone call from {{$node[\"GetCustomer\"].json[\"results\"][0][\"table\"][\"_source\"][\"table\"][\"firstname\"]}} {{$node[\"GetCustomer\"].json[\"results\"][0][\"table\"][\"_source\"][\"table\"][\"lastname\"]}} ({{$node[\"Webhook\"].json[\"body\"][\"contact\"][\"phone\"]}})"
},
{
"name": "body",
"value": "={{$node[\"GetCustomer\"].json[\"results\"][0][\"table\"][\"_source\"][\"table\"][\"firstname\"]}} {{$node[\"GetCustomer\"].json[\"results\"][0][\"table\"][\"_source\"][\"table\"][\"lastname\"]}} called."
},
{
"name": "hidden",
"value": "true"
},
{
"name": "user_id",
"value": "={{$node[\"EnvVariables\"].parameter[\"values\"][\"string\"][1][\"value\"]}}"
}
]
}
},
"credentials": {
"httpHeaderAuth": "Syncro"
},
"typeVersion": 1
},
{
"name": "ForGoogle1",
"type": "n8n-nodes-base.set",
"position": [
1340,
110
],
"parameters": {
"values": {
"string": [
{
"name": "Call",
"value": "={{$node[\"Webhook\"].json[\"body\"][\"call_id\"]}}"
},
{
"name": "Ticket",
"value": "={{$node[\"CreateTicket\"].json[\"ticket\"][\"id\"]}}"
}
]
},
"options": {},
"keepOnlySet": true
},
"typeVersion": 1
},
{
"name": "Google Sheets1",
"type": "n8n-nodes-base.googleSheets",
"position": [
1480,
110
],
"parameters": {
"range": "A:B",
"options": {
"valueInputMode": "USER_ENTERED"
},
"sheetId": "xxx",
"operation": "append"
},
"credentials": {
"googleApi": "Google"
},
"typeVersion": 1
},
{
"name": "NoOp",
"type": "n8n-nodes-base.noOp",
"position": [
830,
220
],
"parameters": {},
"typeVersion": 1
},
{
"name": "Contacts",
"type": "n8n-nodes-base.function",
"position": [
510,
180
],
"parameters": {
"functionCode": "const { json: { results } } = items[0];
const getData = (results, type) => results.filter(r => r.table._index === type).map(x => ({
id: x.table._id,
firstname: x.table._source.table.firstname,
lastname: x.table._source.table.lastname,
customer_id: x.table._source.table.customer_id,
email: x.table._source.table.email,
business_name: x.table._source.table.business_name,
phones: x.table._source.table.phones
}));
return [ { json: { contacts: getData(results, 'contacts') } } ];
"
},
"typeVersion": 1,
"alwaysOutputData": false
},
{
"name": "IFContacts",
"type": "n8n-nodes-base.if",
"position": [
670,
180
],
"parameters": {
"conditions": {
"number": [
{
"value1": "={{$node[\"Contacts\"].json[\"contacts\"].length}}",
"value2": 1,
"operation": "equal"
}
],
"string": [],
"boolean": []
}
},
"typeVersion": 1
},
{
"name": "Customers",
"type": "n8n-nodes-base.function",
"position": [
510,
370
],
"parameters": {
"functionCode": "const { json: { results } } = items[0];
const getData = (results, type) => results.filter(r => r.table._index === type).map(x => ({
id: x.table._id,
firstname: x.table._source.table.firstname,
lastname: x.table._source.table.lastname,
customer_id: x.table._source.table.customer_id,
email: x.table._source.table.email,
business_name: x.table._source.table.business_name,
phones: x.table._source.table.phones
}));
return [ { json: { customers: getData(results, 'customers') } } ];
"
},
"typeVersion": 1
},
{
"name": "IFCustomers",
"type": "n8n-nodes-base.if",
"position": [
670,
370
],
"parameters": {
"conditions": {
"number": [
{
"value1": "={{$node[\"Customers\"].json[\"customers\"].length}}",
"value2": 1,
"operation": "equal"
}
],
"string": [],
"boolean": []
}
},
"typeVersion": 1
},
{
"name": "NoOp1",
"type": "n8n-nodes-base.noOp",
"position": [
810,
520
],
"parameters": {},
"typeVersion": 1
},
{
"name": "CreateTicketForCustomer",
"type": "n8n-nodes-base.httpRequest",
"position": [
860,
360
],
"parameters": {
"url": "={{$node[\"EnvVariables\"].json[\"syncro_baseurl\"]}}/api/v1/tickets",
"options": {
"bodyContentType": "json"
},
"requestMethod": "POST",
"authentication": "headerAuth",
"bodyParametersUi": {
"parameter": [
{
"name": "customer_id",
"value": "={{$node[\"Customers\"].json[\"customers\"][0][\"id\"]}}"
},
{
"name": "subject",
"value": "=Phone call from {{$node[\"Customers\"].json[\"customers\"][0][\"business_name\"]}} ({{$node[\"Webhook\"].json[\"body\"][\"contact\"][\"phone\"]}})"
},
{
"name": "status",
"value": "In Progress"
},
{
"name": "user_id",
"value": "={{$node[\"EnvVariables\"].parameter[\"values\"][\"string\"][1][\"value\"]}}"
}
]
}
},
"credentials": {
"httpHeaderAuth": "Syncro"
},
"typeVersion": 1
},
{
"name": "ForGoogle2",
"type": "n8n-nodes-base.set",
"position": [
1040,
360
],
"parameters": {
"values": {
"string": [
{
"name": "Call",
"value": "={{$node[\"Webhook\"].json[\"body\"][\"call_id\"]}}"
},
{
"name": "Ticket",
"value": "={{$node[\"CreateTicketForCustomer\"].json[\"ticket\"][\"id\"]}}"
}
]
},
"options": {},
"keepOnlySet": true
},
"typeVersion": 1
},
{
"name": "Google Sheets2",
"type": "n8n-nodes-base.googleSheets",
"position": [
1210,
360
],
"parameters": {
"range": "A:B",
"options": {
"valueInputMode": "USER_ENTERED"
},
"sheetId": "xxx",
"operation": "append"
},
"credentials": {
"googleApi": "Google"
},
"typeVersion": 1
},
{
"name": "EnvVariables",
"type": "n8n-nodes-base.set",
"position": [
210,
180
],
"parameters": {
"values": {
"string": [
{
"name": "syncro_baseurl",
"value": "https://subdomain.syncromsp.com"
},
{
"name": "user_id",
"value": "1234"
}
]
},
"options": {}
},
"typeVersion": 1
},
{
"name": "IF",
"type": "n8n-nodes-base.if",
"position": [
70,
180
],
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$node[\"Webhook\"].json[\"body\"][\"direction\"]}}",
"value2": "inbound"
}
]
}
},
"typeVersion": 1
},
{
"name": "NoOp2",
"type": "n8n-nodes-base.noOp",
"position": [
70,
370
],
"parameters": {},
"typeVersion": 1
}
],
"active": true,
"settings": {},
"connections": {
"IF": {
"main": [
[
{
"node": "EnvVariables",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp2",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
},
"Contacts": {
"main": [
[
{
"node": "IFContacts",
"type": "main",
"index": 0
}
]
]
},
"Customers": {
"main": [
[
{
"node": "IFCustomers",
"type": "main",
"index": 0
}
]
]
},
"ForGoogle": {
"main": [
[
{
"node": "Google Sheets",
"type": "main",
"index": 0
}
]
]
},
"GetTicket": {
"main": [
[
{
"node": "IFMoreThanOne",
"type": "main",
"index": 0
}
]
]
},
"ForGoogle1": {
"main": [
[
{
"node": "Google Sheets1",
"type": "main",
"index": 0
}
]
]
},
"ForGoogle2": {
"main": [
[
{
"node": "Google Sheets2",
"type": "main",
"index": 0
}
]
]
},
"IFContacts": {
"main": [
[
{
"node": "GetTicket",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp",
"type": "main",
"index": 0
}
]
]
},
"GetCustomer": {
"main": [
[
{
"node": "Contacts",
"type": "main",
"index": 0
},
{
"node": "Customers",
"type": "main",
"index": 0
}
]
]
},
"IFCustomers": {
"main": [
[
{
"node": "CreateTicketForCustomer",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp1",
"type": "main",
"index": 0
}
]
]
},
"CreateTicket": {
"main": [
[
{
"node": "ForGoogle1",
"type": "main",
"index": 0
}
]
]
},
"EnvVariables": {
"main": [
[
{
"node": "GetCustomer",
"type": "main",
"index": 0
}
]
]
},
"UpdateTicket": {
"main": [
[
{
"node": "ForGoogle",
"type": "main",
"index": 0
}
]
]
},
"IFMoreThanOne": {
"main": [
[
{
"node": "UpdateTicket",
"type": "main",
"index": 0
}
],
[
{
"node": "CreateTicket",
"type": "main",
"index": 0
}
]
]
},
"CreateTicketForCustomer": {
"main": [
[
{
"node": "ForGoogle2",
"type": "main",
"index": 0
}
]
]
}
}
}
功能特点
- 自动检测新邮件
- AI智能内容分析
- 自定义分类规则
- 批量处理能力
- 详细的处理日志
技术分析
节点类型及作用
- Httprequest
- Webhook
- If
- Googlesheets
- Set
复杂度评估
配置难度:
维护难度:
扩展性:
实施指南
前置条件
- 有效的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错误记录和告警
- 处理失败邮件的隔离机制
- 异常情况下的回滚操作