{
  "id": "nF9AWrKj7US3Puqb",
  "meta": {
    "builderVariant": "mcp",
    "aiBuilderAssisted": true
  },
  "name": "Handle e-commerce customer support on WhatsApp with AI, WooCommerce and Notion",
  "tags": [],
  "nodes": [
    {
      "id": "0d72af7c-f04e-4485-a348-948298bd1b6e",
      "name": "Receive WhatsApp Message (Whapi)",
      "type": "n8n-nodes-base.webhook",
      "position": [
        464,
        416
      ],
      "parameters": {
        "path": "ecommerce-support-whatsapp",
        "options": {
          "ignoreBots": true
        },
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "593dab22-a55f-4675-8e63-d558b9ce5a68",
      "name": "Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        656,
        416
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "cfg-openai-model",
              "name": "openai_model",
              "type": "string",
              "value": "gpt-5-mini"
            },
            {
              "id": "cfg-context-window",
              "name": "context_window_length",
              "type": "number",
              "value": 10
            },
            {
              "id": "cfg-max-iterations",
              "name": "max_agent_iterations",
              "type": "number",
              "value": 10
            },
            {
              "id": "cfg-support-scope",
              "name": "support_scope",
              "type": "string",
              "value": "order status and tracking, product availability and pricing, shipping and returns policy, and basic technical troubleshooting for our e-commerce store"
            },
            {
              "id": "cfg-jailbreak-threshold",
              "name": "jailbreak_threshold",
              "type": "number",
              "value": 0.7
            },
            {
              "id": "cfg-nsfw-threshold",
              "name": "nsfw_threshold",
              "type": "number",
              "value": 0.7
            },
            {
              "id": "cfg-topical-threshold",
              "name": "topical_threshold",
              "type": "number",
              "value": 0.6
            },
            {
              "id": "cfg-notification-email",
              "name": "notification_email",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Email address of the human support manager who receives escalations__>"
            },
            {
              "id": "cfg-text-only-reply",
              "name": "text_only_reply",
              "type": "string",
              "value": "Hello! For now I can only read text messages \ud83d\ude42 Could you send your question as text?"
            },
            {
              "id": "cfg-policy-violation-reply",
              "name": "policy_violation_reply",
              "type": "string",
              "value": "Sorry, I can't help with that request. If you think this is a mistake, please contact our support team directly."
            },
            {
              "id": "cfg-customer-phone",
              "name": "customer_phone",
              "type": "string",
              "value": "={{ $json.body?.messages?.[0]?.from ?? \"\" }}"
            },
            {
              "id": "cfg-message-type",
              "name": "message_type",
              "type": "string",
              "value": "={{ $json.body?.messages?.[0]?.type ?? \"unknown\" }}"
            },
            {
              "id": "cfg-message-text",
              "name": "message_text",
              "type": "string",
              "value": "={{ $json.body?.messages?.[0]?.text?.body ?? \"\" }}"
            },
            {
              "id": "cfg-message-id",
              "name": "message_id",
              "type": "string",
              "value": "={{ $json.body?.messages?.[0]?.id ?? \"\" }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ddb1f00d-2d32-4eb5-a901-867ab14c1156",
      "name": "Is Text Message?",
      "type": "n8n-nodes-base.if",
      "position": [
        928,
        416
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.message_type }}",
              "rightValue": "text"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "a02c03a8-2abb-4706-b8aa-f4c8fd080269",
      "name": "Guardrails: Check Message Safety",
      "type": "@n8n/n8n-nodes-langchain.guardrails",
      "position": [
        656,
        -48
      ],
      "parameters": {
        "text": "={{ $json.message_text }}",
        "guardrails": {
          "nsfw": {
            "value": {
              "threshold": "={{ $json.nsfw_threshold }}"
            }
          },
          "jailbreak": {
            "value": {
              "threshold": "={{ $json.jailbreak_threshold }}"
            }
          },
          "topicalAlignment": {
            "value": {
              "prompt": "=You are a compliance classifier for a customer support assistant. The assistant may ONLY discuss: {{ $json.support_scope }}. Flag any message asking about unrelated topics as a violation.",
              "threshold": "={{ $json.topical_threshold }}"
            }
          }
        }
      },
      "typeVersion": 2
    },
    {
      "id": "2d8ad11e-6710-4cf2-a9ad-8d9993c4544f",
      "name": "OpenAI Model (Guardrails)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        656,
        176
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Configuration').item.json.openai_model }}"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "1411ff1f-a61e-4837-af68-34be677a20b3",
      "name": "E-Commerce Customer Support Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1472,
        -112
      ],
      "parameters": {
        "text": "={{ $(\"Configuration\").item.json.message_text }}",
        "options": {
          "maxIterations": "={{ $(\"Configuration\").item.json.max_agent_iterations }}",
          "systemMessage": "=You are a friendly, professional AI customer support assistant for an e-commerce store, reachable on WhatsApp.\n\nScope: {{ $(\"Configuration\").item.json.support_scope }}\n\nTOOLS: use \"Search Knowledge Base (Notion)\" for policies, FAQs and troubleshooting guides. Use \"Get Single Order\" / \"List Customer Orders\" for order questions, always fetching real data before answering, never guessing order status. Use \"Get Single Product\" / \"List Products\" for live price and stock, never trust memory for prices. Use \"Get Customer Profile\" to personalize the conversation once you know the customer email. Use \"Calculator\" for any arithmetic (totals, discounts, conversions). Use \"Escalate to Human Support\" whenever the customer asks for a human, the issue is a dispute, fraud, damaged goods, or anything you cannot resolve after a genuine attempt \u2014 tell the customer you are escalating before and after calling the tool.\n\nSTYLE: warm, concise, one clear question at a time when you need more info. Never invent prices, stock, or order statuses \u2014 always use the tools. Never expose internal IDs or raw API data, translate everything into natural language.\n\nKeep replies under 4 short paragraphs, suitable for a WhatsApp message."
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "23ec039f-22ab-4663-971a-7d1ef5783532",
      "name": "OpenAI Model (Agent)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        912,
        224
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Configuration').item.json.openai_model }}"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "115af633-67ec-4eff-af62-53066af3fd87",
      "name": "Conversation Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1056,
        224
      ],
      "parameters": {
        "sessionKey": "={{ $('Configuration').item.json.customer_phone }}",
        "sessionIdType": "customKey",
        "contextWindowLength": "={{ $('Configuration').item.json.context_window_length }}"
      },
      "typeVersion": 1.4
    },
    {
      "id": "e3e8a14a-beaa-429e-ba05-98dd4c6c29b2",
      "name": "Search Knowledge Base (Notion)",
      "type": "n8n-nodes-base.notionTool",
      "position": [
        1216,
        224
      ],
      "parameters": {
        "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('query', 'Search query for the company knowledge base. Use for FAQs, shipping and return policies, warranty info, and troubleshooting guides stored as Notion pages. Do not use for live product price or stock, use the product tools for that.') }}",
        "limit": 5,
        "options": {
          "filter": {
            "filters": {
              "value": "page"
            }
          }
        },
        "operation": "search"
      },
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "fb74ab2a-860c-46be-8821-90edde4c2193",
      "name": "Get Single Order",
      "type": "n8n-nodes-base.wooCommerceTool",
      "position": [
        1376,
        224
      ],
      "parameters": {
        "orderId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('order_id', 'The WooCommerce order ID the customer is asking about, e.g. 4521') }}",
        "resource": "order",
        "operation": "get"
      },
      "typeVersion": 1
    },
    {
      "id": "dbcb7c52-93cb-443a-89c8-2c722fce433f",
      "name": "List Customer Orders",
      "type": "n8n-nodes-base.wooCommerceTool",
      "position": [
        1536,
        224
      ],
      "parameters": {
        "limit": 10,
        "options": {
          "search": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('search', 'Search text to find orders, such as the customer email address or name. Leave empty to list the most recent orders.') }}"
        },
        "resource": "order",
        "operation": "getAll"
      },
      "typeVersion": 1
    },
    {
      "id": "5224611a-3a20-4f18-aad9-a4eeb310c88a",
      "name": "Get Single Product",
      "type": "n8n-nodes-base.wooCommerceTool",
      "position": [
        1712,
        224
      ],
      "parameters": {
        "operation": "get",
        "productId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('product_id', 'The WooCommerce product ID to fetch live price, stock and details for') }}"
      },
      "typeVersion": 1
    },
    {
      "id": "1f5b6ddb-5a23-4b94-a25a-7900890272d6",
      "name": "List Products",
      "type": "n8n-nodes-base.wooCommerceTool",
      "position": [
        1872,
        224
      ],
      "parameters": {
        "limit": 10,
        "options": {
          "search": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('search', 'Search text to find products by name or category, for recommendations or comparisons. Leave empty to list featured/recent products.') }}"
        },
        "operation": "getAll"
      },
      "typeVersion": 1
    },
    {
      "id": "b7296afb-1487-4245-94f5-939dcc9f6f04",
      "name": "Get Customer Profile",
      "type": "n8n-nodes-base.wooCommerceTool",
      "position": [
        2032,
        224
      ],
      "parameters": {
        "limit": 1,
        "filters": {
          "email": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('email', \"The customer's email address, used to look up their account profile and order history\") }}"
        },
        "resource": "customer",
        "operation": "getAll"
      },
      "typeVersion": 1
    },
    {
      "id": "8fd07523-f99b-468c-8af8-d3b1419b892c",
      "name": "Calculator",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "position": [
        2192,
        224
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "dbd2ba4d-f329-44a4-92bd-5785f1ba08b4",
      "name": "Escalate to Human Support",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        2336,
        224
      ],
      "parameters": {
        "sendTo": "={{ $('Configuration').item.json.notification_email }}",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('body', \"Full context for the human agent: the customer's phone number, a summary of the issue, what has already been attempted, and why this needs human attention. Write in clear plain text.\") }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('subject', 'Short subject line summarizing the escalation, e.g. \"WhatsApp escalation: order dispute #4521\"') }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "49ec978c-ad45-4516-8718-c13501c1ad0d",
      "name": "Send WhatsApp Reply",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        2080,
        -112
      ],
      "parameters": {
        "url": "https://gate.whapi.cloud/messages/text",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ { \"to\": $(\"Configuration\").item.json.customer_phone, \"body\": $json.output } }}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.4
    },
    {
      "id": "2c26dbfb-1fec-4fa6-aef5-98bbd21aa3ee",
      "name": "Reply: Policy Violation",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        976,
        16
      ],
      "parameters": {
        "url": "https://gate.whapi.cloud/messages/text",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ { \"to\": $(\"Configuration\").item.json.customer_phone, \"body\": $(\"Configuration\").item.json.policy_violation_reply } }}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.4
    },
    {
      "id": "06e74ae5-9ecb-42cf-b88e-661905b535d6",
      "name": "Reply: Text Only Supported",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        1312,
        560
      ],
      "parameters": {
        "url": "https://gate.whapi.cloud/messages/text",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ { \"to\": $json.customer_phone, \"body\": $json.text_only_reply } }}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.4
    },
    {
      "id": "307e721b-f46e-4b00-b729-e94f049b96c4",
      "name": "Sticky Note 5908cd29",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        -496
      ],
      "parameters": {
        "color": 4,
        "width": 460,
        "height": 1780,
        "content": "# Handle e-commerce customer support on WhatsApp with AI, WooCommerce and Notion\n# \ud83d\udce5  [Open full documentation on Notion](https://automatisation.notion.site/Course-Handle-e-commerce-customer-support-on-WhatsApp-with-AI-WooCommerce-and-Notion-39f3d6550fd98156b224eeea65e06c93)\n\n## How it works\nA customer messages your WhatsApp Business number through Whapi. The workflow checks the message is text, screens it for jailbreaks, NSFW content and off-topic requests with Guardrails, then hands it to an AI Agent that can search your Notion knowledge base, look up live WooCommerce orders/products/customers, do math, and escalate to a human by email when needed. The reply is sent back to the customer on WhatsApp.\n\n## Setup\n1. Create a free Whapi account, connect your WhatsApp number, and copy the webhook URL from this workflow's trigger node into your Whapi channel settings.\n2. Create a \"Whapi\" credential (Bearer Token) in n8n using your Whapi API token.\n3. Create a \"WooCommerce account\" credential (Consumer Key/Secret) from your WooCommerce store REST API settings.\n4. Connect your Notion, OpenAI and Gmail accounts, and add your policies/FAQs as Notion pages the agent can search.\n5. Fill in the \"Configuration\" node: support manager email, and adjust the messages/thresholds if needed.\n\n## Requirements\n- A Whapi account (WhatsApp Business API gateway)\n- A WooCommerce store with REST API keys\n- A Notion workspace with your knowledge base pages\n- An OpenAI account\n- A Gmail account for human escalation\n\n## Customization\nAdjust the system prompt, guardrail thresholds, and the support scope description in \"Configuration\" to fit your store. Add more WooCommerce tools (e.g. create/update order) if you want the agent to take actions, not just look things up.\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": "f3739ded-52a4-47f3-83b5-4d828257b018",
      "name": "Sticky Note 0307c364",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        864
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 200,
        "content": "## STEP 1 - Configuration\nAll adjustable variables in one place: model, thresholds, messages, and the support manager email."
      },
      "typeVersion": 1
    },
    {
      "id": "b4e23385-801b-47f6-8c15-d65726597693",
      "name": "Sticky Note d37de81a",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        944,
        864
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 248,
        "content": "## STEP 2 - Message intake & safety\nOnly text messages are processed. Guardrails blocks jailbreak attempts, NSFW content and off-topic requests before they reach the agent."
      },
      "typeVersion": 1
    },
    {
      "id": "a5d8001b-ed5b-4a9d-a066-27f612b77fd7",
      "name": "Sticky Note a2fc851b",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1296,
        864
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 248,
        "content": "## STEP 3 - AI Support Agent & tools\nSearches the Notion knowledge base, looks up live WooCommerce orders/products/customers, does math, and escalates to a human via email when needed."
      },
      "typeVersion": 1
    },
    {
      "id": "b81c24bf-aff4-4721-8e46-685b2dd03d33",
      "name": "Sticky Note 88c5e38d",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1648,
        864
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 200,
        "content": "## STEP 4 - Reply on WhatsApp\nSends the agent's answer back to the customer through the Whapi API."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": true,
    "executionOrder": "v1"
  },
  "versionId": "accb0392-5e29-43cc-8034-c2d82cee02b2",
  "nodeGroups": [],
  "connections": {
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Configuration": {
      "main": [
        [
          {
            "node": "Is Text Message?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Products": {
      "ai_tool": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Single Order": {
      "ai_tool": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Is Text Message?": {
      "main": [
        [
          {
            "node": "Guardrails: Check Message Safety",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reply: Text Only Supported",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Single Product": {
      "ai_tool": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Conversation Memory": {
      "ai_memory": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Get Customer Profile": {
      "ai_tool": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "List Customer Orders": {
      "ai_tool": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model (Agent)": {
      "ai_languageModel": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Escalate to Human Support": {
      "ai_tool": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model (Guardrails)": {
      "ai_languageModel": [
        [
          {
            "node": "Guardrails: Check Message Safety",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Search Knowledge Base (Notion)": {
      "ai_tool": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Guardrails: Check Message Safety": {
      "main": [
        [
          {
            "node": "E-Commerce Customer Support Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reply: Policy Violation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive WhatsApp Message (Whapi)": {
      "main": [
        [
          {
            "node": "Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "E-Commerce Customer Support Agent": {
      "main": [
        [
          {
            "node": "Send WhatsApp Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}