8
n8n 中文网amn8n.com

AI自动路由电子邮件并发送Slack警报

中级

这是一个AI Summarization, Multimodal AI领域的自动化工作流,包含 7 个节点。主要使用 Set, Gmail, Slack, GmailTrigger, Agent 等节点。 使用GPT-4o自动分类Gmail邮件并发送优先级Slack警报

前置要求
  • Google 账号和 Gmail API 凭证
  • Slack Bot Token 或 Webhook URL
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "name": "AI 自动路由电子邮件并发送 Slack 警报",
  "nodes": [
    {
      "id": "cfcf1f18-7faa-408d-9cb6-a7eb7fab5886",
      "name": "触发未读电子邮件",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -368,
        224
      ],
      "parameters": {
        "filters": {
          "readStatus": "unread"
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "96e9c067-b27e-437c-9ea7-16e46cf1f09d",
      "name": "获取电子邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -144,
        224
      ],
      "parameters": {
        "simple": false,
        "options": {},
        "messageId": "={{ $json.id }}",
        "operation": "get"
      },
      "typeVersion": 2.1
    },
    {
      "id": "d7d471c3-65e2-43d6-8472-31d278171fd9",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        80,
        224
      ],
      "parameters": {
        "text": "=You are an email router. Read subject and body and output valid JSON with:\n- category: one of [sales_pre_purchase, support_technical, billing_refund, complaint_escalation]\n- from: {{$json.from?.value?.[0]?.address || $json.from?.email || ''}}\n- subject: {{$json.subject || $json.headers?.subject || $json.subject}}\n- priority: one of [low, normal, high, urgent]\n- summary: short one line summary\n- reason: short why you chose the category\n\nRules:\n- If the sender asks pre-purchase features, pricing, demos → sales_pre_purchase\n- If the sender reports bugs, errors, account access, how-to → support_technical\n- If the sender mentions charges, invoices, refunds → billing_refund\n- If the sender is angry, threatens to leave, mentions escalation or complaint → complaint_escalation\nOutput only minified JSON. No extra text.\n\nEmail Body:\n{{$json.textPlain || $json.text || ''}}\n",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "c906a662-dfe5-4bb7-ad61-5b472d4027bc",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        88,
        448
      ],
      "parameters": {
        "model": {
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "ce9714c6-1d15-470b-a805-1041a7a63571",
      "name": "结构化输出解析器",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        216,
        448
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"category\": { \"type\": \"string\", \"enum\": [\"sales_pre_purchase\",\"support_technical\",\"billing_refund\",\"complaint_escalation\"] },\n    \"priority\": { \"type\": \"string\", \"enum\": [\"low\",\"normal\",\"high\",\"urgent\"] },\n    \"summary\": { \"type\": \"string\", \"maxLength\": 280 },\n    \"reason\": { \"type\": \"string\", \"maxLength\": 140 },\n    \"subject\": { \"type\": \"string\", \"maxLength\": 280 },\n    \"from\": { \"type\": \"string\", \"maxLength\": 140 }\n  },\n  \"required\": [\"category\",\"priority\",\"summary\",\"subject\",\"from\"],\n  \"additionalProperties\": false\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "360cf165-a32a-4aa8-8770-af244fe67995",
      "name": "路由映射",
      "type": "n8n-nodes-base.set",
      "position": [
        432,
        224
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "name": "label",
              "type": "string",
              "value": "={{ $json.output.category === 'sales_pre_purchase' ? 'Sales' : $json.output.category === 'support_technical' ? 'Support' : $json.output.category === 'billing_refund' ? 'Billing' : 'Complaint' }}"
            },
            {
              "name": "slackChannel",
              "type": "string",
              "value": "={{ \n  $json.output.category === 'sales_pre_purchase' ? 'C09B7HS98GN' :\n  $json.output.category === 'support_technical' ? 'C09B5JV2G9Y' :\n  $json.output.category === 'billing_refund' ? 'C09BYN135T2' :\n  'C09B5JV2G9Y'\n}}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "39e36a35-33f9-4f1b-a38d-cfffd4ba8127",
      "name": "发送通知到 Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        656,
        224
      ],
      "parameters": {
        "text": "=Priority: {{$json.output.priority}}\nFrom: {{ $json.output.from }}\nSummary: {{ $json.output.summary }}\nReason: {{ $json.output.reason }}",
        "user": {
          "value": "={{ $json.slackChannel }}"
        },
        "select": "user",
        "otherOptions": {
          "includeLinkToWorkflow": false
        },
        "authentication": "oAuth2"
      },
      "typeVersion": 2.3
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Routing Map",
            "type": "main",
            "index": 0
          }
        ]
      ],
      "ai_outputParser": [
        [
          {
            "node": "Structured Output Parser",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ],
      "ai_languageModel": [
        [
          {
            "node": "OpenAI Chat Model",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Email": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Routing Map": {
      "main": [
        [
          {
            "node": "Send Notification to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger on Unread Email": {
      "main": [
        [
          {
            "node": "Get Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - AI 摘要总结, 多模态 AI

需要付费吗?

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

工作流信息
难度等级
中级
节点数量7
分类2
节点类型7
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Matt Chong | n8n Creator

Matt Chong | n8n Creator

@mattxchong

Automation nerd fueled by good coffee, deep curiosity, and clean flows.

外部链接
在 n8n.io 查看

分享此工作流