{
  "name": "BMC Quote Workflow - Test",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "whatsapp-quote",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "WhatsApp Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "condition-1",
              "leftValue": "={{ $json.body.message }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "isNotEmpty"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "message-check",
      "name": "Check Message",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3000/api/parse-quote",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "consulta",
              "value": "={{ $json.body.message }}"
            }
          ]
        },
        "options": {}
      },
      "id": "parse-quote",
      "name": "Parse Quote with AI",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        200
      ]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3000/api/sheets/enhanced-sync",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "action",
              "value": "add_quote"
            },
            {
              "name": "data",
              "value": "={{ {\n  \"arg\": \"WA\" + new Date().getDate() + $json.body.from.slice(-4),\n  \"estado\": \"Pendiente\",\n  \"fecha\": new Date().toLocaleDateString('es-UY'),\n  \"cliente\": $json.body.from,\n  \"origen\": \"WA\",\n  \"telefono\": $json.body.from,\n  \"direccion\": \"A confirmar\",\n  \"consulta\": $json.body.message\n} }}"
            }
          ]
        },
        "options": {}
      },
      "id": "save-to-sheets",
      "name": "Save to Google Sheets",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        900,
        200
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ {\n  \"success\": true,\n  \"message\": \"Cotizaci\u00f3n recibida y procesada exitosamente\",\n  \"data\": {\n    \"arg\": \"WA\" + new Date().getDate() + $json.body.from.slice(-4),\n    \"parsed\": $('Parse Quote with AI').first().json,\n    \"timestamp\": new Date().toISOString()\n  }\n} }}",
        "options": {}
      },
      "id": "success-response",
      "name": "Success Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1120,
        200
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ {\n  \"success\": false,\n  \"error\": \"Mensaje vac\u00edo o inv\u00e1lido\",\n  \"timestamp\": new Date().toISOString()\n} }}",
        "options": {}
      },
      "id": "error-response",
      "name": "Error Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        680,
        400
      ]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3000/api/integrated-quote",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "action",
              "value": "process"
            },
            {
              "name": "consulta",
              "value": "={{ $json.body.message }}"
            },
            {
              "name": "userPhone",
              "value": "={{ $json.body.from }}"
            },
            {
              "name": "userName",
              "value": "Cliente WhatsApp"
            }
          ]
        },
        "options": {}
      },
      "id": "integrated-quote",
      "name": "Process with Integrated AI",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        900,
        100
      ]
    }
  ],
  "connections": {
    "WhatsApp Webhook": {
      "main": [
        [
          {
            "node": "Check Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Message": {
      "main": [
        [
          {
            "node": "Parse Quote with AI",
            "type": "main",
            "index": 0
          },
          {
            "node": "Process with Integrated AI",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Quote with AI": {
      "main": [
        [
          {
            "node": "Save to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process with Integrated AI": {
      "main": [
        [
          {
            "node": "Save to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Google Sheets": {
      "main": [
        [
          {
            "node": "Success Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "createdAt": "2024-12-19T10:00:00.000Z",
      "updatedAt": "2024-12-19T10:00:00.000Z",
      "id": "bmc-quotes",
      "name": "BMC Quotes"
    }
  ],
  "triggerCount": 1,
  "updatedAt": "2024-12-19T10:00:00.000Z",
  "versionId": "1"
}