8
n8n 中文网amn8n.com

行为准则问答 Slack 聊天机器人(RAG 驱动)

高级

这是一个AI RAG, Multimodal AI领域的自动化工作流,包含 24 个节点。主要使用 If, Code, Slack, Webhook, FormTrigger 等节点。 使用 GPT-4 和 RAG 技术在 Slack 中回答行为准则问题

前置要求
  • Slack Bot Token 或 Webhook URL
  • HTTP Webhook 端点(n8n 会自动生成)
  • Google Drive API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "rFm9WyEEbE0Cbp4V",
  "meta": {
    "instanceId": "4a2e6764ba7a6bc9890d9225f4b21d570ce88fc9bd57549c89057fcee58fed0f",
    "templateId": "1961",
    "templateCredsSetupCompleted": true
  },
  "name": "行为准则问答 Slack 聊天机器人(RAG 驱动)",
  "tags": [
    {
      "id": "mrjg6I7yRRonHQkj",
      "name": "slack",
      "createdAt": "2025-08-22T05:19:22.985Z",
      "updatedAt": "2025-08-22T05:19:22.985Z"
    }
  ],
  "nodes": [
    {
      "id": "d8182642-5598-4fae-8a72-13f63d9436a2",
      "name": "是用户消息吗?",
      "type": "n8n-nodes-base.if",
      "position": [
        -3224,
        1192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1def7344-ce55-450d-a85a-468f746fe31f",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.body.event.type }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d2ae5571-62c6-4ada-8807-0e53d90ae6c5",
      "name": "无操作,不执行任何操作",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -2760,
        1392
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "8794702d-9c02-40ba-8a62-acd6ccb8df08",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -3536,
        1200
      ],
      "webhookId": "4e9d4215-802a-4322-ad54-67ce21d5c1e3",
      "parameters": {
        "path": "4e9d4215-802a-4322-ad54-67ce21d5c1e3",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "lastNode"
      },
      "typeVersion": 2
    },
    {
      "id": "b9c6502a-8232-4840-a252-0f2889d96d7d",
      "name": "gpt4-1 模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -2912,
        1008
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "PPSwAKeLQYgAPobT",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "372bc24d-4510-4eb2-9ef5-fbaba46e18fc",
      "name": "在提及的频道中发送结果",
      "type": "n8n-nodes-base.slack",
      "position": [
        -2160,
        992
      ],
      "webhookId": "9e363320-9c63-4ed9-9438-31d5fdc030c9",
      "parameters": {
        "text": "=<@{{ $json.id }}> {{ $('Code Of Conduct Agent').item.json.output }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Webhook').item.json.body.event.channel }}"
        },
        "otherOptions": {
          "mrkdwn": true
        }
      },
      "credentials": {
        "slackApi": {
          "id": "3MfZsxrz9SluxmDt",
          "name": "COC Bot"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "a9a7c510-4b00-4fcb-988a-f6b126a9564a",
      "name": "获取用户信息",
      "type": "n8n-nodes-base.slack",
      "position": [
        -2384,
        992
      ],
      "webhookId": "4b89e5a8-34cc-4d7b-a91b-465e7a864875",
      "parameters": {
        "user": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Webhook').item.json.body.event.user }}"
        },
        "resource": "user",
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "id": "4JSKt9sIRV1KGswQ",
          "name": "Slack account"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "5821abdb-fba3-47fd-986e-29e0282855ee",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -4928,
        592
      ],
      "parameters": {
        "color": 4,
        "width": 1056,
        "height": 2144,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "e06f197d-f4e7-4e29-96c9-5c44dea773d5",
      "name": "默认数据加载器",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -3216,
        1608
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1.1
    },
    {
      "id": "24bb84e8-1ab4-42d9-9e8e-088590882f45",
      "name": "将数据插入存储",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        -3312,
        1384
      ],
      "parameters": {
        "mode": "insert",
        "memoryKey": {
          "__rl": true,
          "mode": "list",
          "value": "vector_store_key",
          "cachedResultName": "vector_store_key"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "de57e328-271a-42a5-914a-073ee5762a54",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        -3224,
        1784
      ],
      "parameters": {
        "jsCode": "const data = $input.item.json;\nconst binaryData = $input.item.binary;\n\nlet output = [];\n\nObject.keys(binaryData)\n  .filter(label => label.startsWith(\"CV_\"))\n  .forEach(label => {\n    output.push({\n      json: data,\n      binary: { data: binaryData[label] }\n    });\n  });\n\nreturn output;"
      },
      "typeVersion": 2
    },
    {
      "id": "264b1310-b80d-4e92-88da-218f261a9687",
      "name": "在此处上传您的 PDF 文档",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -3536,
        1636
      ],
      "webhookId": "82848bc4-5ea2-4e5a-8bb6-3c09b94a8c5d",
      "parameters": {
        "options": {},
        "formTitle": "Upload your data to test RAG",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "Upload your file(s)",
              "requiredField": true,
              "acceptFileTypes": ".pdf"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f1b4fece-cac6-49b7-ad47-a1a8ced08ba9",
      "name": "将文档备份到 Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -2760,
        1784
      ],
      "parameters": {
        "name": "=document-{{ $now.toFormat(\"yyyyLLdd-HHmmss\") }}-{{$binary.data.fileName}}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive",
          "cachedResultName": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1ObNNVJFR2vcKqP8p-ZnX_eaZy4gBHgha",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1ObNNVJFR2vcKqP8p-ZnX_eaZy4gBHgha",
          "cachedResultName": "SmartIT"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "fC471es5gk5Mm900",
          "name": "Google Drive account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "73b5b601-f14a-44d7-9737-7efe05af9fa1",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        -2688,
        1216
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "PPSwAKeLQYgAPobT",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f229958a-af79-4420-a218-0ed18e5562fc",
      "name": "查询数据工具",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        -2784,
        1008
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolName": "knowledge_base",
        "memoryKey": {
          "__rl": true,
          "mode": "list",
          "value": "vector_store_key"
        },
        "toolDescription": "Use this knowledge base to answer questions from the user"
      },
      "typeVersion": 1.2
    },
    {
      "id": "a6310e4a-fcc0-4814-a203-ce38b8daeff6",
      "name": "行为准则 Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -2896,
        784
      ],
      "parameters": {
        "text": "=You are an AI Slack chatbot for Code of Conduct Q&A.\n\nThe user has asked:\n{{ $json.body.event.text }}\n\nYour answer should be clear, professional, and easy for employees to understand.\nIf the information isn’t found in the retrieved content, say: “I couldn’t find an answer to that in the Code of Conduct. Please reach out to HR or the compliance team for clarification.”\n\nRespond in Slack-friendly format (Markdown supported).",
        "options": {
          "systemMessage": "You are an AI assistant trained to help employees understand and comply with the company's Code of Conduct. Your role is to provide clear, accurate, and friendly answers to questions based on the retrieved content from the official Code of Conduct documentation. Always reference the relevant section when possible, and avoid making assumptions beyond the retrieved data.\n\nIf the question cannot be answered from the provided data, politely respond that the information is not available and suggest contacting HR or compliance team for clarification.\n\nFormatting: \n- Use bullet points or numbered lists if helpful\n- Bold key terms or important statements\n- Keep the tone professional yet approachable\n\nNever fabricate information. Only use the content provided in the retrieved chunks."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "executeOnce": true,
      "typeVersion": 2.1
    },
    {
      "id": "3cee5a9d-bf5c-4f8e-bbc2-abfe3087a52a",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1920,
        784
      ],
      "parameters": {
        "width": 1056,
        "height": 560,
        "content": "![](https://wisestackai.s3.ap-southeast-1.amazonaws.com/Screenshot+2025-08-22+at+12.43.33%E2%80%AFPM.png)"
      },
      "typeVersion": 1
    },
    {
      "id": "1235b85c-8ef7-493e-a91b-84e09e09da12",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3616,
        1824
      ],
      "parameters": {
        "height": 224,
        "content": "#### 1. 🟢 上传 PDF 文档"
      },
      "typeVersion": 1
    },
    {
      "id": "263a5ad7-9392-4d37-8a68-eeff78a73379",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3072,
        1568
      ],
      "parameters": {
        "height": 128,
        "content": "#### 2. 📑 解析 PDF 内容"
      },
      "typeVersion": 1
    },
    {
      "id": "159e3edf-f845-49e6-9fdd-ddd7c45f3016",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2544,
        1264
      ],
      "parameters": {
        "height": 256,
        "content": "#### 3. 🧬 生成嵌入(OpenAI)"
      },
      "typeVersion": 1
    },
    {
      "id": "559c1f98-3af4-46ef-9207-dbda744d8a48",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2544,
        1760
      ],
      "parameters": {
        "content": "#### 4. ☁️ 备份到 Google Drive"
      },
      "typeVersion": 1
    },
    {
      "id": "b5144bb8-087c-4563-8095-8b1aa7b8c15c",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3616,
        992
      ],
      "parameters": {
        "color": 7,
        "content": "#### 1. 🟢 Webhook 触发器(Slack 事件)"
      },
      "typeVersion": 1
    },
    {
      "id": "ccc08f58-a7c3-48b1-ab1b-774525644fc4",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3296,
        1024
      ],
      "parameters": {
        "color": 7,
        "height": 128,
        "content": "#### 2. 🧠 消息验证"
      },
      "typeVersion": 1
    },
    {
      "id": "bd562f0a-fab6-4d3b-9712-1adc0af8d720",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3024,
        560
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "content": "#### 3. 🤖 行为准则 Agent(GPT-4 + 查询工具)"
      },
      "typeVersion": 1
    },
    {
      "id": "7e9c0b48-063b-48cf-8ed1-fa902e83cfc8",
      "name": "### 替换 Airtable 连接",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2368,
        784
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 144,
        "content": "#### 5. 💬 Post Response to Slack\n- Fetches user details to personalize the reply.\n- Delivers the final answer back to the mentioned Slack channel, replying to the original message or thread."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {},
  "versionId": "e0003593-074e-4bad-9302-b7c166e9fd92",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Backup document(s) to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Is user message?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "gpt4-1 model": {
      "ai_languageModel": [
        [
          {
            "node": "Code Of Conduct Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Query Data Tool": {
      "ai_tool": [
        [
          {
            "node": "Code Of Conduct Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Is user message?": {
      "main": [
        [
          {
            "node": "Code Of Conduct Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Insert Data to Store",
            "type": "ai_embedding",
            "index": 0
          },
          {
            "node": "Query Data Tool",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Insert Data to Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Code Of Conduct Agent": {
      "main": [
        [
          {
            "node": "Get information about a user",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get information about a user": {
      "main": [
        [
          {
            "node": "Send result in the mentioned channel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload your PDF document here": {
      "main": [
        [
          {
            "node": "Insert Data to Store",
            "type": "main",
            "index": 0
          },
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send result in the mentioned channel": {
      "main": [
        []
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - AI RAG 检索增强, 多模态 AI

需要付费吗?

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

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

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

作者
Trung Tran

Trung Tran

@trungtran

Empowering small and medium businesses with smart automation and practical AI, no big tech team required.

外部链接
在 n8n.io 查看

分享此工作流