{
  "name": "WhatsApp AI Agent - Order Management",
  "nodes": [
    {
      "parameters": {
        "path": "whatsapp-webhook",
        "authentication": "headerAuth",
        "headerAuth": {
          "secretKey": "your-secret-key-here"
        },
        "options": {}
      },
      "id": "whatsapp-trigger",
      "name": "WhatsApp Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "{{ $json.data.sender }}",
        "startingMessage": "",
        "schemaExample": "{\n  \"messageText\": \"What's the status of my order?\",\n  \"customerId\": \"123\"\n}",
        "memory": "long",
        "model": "gpt-4o-mini",
        "options": {}
      },
      "id": "ai-agent",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1,
      "position": [
        500,
        300
      ],
      "credentials": {
        "openAiApi": "<your credential>"
      }
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "read",
        "documentId": "{{ $env.GOOGLE_SHEETS_ID }}",
        "sheetName": "Sales Orders",
        "options": {
          "range": "A:Z"
        }
      },
      "id": "get-order-status",
      "name": "getOrderStatus",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4,
      "position": [
        750,
        100
      ],
      "credentials": {
        "googleSheetsOAuth2": "<your credential>"
      }
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "read",
        "documentId": "{{ $env.GOOGLE_SHEETS_ID }}",
        "sheetName": "Inventory",
        "options": {
          "range": "A:D"
        }
      },
      "id": "get-inventory",
      "name": "getInventory",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4,
      "position": [
        750,
        200
      ],
      "credentials": {
        "googleSheetsOAuth2": "<your credential>"
      }
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "update",
        "documentId": "{{ $env.GOOGLE_SHEETS_ID }}",
        "sheetName": "Sales Orders",
        "keyRow": 1,
        "columns": "Order ID=orderId,Customer Name=customerName,Order Status=status,Total Amount=amount,Last Updated=timestamp"
      },
      "id": "update-sales-orders",
      "name": "updateSalesOrders",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4,
      "position": [
        750,
        300
      ],
      "credentials": {
        "googleSheetsOAuth2": "<your credential>"
      }
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "documentId": "{{ $env.GOOGLE_SHEETS_ID }}",
        "sheetName": "Sales Orders",
        "columns": "Order ID=orderId,Customer Name=customerName,Order Status=status,Total Amount=amount,Created Date=createdDate"
      },
      "id": "append-sales-orders",
      "name": "appendSalesOrders",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4,
      "position": [
        750,
        400
      ],
      "credentials": {
        "googleSheetsOAuth2": "<your credential>"
      }
    },
    {
      "parameters": {
        "resource": "sheet",
        "operation": "delete",
        "documentId": "{{ $env.GOOGLE_SHEETS_ID }}",
        "sheetName": "Sales Orders",
        "where": {
          "column": "Order ID",
          "condition": "equals",
          "value": "{{ $json.orderId }}"
        }
      },
      "id": "delete-orders",
      "name": "deleteOrders",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4,
      "position": [
        750,
        500
      ],
      "credentials": {
        "googleSheetsOAuth2": "<your credential>"
      }
    },
    {
      "parameters": {
        "operation": "post",
        "url": "{{ $env.WHATSAPP_API_URL }}/messages",
        "authentication": "genericCredentialType",
        "genericAuth": {
          "authType": "bearerAuth",
          "bearerAuth": "{{ $env.WHATSAPP_ACCESS_TOKEN }}"
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "messaging_product",
              "value": "whatsapp"
            },
            {
              "name": "to",
              "value": "{{ $json.data.sender }}"
            },
            {
              "name": "type",
              "value": "text"
            },
            {
              "name": "text",
              "value": {
                "body": "{{ $json.text }}"
              }
            }
          ]
        }
      },
      "id": "whatsapp-response",
      "name": "WhatsApp Response",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1000,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6d8d6f03-68f4-44b2-9d33-4f995a98ec51",
              "name": "text",
              "value": "={{ $json.output }}",
              "type": "string"
            },
            {
              "id": "a933f7c1-d419-4f7f-8c33-bd8853b0f2ea",
              "name": "data",
              "value": "={{ $json.data }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "format-response",
      "name": "Format Response",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.2,
      "position": [
        850,
        300
      ]
    }
  ],
  "connections": {
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Response": {
      "main": [
        [
          {
            "node": "WhatsApp Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "getOrderStatus": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "getInventory": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "updateSalesOrders": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "appendSalesOrders": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "deleteOrders": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true
  },
  "staticData": null,
  "versionId": "1"
}