{
  "name": "Finalcial AI",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "chat",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "id": "NODE_ID_WEBHOOK",
      "name": "Webhook"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "API_URL",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"{{ $json.body.request.intent.slots.Gasto.value }}\" \n    }\n  ]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        208,
        0
      ],
      "id": "NODE_ID_HTTP",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "SHEET_ID",
          "mode": "list",
          "cachedResultName": "Finanzas_XXXX",
          "cachedResultUrl": "URL"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Hoja 1",
          "cachedResultUrl": "URL"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Concepto": "={{ $json.concepto }}",
            "Monto": "={{ $json.monto }}",
            "Categoria": "={{ $json.categoria }}",
            "Moneda": "={{ $json.moneda }}",
            "Fecha": "={{ $now.toFormat('dd-MM-yyyy') }}"
          },
          "matchingColumns": [
            "data"
          ],
          "schema": [
            {
              "id": "Fecha",
              "displayName": "Fecha",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Concepto",
              "displayName": "Concepto",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Monto",
              "displayName": "Monto",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Categoria",
              "displayName": "Categoria",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Moneda",
              "displayName": "Moneda",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        624,
        0
      ],
      "id": "NODE_ID_SHEETS",
      "name": "Append row in sheet",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "\nlet texto = $input.first().json.data;\nif (typeof texto === 'string') {\n  texto = texto.replace(/```json/gi, '')\n               .replace(/```/g, '')\n               .trim();\n}\ntry {\n  const jsonLimpio = JSON.parse(texto);\n  return jsonLimpio;\n} catch (error) {\n  throw new Error(\"La IA envi\u00f3 un formato que no es JSON v\u00e1lido: \" + texto);\n}"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        416,
        0
      ],
      "id": "NODE_ID_CODE",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"version\": \"1.0\",\n  \"response\": {\n    \"outputSpeech\": {\n      \"type\": \"PlainText\",\n      \"text\": \"Listo, registr\u00e9 {{ $json.Monto }} {{ $json.Moneda }} en {{ $json.Categoria }}.\"\n    },\n    \"shouldEndSession\": true\n  }\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        832,
        0
      ],
      "id": "NODE_ID_RESPOND",
      "name": "Respond to Webhook",
      "alwaysOutputData": true
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append row in sheet": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false
  },
  "versionId": "VERSION_ID",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "WORKFLOW_ID",
  "tags": []
}