Customer and Sales Support

工作流概述

这是一个包含7个节点的中等工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "7Pw91QNT4UGeNmL5",
  "meta": {
    "instanceId": "95959af22bc98ea4ce12f3aa06514276ddf020a37e9465025051938d10308902",
    "templateCredsSetupCompleted": true
  },
  "name": "Customer and Sales Support",
  "tags": [],
  "nodes": [
    {
      "id": "99d711a1-2341-493b-ba56-e40e76e07d97",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -360,
        -120
      ],
      "webhookId": "1de1a4dd-cea5-4c95-b489-6004601ff727",
      "parameters": {
        "public": true,
        "options": {
          "responseMode": "lastNode",
          "loadPreviousSession": "memory"
        },
        "initialMessages": "Hi! I’m Babish from Apple Case. How can I help?”"
      },
      "typeVersion": 1.1
    },
    {
      "id": "ab809cbb-0456-4a6f-b078-8a6f7bdbd4d0",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        60,
        260
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "gpt-4.1"
        },
        "options": {
          "maxTokens": 1024,
          "temperature": 0.3
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "zqONgMf7CM0LERga",
          "name": "OpenAi DPL 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e74bc18b-3058-4658-83fd-85f9a45d3537",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -220,
        240
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "008d806b-e56d-4c37-b64d-2eb6792eefb5",
      "name": "Place order",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        540,
        240
      ],
      "parameters": {
        "columns": {
          "value": {
            "Address": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Address', ``, 'string') }}",
            "Case ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Case_ID', ``, 'string') }}",
            "Quantity": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Quantity', ``, 'string') }}",
            "Case Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Case_Name', ``, 'string') }}",
            "Timestamp": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Timestamp', ``, 'string') }}",
            "Phone Model": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Phone_Model', ``, 'string') }}",
            "Phone Number": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Phone_Number', ``, 'string') }}",
            "Customer Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Customer_Name', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Case ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Case ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Case Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Case Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone Model",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone Model",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Customer Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone Number",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Address",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Quantity",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Quantity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 622166849,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1btXGPudVDrG64coe5mIlw0Nd8r6YzOnNQ3wp7OVUffc/edit#gid=622166849",
          "cachedResultName": "Order placed"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1btXGPudVDrG64coe5mIlw0Nd8r6YzOnNQ3wp7OVUffc",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1btXGPudVDrG64coe5mIlw0Nd8r6YzOnNQ3wp7OVUffc/edit?usp=drivesdk",
          "cachedResultName": "Apple Case Stock"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "r16nFPNT77oA4BPq",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "9f1d892a-ad76-47ce-815f-1a7cc7a46cf8",
      "name": "Update Stock",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        660,
        240
      ],
      "parameters": {
        "columns": {
          "value": {
            "Sold": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Sold', ``, 'string') }}",
            "Case ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Case_ID__using_to_match_', ``, 'string') }}",
            "Updated ISO": "={{ $now.toISO() }}",
            "Quantity Available": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Quantity_Available', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "Case ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Case ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone Model",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Phone Model",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Case Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Case Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Case Type",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Case Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Quantity Available",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Quantity Available",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Initial Inventory,",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Initial Inventory,",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sold",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sold",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Updated ISO",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Updated ISO",
              "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": [
            "Case ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 2019723207,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1btXGPudVDrG64coe5mIlw0Nd8r6YzOnNQ3wp7OVUffc/edit#gid=2019723207",
          "cachedResultName": "Inventory"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1btXGPudVDrG64coe5mIlw0Nd8r6YzOnNQ3wp7OVUffc",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1btXGPudVDrG64coe5mIlw0Nd8r6YzOnNQ3wp7OVUffc/edit?usp=drivesdk",
          "cachedResultName": "Apple Case Stock"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "r16nFPNT77oA4BPq",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "7f0e6e31-6bdb-4901-9c07-4fb6fa4734f0",
      "name": "Support Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        120,
        -120
      ],
      "parameters": {
        "options": {
          "systemMessage": "=SYSTEM
You are the customer-support agent for “My Apple Case”.

TOOLS
• GetStock      { \"phone_model\": string }
  • Returns: [{ \"case_id\": int, \"case_name\": string,
                \"quantity_available\": int, \"sold\": int,
                \"image_url\": string, ... }]
• PlaceOrder    { \"case_id\": int,
                  \"case_name\": string,
                  \"phone_model\": string,
                  \"customer_name\": string,
                  \"phone_number\": string,
                  \"address\": string,
                  \"quantity\": int }
• UpdateStock   { \"case_id\": int,
                  \"quantity_sold\": int,
                  \"quantity_available\": int,
                  \"sold\": int }
•  The \"case_id\" you send to PlaceOrder or UpdateStock must be the one that
   appears **in the same row as the chosen case_name** from the latest
   GetStock response. Do not invent or modify it.
RULES
1. Begin every user-visible reply with:  **Welcome to My Apple Case.**
2. Speak English or Roman-Nepali, matching the customer.
3. ONE tool call per turn. 
4. If GetStock returns an **image_url**, embed it after the text line using
   Markdown:  
   `![<case_name>](<image_url>)`
5. Legal case_ids set
   • The only valid case_id values are the ones you just received from
     GetStock in this conversation turn.
6. Guard clause
   • If you do not have a valid case_id for the customer’s chosen case,
     ask follow-up questions or run GetStock again.  DO NOT guess.
7.Picking the correct case_id
   a. After GetStock returns, keep its rows in memory.
   b. When the customer names a case_name you just showed, locate the row
      whose case_name matches **exactly** (case-insensitive) and copy that
      row’s case_id.
   c. If more than one row shares the same case_name, ask which “Option #”
      or show a numbered list so they can pick.  Never guess.

WORKFLOW
a. If you don’t yet know stock data, call **GetStock** with the phone model.  
b. From GetStock output read:
      qa = quantity_available
      sold = sold
      img  = image_url  
  • Show the case_id, case_name, qa and (if img exists) the image. 
c. If qa < requested quantity → apologize, no PlaceOrder. 
d. Determine the correct case_id:
     • EXACT match: one row → use that row’s case_id.
     • Multiple matches: show a numbered list and ask the customer to
       choose (e.g. “Type 1 or 2”).  Run no tools until they choose.
   Then call PlaceOrder using that exact case_id.
e. Else collect missing customer fields → call **PlaceOrder**.  
f. After PlaceOrder succeeds, compute:
      qa_new   = qa   - quantity
      sold_new = sold + quantity
   then call **UpdateStock** with:
      { \"case_id\": ..., \"quantity_sold\": quantity,
        \"quantity_available\": qa_new, \"sold\": sold_new }
g. After UpdateStock returns, thank the customer and show qa_new.

EXAMPLES
### Check stock with image
User: iPhone 12 ko cover cha?  
Assistant → tool:  
{ \"tool\": \"GetStock\", \"args\": { \"phone_model\": \"iPhone 12\" } }

(GetStock output example)  
[
  {
    \"case_id\": 312,
    \"case_name\": \"Clear MagSafe Case\",
    \"quantity_available\": 25,
    \"sold\": 75,
    \"image_url\": \"https://example.com/clear-case.png\"
  }
]

### Two rows same name
(GetStock output)
1. case_id 101  \"Leather Flip\"  qty 3
2. case_id 202  \"Leather Flip\"  qty 10

User: I want the Leather Flip case.
Assistant: Welcome to My Apple Case. I have two “Leather Flip” options:
(1) case_id 101 – 3 in stock
(2) case_id 202 – 10 in stock
Which one would you like? Please reply 1 or 2.

My Apple Case ma swagatam. **Clear MagSafe Case** – 25 stock cha.  
![Clear MagSafe Case](https://example.com/clear-case.png)
",
          "returnIntermediateSteps": true
        }
      },
      "retryOnFail": true,
      "typeVersion": 1.8
    },
    {
      "id": "03153a59-4971-49db-86c2-5fd245b36d28",
      "name": "GetStock",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        400,
        240
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Value', ``, 'string') }}",
              "lookupColumn": "Phone Model"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 2019723207,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1btXGPudVDrG64coe5mIlw0Nd8r6YzOnNQ3wp7OVUffc/edit#gid=2019723207",
          "cachedResultName": "Inventory"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1btXGPudVDrG64coe5mIlw0Nd8r6YzOnNQ3wp7OVUffc",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1btXGPudVDrG64coe5mIlw0Nd8r6YzOnNQ3wp7OVUffc/edit?usp=drivesdk",
          "cachedResultName": "Apple Case Stock"
        },
        "combineFilters": "OR"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "r16nFPNT77oA4BPq",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.5
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6f49665c-583f-456e-9ea9-bb95b172cac1",
  "connections": {
    "GetStock": {
      "ai_tool": [
        [
          {
            "node": "Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Place order": {
      "ai_tool": [
        [
          {
            "node": "Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update Stock": {
      "ai_tool": [
        [
          {
            "node": "Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Support Agent",
            "type": "ai_memory",
            "index": 0
          },
          {
            "node": "When chat message received",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Support Agent": {
      "main": [
        []
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Support Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Support Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • @N8N/N8N Nodes Langchain.Chattrigger
  • @N8N/N8N Nodes Langchain.Lmchatopenai
  • @N8N/N8N Nodes Langchain.Memorybufferwindow
  • Googlesheetstool
  • @N8N/N8N Nodes Langchain.Agent

复杂度评估

配置难度:
★★★☆☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作