8
n8n 中文网amn8n.com

基于Gemini AI的WhatsApp虚拟接待员 - 处理文本和语音的知识库系统

高级

这是一个Support Chatbot, AI RAG领域的自动化工作流,包含 18 个节点。主要使用 Set, Code, Switch, WhatsApp, HttpRequest 等节点。 基于Gemini AI的WhatsApp虚拟接待员 - 处理文本和语音的知识库系统

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Gemini API Key
  • Pinecone API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "07df66e33836083697e8bd7e53a57a2a1f404ad7aabcc82daa752a2b5a254167",
    "templateId": "5385"
  },
  "nodes": [
    {
      "id": "ca19699e-15fd-4366-8aa0-2f26a8f0b2bb",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        720,
        496
      ],
      "parameters": {
        "text": "={{ $json.messages[0].text.body }}\n{{ $json.candidates[0].content.parts[0].text }}",
        "options": {
          "systemMessage": "=You are currently talking to {{ $json.contacts[0].profile.name }}.\n\n***IMMEDIATE AND ABSOLUTE RULES:***\n***1. LANGUAGE: Respond ONLY in English. If the user's input is in English, respond in English.\n***2. RESPONSE START: Your response MUST BEGIN DIRECTLY WITH THE ANSWER OR THE PRODUCT RECOMMENDATION. DO NOT USE ANY FORM OF THANK YOU, GREETING, OR ACKNOWLEDGEMENT OF THE USER'S INPUT AT THE START OF YOUR RESPONSE. THIS IS A CRITICAL PROFESSIONAL REQUIREMENT.***\n\nYou are a friendly and professional virtual receptionist for Superclean Middle East Chemicals & Cleaning Materials L.L.C. Your primary function is to provide information about cleaning and hygiene products, take quote requests, guide customers, and collect essential details. You achieve this by directly responding to inquiries.\n\nYou have been provided with relevant information from our knowledge base/vector store to help you answer the user's question. Use this information directly and integrate it seamlessly into your response. Do not acknowledge the source of this information (e.g., \"based on our product information\" or \"from the knowledge base\").\n\n**Regarding Product Recommendations:**\n* **Prioritize a direct product recommendation immediately.** Do not ask multiple clarifying questions upfront.\n* If multiple products *could* match, provide a brief list of the top 2-3 most relevant options based on the initial query.\n* If absolutely necessary to clarify for a *better* recommendation, ask **only one, most crucial question** after providing an initial recommendation. Do not engage in a back-and-forth questioning session.\n\nAlways maintain a polite, business-casual tone with clarity. If you don’t know an answer, redirect or creatively deflect the question while offering help. If a product-specific question is asked that isn't in your script, offer to pass the inquiry to a specialist. Speak clearly and naturally.\nDon't mention \"based on our product information\" to the user.\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "29da8178-4c2b-4da6-87e3-87bbeb51f4d4",
      "name": "Google Gemini聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        656,
        736
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "2CxiwuZKBBT7X4pw",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e48c4c7a-6285-497c-8a65-3d7b132cadee",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        784,
        736
      ],
      "parameters": {
        "sessionKey": "={{ $('WhatsApp Trigger').item.json.contacts[0].wa_id }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 20
      },
      "typeVersion": 1.3
    },
    {
      "id": "9b267a71-5eff-4a09-9b00-26c1924d60f2",
      "name": "使用向量存储回答问题",
      "type": "@n8n/n8n-nodes-langchain.toolVectorStore",
      "position": [
        912,
        736
      ],
      "parameters": {
        "description": "返回与公司信息、产品和服务相关的文档"
      },
      "typeVersion": 1.1
    },
    {
      "id": "56ee6e8c-2087-4b0a-8182-d4e09ca1070f",
      "name": "Pinecone Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        816,
        944
      ],
      "parameters": {
        "options": {},
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "superclean",
          "cachedResultName": "superclean"
        }
      },
      "credentials": {
        "pineconeApi": {
          "id": "MCsQPuVGkm8qJFlq",
          "name": "PineconeApi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "800013cf-a0fc-4fc9-9aab-e7fca168ce07",
      "name": "Google Gemini 聊天模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1104,
        944
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "2CxiwuZKBBT7X4pw",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5356b124-d55b-4a95-bebf-da34d258e4b5",
      "name": "Google Gemini 嵌入",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        896,
        1152
      ],
      "parameters": {},
      "credentials": {
        "googlePalmApi": {
          "id": "2CxiwuZKBBT7X4pw",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "60bbd3ad-9cc5-4314-accf-63443742566f",
      "name": "WhatsApp 触发器",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        -880,
        480
      ],
      "webhookId": "4a234429-953d-4945-ba4c-e2601babf287",
      "parameters": {
        "options": {},
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "id": "c3SMCxa8j0SOP79z",
          "name": "WhatsApp OAuth account Magic"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "62fbdacb-50a4-4ca2-87e1-ecb4277e13fc",
      "name": "获取音频URL",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        -464,
        304
      ],
      "webhookId": "447d8752-1b55-429f-b53e-829af23156b9",
      "parameters": {
        "resource": "media",
        "operation": "mediaUrlGet",
        "mediaGetId": "={{ $json.messages[0].audio.id }}"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "HEJFAbeNaUYGKHZb",
          "name": "WhatsApp account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4e830f8a-a674-4dd7-ad32-39671f5f23cf",
      "name": "音频下载",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -240,
        304
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "nsCa9zmf7PjXTod2",
          "name": "Whatsapp download Auth"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f1d1d1ab-d058-4852-8f74-5ac60a8e49e0",
      "name": "音频提示",
      "type": "n8n-nodes-base.set",
      "position": [
        400,
        304
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "49a3d92d-3bc6-4856-a15e-2ba2afa0ace8",
              "name": "candidates[0].content.parts[0].text",
              "type": "string",
              "value": "={{ $json.candidates[0].content.parts[0].text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "6de808f7-75a9-4bcf-9bb9-c5cacaa4c128",
      "name": "发送消息",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        1312,
        496
      ],
      "webhookId": "3b158ca3-ea29-497e-9002-45422d69490c",
      "parameters": {
        "textBody": "={{ $json.output }}",
        "operation": "send",
        "phoneNumberId": "723548604171403",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('WhatsApp Trigger').item.json.messages[0].from }}"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "9Il95VjdrW30AtrZ",
          "name": "WhatsApp account Magic valley"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "87c6c269-cf17-4645-ac05-0c8872895d00",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1200,
        320
      ],
      "parameters": {
        "color": 4,
        "width": 256,
        "height": 384,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "17502cf4-64bc-4726-83ce-351af9b487b3",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -48
      ],
      "parameters": {
        "color": 3,
        "width": 528,
        "height": 272,
        "content": "🎧 语音消息处理"
      },
      "typeVersion": 1
    },
    {
      "id": "a018416b-d5fe-4509-b5c0-920282eef62d",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        176
      ],
      "parameters": {
        "color": 5,
        "width": 368,
        "height": 224,
        "content": "🧠 AI 代理 + 知识库"
      },
      "typeVersion": 1
    },
    {
      "id": "b47ef7d2-6885-42e5-a37c-b8e1c3d5ecb1",
      "name": "音频/消息",
      "type": "n8n-nodes-base.switch",
      "position": [
        -688,
        480
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Audio",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "5acd4de2-655d-4978-af3a-814f4201c651",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.messages[0].audio }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "94d38699-c1b5-4051-b630-a460edaf4259",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.messages[0].text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "d2038571-24f9-42d7-9412-09c6ad12efa9",
      "name": "音频转换",
      "type": "n8n-nodes-base.code",
      "position": [
        0,
        304
      ],
      "parameters": {
        "jsCode": "const binaryKey = 'data'; // from your node, it's named \"data\"\nconst binaryData = items[0].binary[binaryKey].data;\nconst mimeType = items[0].binary[binaryKey].mimeType || 'audio/ogg';\n\nreturn [\n  {\n    json: {\n      base64Audio: binaryData,\n      mimeType\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "2d5a44f6-7fe5-4363-966f-f8bfb7ad9db4",
      "name": "Gemini 语音转文本",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        208,
        304
      ],
      "parameters": {
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"inlineData\": {\n            \"mimeType\": \"{{ $json.mimeType }}\",\n            \"data\": \"{{ $json.base64Audio }}\"\n          }\n        },\n        {\n          \"text\": \"Transcribe this audio and return only the plain spoken words.\"\n        }\n      ]\n    }\n  ]\n}\n",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.2
    }
  ],
  "pinData": {},
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Audio Prompt": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Audio Convert": {
      "main": [
        [
          {
            "node": "Gemini speech to text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Audio/Message": {
      "main": [
        [
          {
            "node": "Get Audio URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Audio URL": {
      "main": [
        [
          {
            "node": "Audio Download",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Audio Download": {
      "main": [
        [
          {
            "node": "Audio Convert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "Audio/Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini speech to text": {
      "main": [
        [
          {
            "node": "Audio Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Store": {
      "ai_vectorStore": [
        [
          {
            "node": "Answer questions with a vector store",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Answer questions with a vector store",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Answer questions with a vector store": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

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

需要付费吗?

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

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

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

作者
Akshay

Akshay

@akshay6

Automation Engineer

外部链接
在 n8n.io 查看

分享此工作流