{
  "name": "WhatsApp LLaMA 3 Chatbot (Twilio)",
  "nodes": [
    {
      "parameters": {
        "path": "whatsapp",
        "method": "POST",
        "responseMode": "lastNode"
      },
      "id": "1",
      "name": "Webhook - WhatsApp Input",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [200, 300]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "http://localhost:11434/api/generate",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={\n  \"model\": \"llama3\",\n  \"prompt\": \"{{$json[\"Body\"]}}\",\n  \"stream\": false\n}"
      },
      "id": "2",
      "name": "Ask LLaMA 3",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [400, 300]
    },
    {
      "parameters": {
        "functionCode": "const res = JSON.parse(items[0].json.body);\nreturn [{\n  json: {\n    to: $json[\"From\"],\n    body: res.response.trim()\n  }\n}];"
      },
      "id": "3",
      "name": "Prepare Twilio Reply",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [600, 300]
    },
    {
      "parameters": {
        "authentication": "predefinedCredentialType",
        "url": "=https://api.twilio.com/2010-04-01/Accounts={{$env.TWILIO_SID}}/Messages.json",
        "options": {},
        "bodyParameters": {
          "body": "={{$json[\"body\"]}}",
          "from": "whatsapp:{{$env.TWILIO_NUMBER}}",
          "to": "={{$json[\"to\"]}}"
        }
      },
      "id": "4",
      "name": "Send via Twilio",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [800, 300],
      "credentials": {
        "httpBasicAuth": {
          "id": "twilio-auth",
          "name": "Twilio API"
        }
      }
    }
  ],
  "connections": {
    "Webhook - WhatsApp Input": {
      "main": [
        [
          {
            "node": "Ask LLaMA 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ask LLaMA 3": {
      "main": [
        [
          {
            "node": "Prepare Twilio Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Twilio Reply": {
      "main": [
        [
          {
            "node": "Send via Twilio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {},
  "version": 1
}
