Build N8N Whatsapp Chatbot! [Simple Method]

Use following key in Window Buffer Memory:

{{ $('WhatsApp Msg').item.json.contacts[0].wa_id }}|

Copy and paste following to get a complete chatbot Workflow

{
  "name": "WhatsApp Chatbot",
  "nodes": [
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.messages[0].text.body }}",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        440,
        0
      ],
      "id": "604cccd0-65e6-4ef8-9606-83ba508738ba",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "modelName": "models/gemini-2.0-flash-lite-001",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        420,
        200
      ],
      "id": "c6f661c4-d8b3-43ec-b121-4c618dac9b47",
      "name": "Google Gemini Chat Model",
      "credentials": {
        "googlePalmApi": {
          "id": "Gc8tUGF1e3gZ0HAc",
          "name": "Google Gemini(PaLM) Api account 2"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('WhatsApp Msg').item.json.contacts[0].wa_id }}|"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        560,
        200
      ],
      "id": "71693488-1a74-49d5-a550-685b4b192f33",
      "name": "Window Buffer Memory"
    },
    {
      "parameters": {
        "updates": [
          "messages"
        ]
      },
      "type": "n8n-nodes-base.whatsAppTrigger",
      "typeVersion": 1,
      "position": [
        -80,
        0
      ],
      "id": "9b119aba-6826-420e-84a1-68b8d65b0db5",
      "name": "WhatsApp Msg",
      "webhookId": "68c2def0-63f4-4618-902f-8b3eacd9dc7c",
      "credentials": {
        "whatsAppTriggerApi": {
          "id": "VdB2t6VoilgbmYIt",
          "name": "WhatsApp OAuth account 2"
        }
      }
    },
    {
      "parameters": {
        "operation": "send",
        "phoneNumberId": "619100544628812",
        "recipientPhoneNumber": "+1 (917) 730-2010",
        "textBody": "={{ $json.output }}",
        "additionalFields": {},
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        800,
        0
      ],
      "id": "f60e08e0-e6f4-4dd7-afc7-53d8078cee5c",
      "name": "WhatsApp Business Cloud",
      "credentials": {
        "whatsAppApi": {
          "id": "oe5Pyps3hOX4A2u5",
          "name": "WhatsApp account 2"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "37d858ae-cc06-4155-815f-fdc7f5eefb42",
              "leftValue": "={{ $json.messages[0].type }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        140,
        0
      ],
      "id": "123216ca-ac48-471a-990b-47faeccd8530",
      "name": "If"
    }
  ],
  "pinData": {},
  "connections": {
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "WhatsApp Msg": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "WhatsApp Business Cloud",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "3504d794-a43b-4ca2-9a9a-895a34082600",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "17d78cca3fac12a3987a8eb6a1fbe04ffab47bc61da1211a8ec4371fed6b9f91"
  },
  "id": "mDZGv3vQUCCljBkN",
  "tags": []
}
5/5 - (5 votes)

About

Leave a Comment

Your email address will not be published. Required fields are marked *