8
n8n 中文网amn8n.com

具有 AI 分类、Gmail 草稿和 Slack 通知的智能电子邮件助手

高级

这是一个Ticket Management, AI Summarization领域的自动化工作流,包含 16 个节点。主要使用 Set, Code, Gmail, Slack, Switch 等节点。 使用 OpenAI 分类、Gmail 草稿和 Slack 提醒实现邮件管理自动化

前置要求
  • Google 账号和 Gmail API 凭证
  • Slack Bot Token 或 Webhook URL
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "FSJP3VvgYM0hlloV",
  "meta": {
    "instanceId": "1ada9ce9d909de0cc535c0dfb57eee784c801e364e1670e7476e5ce8b69d1197"
  },
  "name": "具有 AI 分类、Gmail 草稿和 Slack 通知的智能电子邮件助手",
  "tags": [
    {
      "id": "grLYSyd5iJcUTmvb",
      "name": "ZenAgent Labs",
      "createdAt": "2025-06-29T14:28:06.655Z",
      "updatedAt": "2025-06-29T14:28:06.655Z"
    }
  ],
  "nodes": [
    {
      "id": "e777600d-4456-4bcd-b356-231a340e8da7",
      "name": "工作流描述",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -700,
        140
      ],
      "parameters": {
        "width": 550,
        "height": 1300,
        "content": "## 具有 AI 分类、Gmail 草稿和 Slack 通知的智能电子邮件助手"
      },
      "typeVersion": 1
    },
    {
      "id": "5825d614-da89-4262-810b-074f5a788ac4",
      "name": "Gmail 设置说明",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        680
      ],
      "parameters": {
        "width": 380,
        "height": 580,
        "content": "## Gmail 标签设置说明"
      },
      "typeVersion": 1
    },
    {
      "id": "6a4ce1eb-3e14-4f7b-8dd2-884858e9edd3",
      "name": "Gmail 触发器 - AI Agent 标签",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        520,
        660
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "labelIds": []
        },
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "LwfJ8b1o1ZOBYMwi",
          "name": "Gmail ZNTL"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "575d0664-15f9-4c1a-bb85-702aa7406f02",
      "name": "提取电子邮件数据",
      "type": "n8n-nodes-base.set",
      "position": [
        740,
        660
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "email-id",
              "name": "emailId",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "id": "email-subject",
              "name": "subject",
              "type": "string",
              "value": "={{ $json.subject }}"
            },
            {
              "id": "email-from",
              "name": "sender",
              "type": "string",
              "value": "={{ $json.from }}"
            },
            {
              "id": "email-body",
              "name": "content",
              "type": "string",
              "value": "={{ $json.text || $json.html }}"
            },
            {
              "id": "timestamp",
              "name": "receivedAt",
              "type": "string",
              "value": "={{ $json.date }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9dc28e85-da76-4a56-bab7-2449eeeabd5a",
      "name": "AI Agent - 电子邮件分类器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        960,
        660
      ],
      "parameters": {
        "text": "=Email to analyze:\nFrom: {{ $json.sender }}\nSubject: {{ $json.subject }}\nContent: {{ $json.content }}",
        "options": {
          "systemMessage": "=You are an AI assistant for email classification. Your task is to analyze incoming emails and categorize them into one of the following categories:\n\n1. **Inquiry** - Requests from partners, prospects, or your network\n2. **Support** - Customer support requests, complaints, or help requests\n3. **Newsletter** - Marketing emails, newsletters, or promotional content\n4. **Actionpoint** - Emails requiring immediate action or follow-up tasks\n\nAnalyze the email content including:\n- Sender information\n- Subject line\n- Email content\n- Tone and urgency\n\nRespond with a JSON object in exactly this format:\n{\n  \"category\": \"[One of: Inquiry, Support, Newsletter, Actionpoint]\",\n  \"confidence\": [0.0-1.0],\n  \"reasoning\": \"Brief explanation of why this category was chosen\",\n  \"suggestedResponse\": \"Only for Inquiry and Support emails: A professional, friendly draft response in English\",\n  \"summary\": \"Only for Newsletter emails: A summary of essential information. Particularly interesting and noteworthy for me are infos about AI agents and AI automation\"\n}\n\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "32502ca5-832f-4bf6-85b8-18452071d589",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        920,
        920
      ],
      "parameters": {
        "model": "o3",
        "options": {
          "responseFormat": "json_object"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "73c4e031-badb-4562-b791-4843c4b12cf9",
      "name": "解析 AI 分类",
      "type": "n8n-nodes-base.code",
      "position": [
        1280,
        660
      ],
      "parameters": {
        "jsCode": "// Parse AI Agent output and prepare for routing\nconst aiOutput = $input.first().json.output;\nlet classification;\n\ntry {\n  // Parse JSON string output from AI Agent\n  classification = JSON.parse(aiOutput);\n} catch (error) {\n  // Fallback if parsing fails\n  classification = {\n    category: \"Support\",\n    confidence: 0.5,\n    reasoning: \"AI response could not be parsed, defaulting to Support\",\n    suggestedResponse: \"\"\n  };\n}\n\n// Map categories to Gmail Label IDs\n// IMPORTANT: Update these Label IDs with your actual Gmail label IDs\nconst labelMapping = {\n  \"Inquiry\": \"Label_123456789\",\n  \"Actionpoint\": \"Label_123456789\", \n  \"Support\": \"Label_123456789\",\n  \"Newsletter\": \"Label_123456789\"\n};\n\n// Combine with original email data and add label ID\nreturn {\n  json: {\n    ...classification,\n    labelId: labelMapping[classification.category] || labelMapping[\"Support\"], // Fallback to Support\n    emailId: $('Extract Email Data').first().json.emailId,\n    subject: $('Extract Email Data').first().json.subject,\n    sender: $('Extract Email Data').first().json.sender,\n    content: $('Extract Email Data').first().json.content,\n    receivedAt: $('Extract Email Data').first().json.receivedAt\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "858a4fbf-7ba3-497b-955c-20be5d6148c0",
      "name": "AI 分类信息",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        920,
        140
      ],
      "parameters": {
        "width": 380,
        "height": 380,
        "content": "## AI 分类逻辑"
      },
      "typeVersion": 1
    },
    {
      "id": "cfa9478c-ed03-4c78-b910-be6e48528888",
      "name": "添加分类标签",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1480,
        660
      ],
      "webhookId": "78dd2938-c072-41b1-97c2-e526313dcdba",
      "parameters": {
        "labelIds": "={{ $json.labelId }}",
        "messageId": "={{ $('Gmail Trigger - AI Agent Label').item.json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "LwfJ8b1o1ZOBYMwi",
          "name": "Gmail ZNTL"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "30ca3a6d-775d-485c-b978-3b902d94bda4",
      "name": "按类别路由",
      "type": "n8n-nodes-base.switch",
      "position": [
        1680,
        660
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Draft",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "bcdd0c26-f15f-495d-851f-428448a4809d",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Parse AI Classification').item.json.category }}",
                    "rightValue": "=Support"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Draft",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "1e4a4ac3-9a17-4431-ba3c-57143c1c3d4f",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Parse AI Classification').item.json.category }}",
                    "rightValue": "Inquiry"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Newsletter",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "92882b71-a38c-456d-a767-9db4920c95a5",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Parse AI Classification').item.json.category }}",
                    "rightValue": "Newsletter"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Actionpoint",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "3e4709bf-e84e-4963-af62-2b49f2147ca3",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Parse AI Classification').item.json.category }}",
                    "rightValue": "Actionpoint"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "none"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "2bb9e810-b62b-43b5-9018-8a4ee43da90e",
      "name": "成功操作信息",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2440,
        280
      ],
      "parameters": {
        "color": 4,
        "width": 320,
        "height": 280,
        "content": "## 工作流操作摘要"
      },
      "typeVersion": 1
    },
    {
      "id": "713a3bc5-8e0f-46f4-ad9b-87d7adc07dbd",
      "name": "错误处理信息",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2440,
        600
      ],
      "parameters": {
        "color": 5,
        "width": 320,
        "height": 240,
        "content": "## 错误处理与监控"
      },
      "typeVersion": 1
    },
    {
      "id": "ba402d17-fb77-419e-87f2-f00414cf0892",
      "name": "创建草稿回复",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2080,
        460
      ],
      "webhookId": "e8d40041-6c0e-47c1-9c46-68e073deb903",
      "parameters": {
        "message": "={{ $('Parse AI Classification').item.json.suggestedResponse }}",
        "options": {
          "threadId": "={{ $('Gmail Trigger - AI Agent Label').item.json.threadId }}"
        },
        "subject": "=Re: {{ $json.subject }}",
        "resource": "draft"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "LwfJ8b1o1ZOBYMwi",
          "name": "Gmail ZNTL"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "59934725-d2f3-4faf-a9db-8a4187a81081",
      "name": "发送待办事项 Slack 提醒",
      "type": "n8n-nodes-base.slack",
      "position": [
        2080,
        840
      ],
      "webhookId": "2f189afd-e368-4b6a-910a-1fb14d57fb2e",
      "parameters": {
        "operation": "postMessage"
      },
      "typeVersion": 2.2
    },
    {
      "id": "78cce31c-12b8-4c89-b362-07f92be4b3a9",
      "name": "发送通讯摘要到 Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        2080,
        660
      ],
      "webhookId": "1aa89f39-9101-4859-8515-c9796a8335a5",
      "parameters": {
        "operation": "postMessage"
      },
      "typeVersion": 2.3
    },
    {
      "id": "f19d4daa-ff84-4421-8170-c7c9c86321f2",
      "name": "Slack 设置说明",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1940,
        20
      ],
      "parameters": {
        "width": 380,
        "height": 360,
        "content": "## Slack 集成设置"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "60db44aa-f739-4a39-a086-f0726955927a",
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent - Email Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Route by Category": {
      "main": [
        [
          {
            "node": "Create Draft Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Draft Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Newsletter Summary to Slack",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Action Item Slack Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Email Data": {
      "main": [
        [
          {
            "node": "AI Agent - Email Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Classification": {
      "main": [
        [
          {
            "node": "Add Classification Label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Classification Label": {
      "main": [
        [
          {
            "node": "Route by Category",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent - Email Classifier": {
      "main": [
        [
          {
            "node": "Parse AI Classification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger - AI Agent Label": {
      "main": [
        [
          {
            "node": "Extract Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 工单管理, AI 摘要总结

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量16
分类2
节点类型9
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 查看

分享此工作流