{
  "name": "Whatsapp automation (mahirmunaj.com)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "whatsapp",
        "options": {}
      },
      "id": "7dd35d11-1131-5fe2-88c7-a754a8bfff20",
      "name": "WhatsApp message (Webhook)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "from",
              "value": "={{ $json.body.entry[0].changes[0].value.messages[0].from }}",
              "type": "string"
            },
            {
              "id": "2",
              "name": "text",
              "value": "={{ $json.body.entry[0].changes[0].value.messages[0].text.body }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "9ec6a245-85e0-527a-b6e8-0b5569b05252",
      "name": "Extract message",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'gpt-4o-mini', temperature: 0.3, messages: [ { role: 'system', content: \"You answer WhatsApp questions for a small business. Use ONLY this FAQ; if the answer isn't there, say a team member will reply soon. Keep replies under 60 words. FAQ: [paste your hours, prices, services, address and booking link here]\" }, { role: 'user', content: $json.text } ] }) }}",
        "options": {}
      },
      "id": "81b29a3e-05d3-5619-a47c-22f8666a3a29",
      "name": "AI answer from FAQ",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://graph.facebook.com/v21.0/YOUR_PHONE_NUMBER_ID/messages",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_WHATSAPP_TOKEN"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ messaging_product: 'whatsapp', to: $('Extract message').item.json.from, type: 'text', text: { body: $json.choices[0].message.content } }) }}",
        "options": {}
      },
      "id": "0da1b8e5-b646-5e89-ba98-bc4fceba693f",
      "name": "Send WhatsApp reply",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        300
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "WhatsApp"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "from": "={{ $('Extract message').item.json.from }}",
            "question": "={{ $('Extract message').item.json.text }}"
          }
        },
        "options": {}
      },
      "id": "42f447d7-7771-52e1-b0de-52a8e1c1b3c7",
      "name": "Log conversation",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        880,
        300
      ]
    }
  ],
  "connections": {
    "WhatsApp message (Webhook)": {
      "main": [
        [
          {
            "node": "Extract message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract message": {
      "main": [
        [
          {
            "node": "AI answer from FAQ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI answer from FAQ": {
      "main": [
        [
          {
            "node": "Send WhatsApp reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp reply": {
      "main": [
        [
          {
            "node": "Log conversation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "https://mahirmunaj.com/templates/n8n-whatsapp-ai-auto-reply-workflow"
  }
}