{
  "name": "Answer WhatsApp support chats with OpenRouter, Pinecone, Gemini and Gmail",
  "nodes": [
    {
      "id": "d6675c4e-987e-4da5-b574-ce8e8e97d492",
      "name": "WhatsApp Trigger",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "options": {
          "messageStatusUpdates": [
            "deleted"
          ]
        },
        "updates": [
          "messages"
        ]
      },
      "typeVersion": 1
    },
    {
      "id": "6b1a526d-df0a-4c0a-9103-fcbca2f2e410",
      "name": "Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        288,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "business_name",
              "type": "string",
              "value": "Acme Store"
            },
            {
              "id": "a2",
              "name": "support_email",
              "type": "string",
              "value": "user@example.com"
            },
            {
              "id": "a3",
              "name": "chat_model",
              "type": "string",
              "value": "openai/gpt-5-mini"
            },
            {
              "id": "a4",
              "name": "embedding_model",
              "type": "string",
              "value": "models/gemini-embedding-001"
            },
            {
              "id": "a5",
              "name": "knowledge_top_k",
              "type": "number",
              "value": 5
            },
            {
              "id": "a11",
              "name": "memory_window",
              "type": "number",
              "value": 10
            },
            {
              "id": "a6",
              "name": "reply_language",
              "type": "string",
              "value": "the same language the customer wrote in"
            },
            {
              "id": "a7",
              "name": "escalation_notice",
              "type": "string",
              "value": "Thanks for your patience \u2014 I've passed your question to a human agent from our team who will follow up with you shortly."
            },
            {
              "id": "a8",
              "name": "customer_message",
              "type": "string",
              "value": "={{ $json.messages[0].text.body }}"
            },
            {
              "id": "a9",
              "name": "customer_phone",
              "type": "string",
              "value": "={{ $json.messages[0].from }}"
            },
            {
              "id": "a10",
              "name": "whatsapp_phone_number_id",
              "type": "string",
              "value": "={{ $json.metadata.phone_number_id }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.5
    },
    {
      "id": "3a6356a0-e01f-4195-9e47-49602f4d0937",
      "name": "Only incoming text messages",
      "type": "n8n-nodes-base.filter",
      "position": [
        560,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c1",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.customer_message }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "6f55584a-1dbd-41cf-bf18-c294d773a767",
      "name": "AI Support Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        848,
        0
      ],
      "parameters": {
        "text": "={{ $('Configuration').item.json.customer_message }}",
        "options": {
          "maxIterations": 10,
          "systemMessage": "=You are {{ $('Configuration').item.json.business_name }} customer support assistant on WhatsApp. You help customers with clear, friendly, concise answers.\n\nHOW TO ANSWER:\n- ALWAYS call the \"Company knowledge base\" tool first to look up the answer before replying. Base your answer only on what you find there.\n- Reply in {{ $('Configuration').item.json.reply_language }}. Keep it short and easy to read on a phone screen.\n- Never invent policies, prices, or facts that are not in the knowledge base.\n\nWHEN TO ESCALATE TO A HUMAN:\n- If the knowledge base does not contain the answer, OR the customer explicitly asks to talk to a person, OR the request involves a complaint, refund, cancellation, or anything you are unsure about: call the \"Escalate to human support\" tool to email the support team. In that tool, include the customer question, the customer phone number ({{ $('Configuration').item.json.customer_phone }}), and why it needs a human.\n- After escalating, reply to the customer with exactly this message: {{ $('Configuration').item.json.escalation_notice }}\n\nAlways stay polite and professional."
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "3ecf0ca0-9098-4d3e-b897-288efdb88b8b",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        848,
        240
      ],
      "parameters": {
        "model": "={{ $('Configuration').item.json.chat_model }}",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "532ffa2d-0088-4a8b-8ea6-97228f1afebd",
      "name": "Conversation Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1072,
        240
      ],
      "parameters": {
        "sessionKey": "={{ $('WhatsApp Trigger').item.json.messages[\"0\"].from }}",
        "sessionIdType": "customKey",
        "contextWindowLength": "={{ $('Configuration').item.json.memory_window }}"
      },
      "typeVersion": 1.4
    },
    {
      "id": "4f495f74-8bdf-441e-bb22-70a722261b1a",
      "name": "Company knowledge base",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        1280,
        240
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": "={{ $('Configuration').item.json.knowledge_top_k }}",
        "options": {},
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "toolDescription": "Search the company customer-support knowledge base (FAQs, policies, product info, shipping, returns). Always call this first to find the answer to a customer question before replying."
      },
      "typeVersion": 1.3
    },
    {
      "id": "1bceb382-08dd-44d8-82ae-279268d46f53",
      "name": "Gemini Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        1280,
        464
      ],
      "parameters": {
        "modelName": "={{ $('Configuration').item.json.embedding_model }}"
      },
      "typeVersion": 1
    },
    {
      "id": "6b676b70-13f9-4ba4-b1d1-6775254a0b4d",
      "name": "Escalate to human support",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        1616,
        240
      ],
      "parameters": {
        "sendTo": "={{ $('Configuration').item.json.support_email }}",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('body', 'The full customer question, the customer WhatsApp number, and a short explanation of why this needs a human agent') }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('subject', 'A short subject line summarizing the customer issue that needs a human') }}",
        "emailType": "text"
      },
      "typeVersion": 2.2
    },
    {
      "id": "e2af9b20-ada4-4845-bb72-ad785d0fd118",
      "name": "Send WhatsApp reply",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        1872,
        0
      ],
      "parameters": {
        "textBody": "={{ $json.output }}",
        "operation": "send",
        "phoneNumberId": "={{ $('Configuration').item.json.whatsapp_phone_number_id }}",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('Configuration').item.json.customer_phone }}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "425a94a1-f2c4-40b0-95a7-4b0c37394eb9",
      "name": "Sticky Note - Overview & setup",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        -464
      ],
      "parameters": {
        "color": 4,
        "width": 684,
        "height": 2064,
        "content": "# Answer WhatsApp support chats from a Pinecone knowledge base with human escalation\n# \ud83d\udce5  [Open full documentation on Notion](https://automatisation.notion.site/3b73d6550fd9811ba6e9d33642c2fcab)\n\n## How it works\nA customer messages your WhatsApp Business number. The AI Support Agent searches your Pinecone knowledge base (embeddings by Google Gemini) and answers only from that verified content, so it never invents a policy or a price. If it cannot find the answer, or the customer asks for a human, or the request is a complaint, refund or cancellation, the agent emails your support team and tells the customer that a person will follow up. The reply goes back over WhatsApp, and the conversation is remembered per phone number.\n\nCanvas map, left to right:\n1. Receive the message & configure\n2. AI support agent (RAG + escalation)\n3. Reply on WhatsApp\n\n## Setup\n1. Select your WhatsApp credentials on **WhatsApp Trigger** and **Send WhatsApp reply** (same phone number).\n2. Select your OpenRouter credential on **OpenRouter Chat Model**.\n3. Create a Pinecone credential and an index, load your FAQ and policy documents into it, then select that index on **Company knowledge base**.\n4. Select your Google Gemini credential on **Gemini Embeddings**. The embedding model must match the one used to load your documents, otherwise the search returns nothing.\n5. Select your Gmail credential on **Escalate to human support**.\n6. Open **Configuration** and set `business_name`, `support_email`, `chat_model` and `reply_language`.\n\n## Requirements\n- A WhatsApp Business Cloud (Meta) account with a phone number.\n- An OpenRouter API key.\n- A Pinecone account with an index already populated with your support content.\n- A Google Gemini API key for the embeddings.\n- A Gmail account to receive the escalation emails.\n\n## Customization\n- Every adjustable value lives in **Configuration**: models, reply language, support email, Top-K, memory window and the escalation notice sent to the customer.\n- Change `chat_model` to any OpenRouter model id to swap the brain without touching a node.\n- Tune how eagerly the bot escalates by editing the system message of **AI Support Agent**.\n- Raise `knowledge_top_k` if answers feel incomplete, lower it if the agent drifts off topic.\n\nThe agent answers from your knowledge base only, but it is still an AI: review the escalation emails to see what it could not handle.\n\n---\nNeed help customizing?\nContact me for consulting and support : [Linkedin](https://www.linkedin.com/in/doctor-firass/)\n\n# MY NEW YOUTUBE CHANNEL\n\ud83d\udc49 [Subscribe to my new YouTube channel](https://www.youtube.com/@DrFiras_AI). Here I'll share videos and Shorts with practical tutorials and FREE templates for n8n.\n\n[![The AI Doctor](https://www.dr-firas.com/the-ai-doctor.png)](https://www.youtube.com/@DrFiras_AI)"
      },
      "typeVersion": 1
    },
    {
      "id": "628593b7-5fc6-4094-88ad-6f8b71348b27",
      "name": "Sticky Note - Step 1 Receive & configure",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 860,
        "height": 340,
        "content": "## 1. Receive the message & configure\nThe trigger fires on incoming WhatsApp messages. **Configuration** centralises every setting: models, support email, reply language, memory window. The filter keeps only real text messages, so a status update or an empty payload never wakes the agent."
      },
      "typeVersion": 1
    },
    {
      "id": "471baa67-39e2-41dd-8bcc-3aea2a62db38",
      "name": "Sticky Note - Step 2 AI agent",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 920,
        "height": 800,
        "content": "## 2. AI support agent (RAG + escalation)\nThe agent searches the Pinecone knowledge base through the Gemini embeddings, remembers the conversation per phone number, and answers only from what it finds. When it cannot answer, or the customer asks for a person, it emails the support team instead of improvising."
      },
      "typeVersion": 1
    },
    {
      "id": "953ba8a0-846b-44cb-ac98-040b7ec277a4",
      "name": "Sticky Note - Step 3 WhatsApp reply",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1792,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 280,
        "height": 340,
        "content": "## 3. Reply on WhatsApp\nThe agent's answer is sent back to the customer on the same WhatsApp number."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Configuration": {
      "main": [
        [
          {
            "node": "Only incoming text messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Support Agent": {
      "main": [
        [
          {
            "node": "Send WhatsApp reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Company knowledge base",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Conversation Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Support Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Support Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Company knowledge base": {
      "ai_tool": [
        [
          {
            "node": "AI Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Escalate to human support": {
      "ai_tool": [
        [
          {
            "node": "AI Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Only incoming text messages": {
      "main": [
        [
          {
            "node": "AI Support Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "instanceId": null
  },
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": true,
    "executionOrder": "v1"
  }
}