{
  "name": "WABridges: AI assistant on WhatsApp",
  "nodes": [
    {
      "parameters": {
        "content": "## AI assistant on your WhatsApp number\n\nAnswers every direct message on a WhatsApp number with an AI Agent that remembers each conversation. Groups and your own messages are ignored.\n\n**How it works**\n\n**WhatsApp message received** (Webhook) → **Settings** → **Direct message from someone else?** → **AI Agent** (OpenAI chat model + per-chat memory keyed by `chat_id`) → **Send reply**.\n\n**Setup**\n\n1. Create a WABridges account (free trial, no card): https://wabridges.com\n2. Dashboard → API key → create one. In n8n add a **Header Auth** credential named `WABridges API key`: name `Authorization`, value `Bearer sk_...`\n3. On the dashboard find the bridge's *Webhook secret*. In n8n add a second **Header Auth** credential named `WABridges webhook secret`: name `Authorization`, value `Bearer whsec_...`. Select it in **WhatsApp message received**.\n4. Add your OpenAI credential to **OpenAI Chat Model** (or replace the node with Anthropic, Gemini, Ollama... any chat model node plugs into the same slot).\n5. Edit the system message in **AI Agent** so it knows your business.\n6. Activate, copy the Webhook node's **Production URL**, paste it into the bridge's *Webhook URL* on the dashboard.\n7. Test with the sandbox first (`customer_ref` = `sandbox`): send a message with the *Send a WhatsApp message* workflow and watch Alice and the agent talk. The sandbox pauses the loop after a few rounds.\n8. Going live: set `customer_ref` to your real bridge and swap the webhook secret credential.\n\nGuide with screenshots-free, field-by-field instructions: https://wabridges.com/guides/whatsapp-n8n",
        "width": 640,
        "height": 760,
        "color": 4
      },
      "id": "b0e9c1a7-8a17-5148-9dab-fb453040763b",
      "name": "About this workflow",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1000,
        -460
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "wabridges",
        "authentication": "headerAuth",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "c6926736-2cca-5503-9689-ea73a42bfa41",
      "name": "WhatsApp message received",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -200,
        0
      ],
      "webhookId": "8ea3a7ac-24aa-5925-948e-bcf2b0169e36",
      "credentials": {
        "httpHeaderAuth": {
          "id": "wabridges-webhook-secret",
          "name": "WABridges webhook secret"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c3383a47-dace-5e2e-96fe-e2a0997acdeb",
              "name": "customer_ref",
              "value": "sandbox",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "afa14d2d-2b71-550c-9685-dbe31ffd1f6c",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        40,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "67e4ab2c-60fd-5bf8-90f0-74f51d0c7ed2",
              "leftValue": "={{ $json.body.event }}",
              "rightValue": "message",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "c7dd7430-a6fd-5bbb-842a-b4f3d2b7d0a5",
              "leftValue": "={{ $json.body.from_me }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            },
            {
              "id": "b4227269-7530-5b82-9ade-f2f19c86be38",
              "leftValue": "={{ $json.body.is_group }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            },
            {
              "id": "b547c042-82ff-5326-9a28-db3b17586b0f",
              "leftValue": "={{ $json.body.body }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "fece0c2c-2ea4-584b-b07f-55663d103aa9",
      "name": "Direct message from someone else?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        280,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.body.body }}",
        "options": {
          "systemMessage": "You are the WhatsApp assistant for ACME Bikes, a bicycle repair shop. Be brief and friendly; WhatsApp messages should be one to three sentences. Answer questions about opening hours (Mon-Sat 9-18), services (repairs, tune-ups from $40, e-bike servicing) and how to book (reply with a preferred day). If you cannot help, say a human will follow up. Never invent prices beyond those listed."
        }
      },
      "id": "1682c177-876f-5e51-a24e-922df735ffec",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        560,
        -60
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "id": "af4bb353-baa0-5b27-846e-1ffb9e65061e",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        480,
        180
      ],
      "credentials": {
        "openAiApi": {
          "id": "openai",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Settings').item.json.body.chat_id }}",
        "contextWindowLength": 10
      },
      "id": "5040aff9-d9ca-540f-8179-cbe30f608f89",
      "name": "Conversation memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        680,
        180
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://wabridges.com/api/instances/{{ $('Settings').item.json.customer_ref }}/proxy/send/text",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ chat: $('Settings').item.json.body.chat_id, body: $json.output }) }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "={{ $execution.id }}-{{ $('Settings').item.json.body.message_id }}"
            }
          ]
        }
      },
      "id": "e0b3ad21-1c1b-5eb9-9d96-1f1cae7c4c5b",
      "name": "Send reply",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        920,
        -60
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "wabridges-api-key",
          "name": "WABridges API key"
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000,
      "notesInFlow": true,
      "notes": "POST /api/instances/{customer_ref}/proxy/send/text"
    },
    {
      "parameters": {
        "content": "### Make it yours\n\n- **System message** in AI Agent: your business, tone, what it must not do.\n- **Tools**: attach any n8n tool node to the agent (Google Sheets lookup, Call n8n Workflow, HTTP Request Tool) so it can check orders or book appointments.\n- **Memory** is keyed by `chat_id`; raise `contextWindowLength` for longer conversations.\n- **Human handoff**: add an IF after the agent, e.g. when the output contains `HANDOFF`, and send yourself a WhatsApp message instead.",
        "width": 460,
        "height": 300
      },
      "id": "06d0e77f-9b61-5bc5-ac4b-39de9c09d94a",
      "name": "Make it yours",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        520,
        -420
      ]
    },
    {
      "parameters": {
        "content": "### Webhook payload\n\nUnder `$json.body`: `event`, `body`, `chat_id`, `phone`, `name`, `from_me`, `is_group`, `message_id`, `timestamp`, `media_type`, `caption`.\n\nFull list: https://wabridges.com/docs/webhooks",
        "width": 380,
        "height": 250
      },
      "id": "13775185-6a7c-5a6b-88f3-b493268286c9",
      "name": "Incoming event fields",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -260,
        -320
      ]
    }
  ],
  "connections": {
    "WhatsApp message received": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Direct message from someone else?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Direct message from someone else?": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Conversation memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "active": false
}