8
n8n 中文网amn8n.com

AI驱动的邮件回复系统,集成垃圾邮件过滤和FAQ查询,使用GPT-4o mini和Pinecone

中级

这是一个AI领域的自动化工作流,包含 13 个节点。主要使用 If, Gmail, GmailTool, GmailTrigger, Agent 等节点,结合人工智能技术实现智能自动化。 AI驱动的邮件回复系统,集成垃圾邮件过滤和FAQ查询,使用GPT-4o mini和Pinecone

前置要求
  • Google 账号和 Gmail API 凭证
  • OpenAI API Key
  • Pinecone API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "eef1c32da34f97cb889cc6dbc544123406b39d27266f625630b9aa0893bf45d7"
  },
  "nodes": [
    {
      "id": "d68e1936-eec7-4334-8317-70805c95b0ab",
      "name": "AI 代理",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        140,
        180
      ],
      "parameters": {
        "text": "={{ $('get_message').item.json.text }}",
        "options": {
          "systemMessage": "You are a polite and professional virtual assistant.\n\nYou receive an email.\n\nYour knowledge base is stored in the Pinecone Vector Store, which contains all relevant FAQs and information needed to assist the user accurately.\n\nAlways consult the Pinecone Vector Store before generating your response.\n\nYour final answer must be sent using the \"Gmail\" tool.\n\nWhen using the Gmail tool, make sure to:\n\nFill in the Message field with the response content\n\nFill in the Subject field with a short subject line (you can use \"Reply\" if unsure)"
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "0d136348-a945-43c0-bebe-1599f4aef1bd",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        80,
        360
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "OTuydMANCBoed1Fr",
          "name": "OpenAi account 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1f6e0331-b1e0-4450-a41a-acff7f0ccae6",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        240,
        360
      ],
      "parameters": {
        "sessionKey": "={{'key'}}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "7af79daa-d3e0-4111-9005-0930debe0c03",
      "name": "Gmail",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        380,
        360
      ],
      "webhookId": "f8feb0d1-c7dd-4172-8ebd-e125f18f2c4c",
      "parameters": {
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "options": {
          "appendAttribution": false
        },
        "emailType": "text",
        "messageId": "={{ $('get_message').item.json.id }}",
        "operation": "reply"
      },
      "typeVersion": 2.1
    },
    {
      "id": "5b1779a5-1cf5-4660-ab6f-456de5f07137",
      "name": "Gmail 触发器",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -1160,
        400
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyHour"
            },
            {}
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "1YbI98PAg8EdHQyr",
          "name": "total_ai_solutions"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a8fb6a4f-037f-42d0-b5a6-e14acef1bf8a",
      "name": "获取消息",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -880,
        400
      ],
      "webhookId": "364e19bb-56a0-4cfe-8f89-1bedce5345ae",
      "parameters": {
        "simple": false,
        "options": {},
        "messageId": "={{ $json.id }}",
        "operation": "get"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "1YbI98PAg8EdHQyr",
          "name": "total_ai_solutions"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "26dd84f5-99e5-4e53-acde-ebbdf8d889d0",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1220,
        160
      ],
      "parameters": {
        "color": 3,
        "width": 1220,
        "height": 460,
        "content": "## Gmail 输入"
      },
      "typeVersion": 1
    },
    {
      "id": "14915f5c-0375-46b8-90ee-c412a6b0e40c",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": 4,
        "width": 540,
        "height": 620,
        "content": "## AI 代理"
      },
      "typeVersion": 1
    },
    {
      "id": "09a0c5ca-6d4f-46ef-aa34-09b565f698f7",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        620
      ],
      "parameters": {
        "color": 6,
        "width": 540,
        "height": 300,
        "content": "## 向量存储"
      },
      "typeVersion": 1
    },
    {
      "id": "4a56b1ab-39d6-424c-a614-06febe5f5f63",
      "name": "Pinecone 向量存储",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        200,
        680
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "options": {},
        "toolName": "FAQ",
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "faqmattabott",
          "cachedResultName": "faqmattabott"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "435fa9d9-cee9-4aad-a51b-25566a96b2af",
      "name": "OpenAI嵌入",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        60,
        800
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "OTuydMANCBoed1Fr",
          "name": "OpenAi account 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d0801a3b-d336-4e50-a8da-58ff218c3673",
      "name": "如果",
      "type": "n8n-nodes-base.if",
      "position": [
        -280,
        400
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "921d0426-0dbf-49ac-ab67-b5538856deee",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.message.content }}",
              "rightValue": "spam"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ddea4fe7-e458-4949-aba5-57da659ab15c",
      "name": "垃圾邮件检查器",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -640,
        400
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are a e-mail assistant. You have to check if the received e-mail are spam or not.\nYou have to check not only normal spam, but everything is not sent from a person, for example, automatic e-mail, google email, and anything out of a possible client.\n\nIf an e-mail is considered spam, as I sayd befor, your output will be \"spam\". If not, say \"no spam\".\n\nDon't respond anything else \"spam\" or \"not spam\"."
            },
            {
              "content": "={{ $json.headers.subject }}{{ $json.headers.from }}{{ $json.text }}"
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "OTuydMANCBoed1Fr",
          "name": "OpenAi account 2"
        }
      },
      "typeVersion": 1.8
    }
  ],
  "pinData": {},
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        []
      ]
    },
    "get_message": {
      "main": [
        [
          {
            "node": "Spam checker",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spam checker": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "get_message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Store": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 人工智能

需要付费吗?

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

工作流信息
难度等级
中级
节点数量13
分类1
节点类型11
难度说明

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

外部链接
在 n8n.io 查看

分享此工作流