8
n8n 中文网amn8n.com

基于Supabase、Gemini 2.5 Flash和OpenAI嵌入的WhatsApp RAG聊天机器人

高级

这是一个Support Chatbot, AI RAG领域的自动化工作流,包含 17 个节点。主要使用 Switch, WhatsApp, HttpRequest, Agent, WhatsAppTrigger 等节点。 基于Supabase、Gemini 2.5 Flash和OpenAI嵌入的WhatsApp RAG聊天机器人

前置要求
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
  • Google Gemini API Key
  • Supabase URL 和 API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "InxpOwOAX7qfXIvX",
  "meta": {
    "instanceId": "9c8f658dbece48b519a8ad7757c7d7db7a30c5f3fd29c9dc8afae32fe0c7711a",
    "templateCredsSetupCompleted": true
  },
  "name": "基于 Supabase、Gemini 2.5 Flash 和 OpenAI 嵌入的 WhatsApp RAG 聊天机器人",
  "tags": [],
  "nodes": [
    {
      "id": "d02befa0-18c6-4aa6-8c94-e84f6993a406",
      "name": "从 Supabase 检索上下文",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        480,
        496
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        },
        "toolDescription": "call this tool to reach the goal"
      },
      "credentials": {
        "supabaseApi": {
          "id": "QkeJlJh5cCiuLpvg",
          "name": "Supabase account"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "0a1543fa-c9ce-4d7a-8466-c778bb532cf9",
      "name": "新的 WhatsApp 消息",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        -304,
        560
      ],
      "webhookId": "ec046705-b8f2-4b88-9b98-4fd99975f432",
      "parameters": {
        "options": {},
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "id": "yVPQQ9GPjNKE9nkZ",
          "name": "whatsApp_OAuth_api"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "79a849a1-da91-4af8-9ba4-7e6e504e4eeb",
      "name": "检查是查询还是文档",
      "type": "n8n-nodes-base.switch",
      "position": [
        -48,
        560
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "query",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "dcd448ce-72f0-4c83-b721-3417a746473e",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.messages[0].text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "document",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "8b2b9810-08c7-452f-a2e0-ba1453586919",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.messages[0].document }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "50a072f5-e8ce-4eae-adf9-8fbf4fd494da",
      "name": "将文件转换为文本",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1008,
        1216
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1.1
    },
    {
      "id": "3932f7f3-524e-40b1-87dd-c9ff1e85d95e",
      "name": "生成 OpenAI 嵌入",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        816,
        1216
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "GVGOwCYLGI5SaqsK",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "75f6cdb9-ef4f-43cd-83ae-b8ceb602b876",
      "name": "将嵌入存储到 Supabase",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        896,
        928
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        }
      },
      "credentials": {
        "supabaseApi": {
          "id": "QkeJlJh5cCiuLpvg",
          "name": "Supabase account"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "d569775f-c2d0-4c12-bb89-fe36667de6ce",
      "name": "Google Gemini LLM",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        352,
        496
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "SuWwLWBsAfrDFgCm",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ee2b82a8-cd95-4ff0-8e42-3d67eedd848d",
      "name": "RAG 查询代理",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        368,
        272
      ],
      "parameters": {
        "text": "={{ $json.messages[0].text }}",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "8eeb7e2c-11de-4ea5-8287-3ef026427f3d",
      "name": "发送 WhatsApp 回复",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        912,
        272
      ],
      "webhookId": "e5e2f982-af07-4274-8937-88ef5109e71b",
      "parameters": {
        "textBody": "={{ $json.output }}",
        "operation": "send",
        "phoneNumberId": "768049963047541",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('New WhatsApp Message').item.json.contacts[0].wa_id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "LV22R0NzX9vZLEp9",
          "name": "whatsapp_reply"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a73408a1-1ea2-4867-9c3d-8b6d54989d7d",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        736
      ],
      "parameters": {
        "color": 7,
        "width": 960,
        "height": 384,
        "content": "## 文档流程:"
      },
      "typeVersion": 1
    },
    {
      "id": "1281e915-20c7-462e-9416-c980a14790c6",
      "name": "便签 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        80
      ],
      "parameters": {
        "color": 7,
        "width": 560,
        "height": 544,
        "content": "## 查询流程:"
      },
      "typeVersion": 1
    },
    {
      "id": "9a40bc48-1dbe-4ed9-9a7e-d6bf86b2e935",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        432
      ],
      "parameters": {
        "color": 7,
        "height": 304,
        "content": "## 消息检查:"
      },
      "typeVersion": 1
    },
    {
      "id": "72e122e4-f577-43ef-bf2e-e51712ef7bd9",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1168,
        208
      ],
      "parameters": {
        "width": 800,
        "height": 832,
        "content": "## 试试看!"
      },
      "typeVersion": 1
    },
    {
      "id": "7698302b-cba7-43ed-abbb-c6c036cd1380",
      "name": "获取文档 URL",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        288,
        928
      ],
      "webhookId": "39934341-fa40-46c5-8c26-9aa2f2b3ffcf",
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].document.id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "LV22R0NzX9vZLEp9",
          "name": "whatsapp_reply"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9eb653ec-15c8-4854-b841-7151efe2cf9d",
      "name": "下载 WhatsApp 文档",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        560,
        928
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "y4by5K1yYvLIIf84",
          "name": "whatsapp"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "e0621b81-844e-4427-bee2-38ebbe0bd734",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1296,
        736
      ],
      "parameters": {
        "width": 336,
        "height": 832,
        "content": "## 文档上传流程"
      },
      "typeVersion": 1
    },
    {
      "id": "001539b5-1ea9-4656-ad10-bf07cb77393b",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1104,
        -192
      ],
      "parameters": {
        "width": 336,
        "height": 848,
        "content": "## 上下文答案流程"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "daa23c09-b671-4bb3-b3c3-f84193cf0ad6",
  "connections": {
    "RAG Query Agent": {
      "main": [
        [
          {
            "node": "Send WhatsApp Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Document URL": {
      "main": [
        [
          {
            "node": "Download WhatsApp Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini LLM": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Query Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Convert File to Text": {
      "ai_document": [
        [
          {
            "node": "Store Embeddings in Supabase",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "New WhatsApp Message": {
      "main": [
        [
          {
            "node": "Check if Query or Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Query or Document": {
      "main": [
        [
          {
            "node": "RAG Query Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Document URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download WhatsApp Document": {
      "main": [
        [
          {
            "node": "Store Embeddings in Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate OpenAI Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Store Embeddings in Supabase",
            "type": "ai_embedding",
            "index": 0
          },
          {
            "node": "Retrieve Context from Supabase",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Store Embeddings in Supabase": {
      "main": [
        []
      ]
    },
    "Retrieve Context from Supabase": {
      "ai_tool": [
        [
          {
            "node": "RAG Query Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 客服机器人, AI RAG 检索增强

需要付费吗?

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

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

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

作者
Manav Desai

Manav Desai

@manavdesai17

Exploring AI and automation with n8n. Here to share builds, learn from the community, and create useful workflows together.

外部链接
在 n8n.io 查看

分享此工作流