{
  "name": "WhatsApp Auto Reply with AI",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "whatsapp-webhook",
        "responseMode": "onReceived",
        "responseData": "allEntries"
      },
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "name": "WhatsApp Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [250, 300]
    },
    {
      "parameters": {
        "model": "gpt-4o-mini",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are a helpful customer support assistant. Reply concisely in the same language as the user message."
            },
            {
              "role": "user",
              "content": "={{ $json.body.messages[0].text.body }}"
            }
          ]
        },
        "options": {
          "maxTokens": 500,
          "temperature": 0.7
        }
      },
      "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "name": "OpenAI Chat",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.2,
      "position": [500, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v18.0/{{ $env.WHATSAPP_PHONE_ID }}/messages",
        "authentication": "genericCredentialType",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.WHATSAPP_TOKEN }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "messaging_product",
              "value": "whatsapp"
            },
            {
              "name": "to",
              "value": "={{ $('WhatsApp Webhook').item.json.body.messages[0].from }}"
            },
            {
              "name": "type",
              "value": "text"
            },
            {
              "name": "text",
              "value": "={{ JSON.stringify({body: $json.choices[0].message.content}) }}"
            }
          ]
        }
      },
      "id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
      "name": "Send WhatsApp Reply",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [750, 300]
    }
  ],
  "connections": {
    "WhatsApp Webhook": {
      "main": [[{"node": "OpenAI Chat", "type": "main", "index": 0}]]
    },
    "OpenAI Chat": {
      "main": [[{"node": "Send WhatsApp Reply", "type": "main", "index": 0}]]
    }
  },
  "settings": {"executionOrder": "v1"},
  "staticData": null,
  "tags": []
}
