{
  "name": "Teiwah AI Agent",
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "inbound",
        "responseMode": "onReceived",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [-336, 208],
      "id": "node-webhook",
      "name": "Teiwah Webhook"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Teiwah Webhook').item.json.body.text }}",
        "options": {
          "systemMessage": "You are a helpful WhatsApp assistant. Reply clearly and concisely."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [-112, 208],
      "id": "node-agent",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": "openrouter/free",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [-104, 432],
      "id": "node-openrouter",
      "name": "OpenRouter Chat Model"
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Teiwah Webhook').item.json.body.chatId }}",
        "contextWindowLength": 25
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [24, 432],
      "id": "node-memory",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.teiwah.cloud/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ chatId: $('Teiwah Webhook').item.json.body.chatId, text: $('AI Agent').item.json.output }) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [240, 208],
      "id": "node-send",
      "name": "Send WhatsApp Reply",
      "credentials": {
        "httpBearerAuth": {
          "id": "Y5h1fJORjcv8FMvU",
          "name": "Teiwah API Key"
        }
      }
    }
  ],
  "connections": {
    "Teiwah Webhook": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send WhatsApp Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  }
}
