{
  "active": false,
  "connections": {
    "Chat": {
      "ai_memory": [
        [
          {
            "node": "AGE3",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Model": {
      "ai_languageModel": [
        [
          {
            "node": "AGE3",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "AGE3",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Wait3": {
      "main": [
        [
          {
            "node": "MESSAGE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MESSAGE": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit": {
      "main": [
        [
          {
            "node": "Delete Memory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "replace": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Convert to File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File1": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "Groq Transcripcion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Transcripcion": {
      "main": [
        [
          {
            "node": "Datos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compara Get Memory": {
      "main": [
        [
          {
            "node": "Compara memorias",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Memory 2": {
      "main": [
        [
          {
            "node": "Redis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait2": {
      "main": [
        [
          {
            "node": "Get Memory 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Redis": {
      "main": [
        [
          {
            "node": "Compara Get Memory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Memory 1": {
      "main": [
        [
          {
            "node": "Escribiendo...",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields3": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Form Me1": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limpiamos Imagen": {
      "main": [
        [
          {
            "node": "Variables individuales",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Variables individuales": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compara memorias": {
      "main": [
        [
          {
            "node": "AGE3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Memory": {
      "main": [
        [
          {
            "node": "Get Memory 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "resumen_gastos": {
      "ai_tool": [
        [
          {
            "node": "AGE3",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Datos": {
      "main": [
        [
          {
            "node": "Text Memory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Text Memory",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Datos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insertar gastos": {
      "ai_tool": [
        [
          {
            "node": "AGE3",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "Limpiamos Imagen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Escribiendo...": {
      "main": [
        [
          {
            "node": "Wait2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Datos",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Edit Fields3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Form Me1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AGE3": {
      "main": [
        [
          {
            "node": "replace",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "createdAt": "2025-06-28T03:55:53.943Z",
  "id": "BcBPBvocIPhVVdE7",
  "isArchived": false,
  "meta": null,
  "name": "Delivery",
  "nodes": [
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Webhook').item.json.body.data.key.remoteJid }}",
        "tableName": "n8n_chat_histories11",
        "contextWindowLength": 10
      },
      "id": "62d6fe29-0098-4e57-bb88-f14cf0023c83",
      "name": "Chat",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "typeVersion": 1.1,
      "position": [
        800,
        720
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": "gpt-4o-2024-11-20",
        "options": {
          "temperature": 0.1,
          "maxRetries": 10
        }
      },
      "id": "f03b4617-a993-4442-971b-ce2bfc96cb19",
      "name": "Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        660,
        720
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "id": "8ba6168e-4cf8-4d12-a58d-5b8a1bb49465",
      "name": "Calculator",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "typeVersion": 1,
      "position": [
        920,
        720
      ]
    },
    {
      "parameters": {
        "operation": "delete",
        "key": "={{ $('Webhook').item.json.body.data.key.remoteJid }}"
      },
      "id": "94e1390a-d505-43c5-8655-52dfa06079d2",
      "name": "Delete Memory",
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        2780,
        -39
      ],
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "amount": "=0"
      },
      "id": "4144ab52-2d5d-4d3a-a588-df226abf6231",
      "name": "Wait3",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        2560,
        161
      ]
    },
    {
      "parameters": {
        "batchSize": "=1",
        "options": {
          "reset": false
        }
      },
      "id": "746fad96-8cf9-4a4c-94df-b4827d0261db",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        2300,
        101
      ],
      "alwaysOutputData": false,
      "executeOnce": false
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $node['Webhook'].json.body.server_url }}/message/sendText/{{ $node['Webhook'].json.body.instance }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $node['Webhook'].json.body.apikey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"delay\": 1500,\n    \"number\": \"{{ $node['Webhook'].json.body.data.key.remoteJid }}\",\n    \"text\": \"{{ $('Loop Over Items').item.json.text.replace(/\\n/g,'\\\\n').replace(/\\\"/g,'\\'') }}\"\n\n}",
        "options": {}
      },
      "id": "741820d0-4539-4714-a7d7-6a95920619e7",
      "name": "MESSAGE",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2800,
        161
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "text",
        "options": {}
      },
      "id": "f1e3d574-43fb-4bf5-953f-bc7f52c3e1ea",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        2040,
        -79
      ]
    },
    {
      "parameters": {},
      "id": "bfd3b9bf-6bb2-4381-b6bf-c05d6bb92d23",
      "name": "Limit",
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        2560,
        -39
      ]
    },
    {
      "parameters": {
        "content": "## Envio por whatsapp",
        "height": 829.1258754413049,
        "width": 1453.850746268657
      },
      "id": "8c5c1624-a961-4694-8799-fa5b97d29498",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1640,
        -340
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5d04d69d-cb9c-41be-a44a-95fac3c059f3",
              "name": "text",
              "value": "={{ $json.output.replace(/\\*\\*(.*?)\\*\\*/g, '*$1*').split(/\\n\\n|---/) }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "id": "68d8fdea-0ff9-4785-b7ab-ff8378d161de",
      "name": "replace",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1820,
        -79
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b7d210f0-6a18-456d-9e89-aa28f548b2a0",
              "name": "body.data.message.base64",
              "value": "={{ $('Webhook').item.json.body.data.message.base64 }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "fc92cabc-608c-4510-a6bb-21f116df0fe4",
      "name": "Edit Fields1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -760,
        -160
      ]
    },
    {
      "parameters": {
        "operation": "toBinary",
        "sourceProperty": "body.data.message.base64",
        "options": {}
      },
      "id": "69fc0634-74ee-477d-b049-70cd43fbad3d",
      "name": "Convert to File1",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        -560,
        -160
      ]
    },
    {
      "parameters": {
        "operation": "toBinary",
        "sourceProperty": "body.data.message.base64",
        "options": {
          "mimeType": "audio/mp3"
        }
      },
      "id": "ed8b8cc7-115b-42da-844f-efde486f545d",
      "name": "Convert to File",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        -340,
        260
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/audio/transcriptions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "bearer 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"
            },
            {
              "name": "Content-type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "whisper-large-v3"
            },
            {
              "name": "temperature",
              "value": "0"
            },
            {
              "name": "response_format",
              "value": "json"
            },
            {
              "name": "language",
              "value": "es"
            },
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "53ea8c8f-87e2-4993-81b0-a939039beb97",
      "name": "Groq Transcripcion",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -140,
        260
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "d5a342e9-585b-42ea-be44-644adae10199",
              "leftValue": "={{ $json.Redis1 }}",
              "rightValue": "={{ $json.Redis2 }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "2475b773-cfe6-49aa-bc56-2b37750ac98a",
      "name": "Compara Get Memory",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        500,
        80
      ]
    },
    {
      "parameters": {
        "operation": "get",
        "propertyName": "Redis2",
        "key": "={{ $('Webhook').item.json.body.data.key.remoteJid }}",
        "options": {}
      },
      "id": "6a023226-344c-41f3-8d23-0305d8d4dcfb",
      "name": "Get Memory 2",
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        140,
        80
      ],
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "amount": 6
      },
      "id": "bd12c9c1-ebb0-42be-a249-4ee95372707e",
      "name": "Wait2",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -20,
        80
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "86ff282a-3ede-4417-98c1-0d10858bc5dc",
              "name": "Redis1",
              "value": "={{ $('Get Memory 1').item.json.Redis1 }}",
              "type": "string"
            },
            {
              "id": "3cd6e8a1-98ef-4abb-9490-fb7946365cfb",
              "name": "Redis2",
              "value": "={{ $json.Redis2 }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "9ed8271a-8975-4eea-a36e-30b86aeb269f",
      "name": "Redis",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        320,
        80
      ]
    },
    {
      "parameters": {
        "operation": "get",
        "propertyName": "Redis1",
        "key": "={{ $('Webhook').item.json.body.data.key.remoteJid }}",
        "options": {
          "dotNotation": true
        }
      },
      "id": "944d7f66-032d-47b9-b586-375085b2e77d",
      "name": "Get Memory 1",
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        -360,
        80
      ],
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "deleteTable",
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "n8n_chat_histories11",
          "mode": "list",
          "cachedResultName": "n8n_chat_histories11"
        },
        "options": {}
      },
      "id": "dc191310-0221-479b-a287-7fda060b1d4e",
      "name": "Postgres",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        100,
        480
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Mensaje ",
        "height": 897.4145773466248,
        "width": 2142.01411510659,
        "color": 6
      },
      "id": "ea22d13a-50b7-490a-9eb5-63adc1bf7f7e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1460,
        -260
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b7d210f0-6a18-456d-9e89-aa28f548b2a0",
              "name": "body.data.message.base64",
              "value": "={{ $('Webhook').item.json.body.data.message.base64 }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "4080ceb5-8e80-4bd8-b351-d821373475a6",
      "name": "Edit Fields3",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -540,
        260
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "94746291-c0f3-44f3-b635-1fe696d7d74e",
              "leftValue": "={{ $json.body.data.key.fromMe }}",
              "rightValue": "false",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "0c6b6fc7-cd54-4d8b-b206-ae05396113b6",
      "name": "Form Me1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -1160,
        180
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "21febd42-6a94-4e95-a4e0-a82e9eac9008",
              "name": "Limpio",
              "value": "={{ $json.content.replace(/\\\\n|\"\"\"|json|\\\\/g, '').trim() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "b7045a35-866e-43bc-88e3-a99f3fc7e5ef",
      "name": "Limpiamos Imagen",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -180,
        -160
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5d04d69d-cb9c-41be-a44a-95fac3c059f3",
              "name": "fecha",
              "value": "={{ $json.Limpio.match(/\"fecha\":\\s*\"([^\"]+)\"/)?.[1] || '' }}",
              "type": "string"
            },
            {
              "id": "791d6622-0b9c-4ff9-abd7-63c54c4c4f5f",
              "name": "monto",
              "value": "={{ $json.Limpio.match(/\"monto\":\\s*\"([^\"]+)\"/).at(1) || '0' }}",
              "type": "string"
            },
            {
              "id": "f2db0e16-0432-4de3-95bf-3e98a298b939",
              "name": "categoria",
              "value": "={{ $json.Limpio.match(/\"categoria\":\\s*\"([^\"]+)\"/)?.[1] || '' }}",
              "type": "string"
            },
            {
              "id": "217c0a67-02b4-4bea-823d-a4ef5bc585d2",
              "name": "descripcion",
              "value": "={{ $json.Limpio.match(/\"descripcion\":\\s*\"([^\"]+)\"/)?.[1] || '' }}",
              "type": "string"
            },
            {
              "id": "1ffa6e8b-6941-49aa-b39e-6f54382b71ff",
              "name": "metodo_pago",
              "value": "={{ $json.Limpio.match(/\"metodo_pago\":\\s*\"([^\"]+)\"/)?.[1] || '' }}",
              "type": "string"
            },
            {
              "id": "dd3ab75e-5ccc-45d3-a28f-1e02321e8bcf",
              "name": "razon_social",
              "value": "={{ $json.Limpio.match(/\"razon_social\":\\s*\"([^\"]+)\"/)?.[1] || '' }}",
              "type": "string"
            },
            {
              "id": "448bcd3f-595a-43a9-a0a7-0e3b13767793",
              "name": "var",
              "value": "={{ $json.Limpio }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "847afa02-06af-4ad7-a131-9bc5eaf432a2",
      "name": "Variables individuales",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        0,
        -160
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $item(0).$node[\"Compara Get Memory\"].json[\"Redis2\"]; \n\nlet array = Array.isArray(data) ? data : JSON.parse(data);\n\nconst mensage_completo = array.join(\" \");\n\nreturn [{ json: { mensage_completo } }];\n"
      },
      "id": "f593ed35-7fd2-45eb-8d10-546f5467a3f9",
      "name": "Compara memorias",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        420,
        300
      ]
    },
    {
      "parameters": {
        "operation": "push",
        "list": "={{ $('Webhook').item.json.body.data.key.remoteJid }}",
        "messageData": "={{ $json.Limpio }} || {{ $json.text }} || {{ $json.voice }} ||  {{ $json.var }}",
        "tail": true
      },
      "id": "77c31388-16b4-4273-9b79-b68315723398",
      "name": "Text Memory",
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        -540,
        80
      ],
      "alwaysOutputData": false,
      "executeOnce": false,
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "name": "resumen_gastos",
        "description": "Llamaras a esta herramienta cuando el usuario necesita saber los gastos semanales, mensuales o diarios",
        "workflowId": {
          "__rl": true,
          "value": "31qNrynUbCN8A34k",
          "mode": "list",
          "cachedResultName": "RAG Personal - resumen gastos"
        },
        "specifyInputSchema": true,
        "jsonSchemaExample": "{\n\t\"desde\": \"algun dato\",    \n    \"hasta\":\"algun dato\"\n}"
      },
      "id": "d197386b-14f9-4fa8-9111-04caf2762486",
      "name": "resumen_gastos",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 1.2,
      "position": [
        1200,
        720
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1c859eff-6baa-453d-b6dd-818fabad66fd",
              "name": "Limpio",
              "value": "={{ $json.body.data.message.conversation || $json.text || ($('Limpiamos Imagen', 0) ? $('Limpiamos Imagen').item.json.Limpio : 'Sin datos disponibles') }}\n",
              "type": "string"
            },
            {
              "id": "cf15fa6e-e477-438d-8119-e72a917e5e46",
              "name": "text",
              "value": "={{ $json.body.data.message.conversation }}",
              "type": "string"
            },
            {
              "id": "921bc6a5-5eaf-489b-88a2-10b654611e3c",
              "name": "voice",
              "value": "={{$json.text || ''}}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "2430580c-166e-435f-9a3d-03106ef18dc6",
      "name": "Datos",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -760,
        80
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "8a574789-aa3a-43f1-898e-a2589764e895",
              "leftValue": "=Limpio",
              "rightValue": "={{ $('Limpiamos Imagen').item.json.Limpio }}",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "af2c2751-3430-4831-9e9d-04d3ecb5c0b6",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        200,
        -160
      ]
    },
    {
      "parameters": {
        "name": "insertar_gastos",
        "description": "LLamaras a esta herramienta cuando el usuario confirme un gasto",
        "workflowId": {
          "__rl": true,
          "value": "RKX1dR3ws7vF9qmR",
          "mode": "list",
          "cachedResultName": "RAG Personal-Gastos"
        },
        "fields": {
          "values": [
            {
              "name": "Fer",
              "stringValue": "={{ $('Webhook').item.json.body.data.key.remoteJid }}"
            }
          ]
        },
        "specifyInputSchema": true,
        "jsonSchemaExample": "{\n\t\"fecha\": \"fecha\",\n    \"monto\": \"monto\",\n    \"descripcion\": \"descripcion del gasto\",\n  \"categoria\":\"tipo de gasto\",\n\"metodo_pago\":\"tarjeta,efectivo, etc\",\n  \"razon_social\":\"nombre del lugar\"\n \n}"
      },
      "id": "9af2f028-edaa-4584-8b32-bf0616daeb06",
      "name": "Insertar gastos",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 1.2,
      "position": [
        1060,
        720
      ]
    },
    {
      "parameters": {
        "resource": "image",
        "operation": "analyze",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4O-MINI"
        },
        "text": "=Analiza esta imagen de comprobante y extrae la siguiente informaci\u00f3n en el siguiente formato:\n\n{\n  \"fecha\": \"\",\n  \"monto\": \"\",\n  \"categoria\": \"\",\n  \"descripcion\": \"\",\n  \"metodo_pago\": \"\",\n  \"razon_social\":\"\"\n}\n\n\nrecuerda que la fecha debes guardarla en formate Date ('yyyy-MM-dd')",
        "inputType": "base64",
        "options": {}
      },
      "id": "44058cc2-bbdb-486b-adf2-3395e9a11e1a",
      "name": "OpenAI",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.7,
      "position": [
        -360,
        -160
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $node['Webhook'].json.body.server_url }}/chat/sendPresence/{{ $node['Webhook'].json.body.instance }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $node['Webhook'].json.body.apikey }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"number\": \"{{ $node['Webhook'].json.body.data.key.remoteJid }}\",\n    \"delay\": 3000,\n    \"presence\": \"composing\"\n}",
        "options": {}
      },
      "id": "86366add-39ce-4dc6-ac61-0a3a90f90d58",
      "name": "Escribiendo...",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -180,
        80
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "60065893-74f7-4b64-bc1a-d891202efa78",
                    "leftValue": "={{ $('Webhook').item.json.body.data.messageType }}",
                    "rightValue": "imageMessage",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Imagen"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "0cb14635-2673-408e-86db-ce9e0373674b",
                    "leftValue": "={{ $('Webhook').item.json.body.data.messageType }}",
                    "rightValue": "conversation",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Texto"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $('Webhook').item.json.body.data.messageType }}",
                    "rightValue": "audioMessage",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "\u00c1udio"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "f8a3997b-ab9a-4804-a782-df8fd79bd499",
                    "leftValue": "={{ $json.body.data.message.listResponseMessage.singleSelectReply.selectedRowId }}",
                    "rightValue": "=reservar_sombrilla",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        },
        "options": {}
      },
      "id": "cf80f820-89cc-471b-a3a3-41beabbddb38",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -1140,
        400
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "delivery",
        "options": {}
      },
      "id": "828f97ec-e0a6-41f1-9f9c-c81f1dde2be3",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -1400,
        180
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.mensage_completo }}",
        "options": {
          "systemMessage": "={\n  \"rol\": \"Asistente virtual especializado en la gesti\u00f3n de pedidos para una rotiser\u00eda. Responde consultas sobre productos, verifica disponibilidad desde la base de datos, calcula precios y registra pedidos.\",\n  \"tareas\": {\n    \"mostrar_carta_por_categoria\": {\n      \"descripcion\": \"Cuando un cliente pregunta por una categor\u00eda, se consulta la base de datos para obtener la lista de productos disponibles y se responde con la informaci\u00f3n correspondiente.\",\n      \"ejemplo\": {\n        \"cliente\": \"Que empanadas tienen?\",\n        \"asistente\": [\n          \"Empanadas disponibles (seg\u00fan la base de datos):\",\n          \"- Carne\",\n          \"- Pollo\",\n          \"- Jam\u00f3n y Queso\",\n          \"- Caprese\",\n          \"- Verdura\",\n          \"- Carne Picante\"\n        ]\n      }\n    },\n    \"confirmar_precios_disponibilidad\": {\n      \"descripcion\": \"Se consulta la base de datos para verificar la disponibilidad del producto y el precio antes de confirmarlo con el cliente.\",\n      \"ejemplo\": {\n        \"cliente\": \"Cuanto cuesta la pizza muzarella?\",\n        \"asistente\": \"La pizza muzarella cuesta 900 pesos seg\u00fan la base de datos. Te anoto una?\"\n      }\n    },\n    \"registrar_pedidos\": {\n      \"descripcion\": \"Los pedidos se registran en la base de datos asoci\u00e1ndolos al cliente registrado. Se consulta la base de datos para calcular autom\u00e1ticamente los subtotales y totales antes de confirmar el pedido.\",\n      \"ejemplo\": {\n        \"cliente\": \"Quiero 2 empanadas de carne y 1 pizza napolitana.\",\n        \"asistente\": \"Perfecto, tu pedido qued\u00f3 registrado. Son 1250 pesos en total, calculados desde la base de datos. Est\u00e1 pendiente de preparaci\u00f3n.\"\n      }\n    },\n    \"consultar_estado_pedidos\": {\n      \"descripcion\": \"Informa al cliente sobre el estado de sus pedidos actuales o anteriores consultando la base de datos.\",\n      \"ejemplo\": {\n        \"cliente\": \"Como va mi pedido?\",\n        \"asistente\": \"Tu pedido est\u00e1 en preparaci\u00f3n. Incluye 2 empanadas de carne y 1 pizza napolitana. Total: 1250 pesos.\"\n      }\n    },\n    \"respuesta_calida_cercana\": {\n      \"descripcion\": \"Usa un tono relajado y expresiones locales para generar cercan\u00eda.\",\n      \"ejemplo\": {\n        \"cliente\": \"Tienen flan casero?\",\n        \"asistente\": \"Si, est\u00e1 disponible seg\u00fan la base de datos. Quer\u00e9s que lo agregue a tu pedido?\"\n      }\n    }\n  },\n  \"especificaciones\": {\n    \"tono\": \"C\u00e1lido y profesional, sin signos de exclamaci\u00f3n. Respuestas claras y cercanas.\",\n    \"interaccion_bd\": {\n      \"productos_disponibles\": \"Todos los productos y precios se obtienen de la base de datos.\",\n      \"clientes_registrados\": \"Solo se registran pedidos para clientes previamente validados en la base de datos.\"\n    },\n    \"personalizacion\": \"Respuestas adaptadas a las consultas del cliente, confirmando cada paso.\"\n  },\n  \"carta_completa\": {\n    \"origen\": \"La carta completa se genera din\u00e1micamente consultando la base de datos.\",\n    \"categorias\": [\"Empanadas\", \"Pizzas\", \"Sandwiches y Hamburguesas\", \"Bebidas\", \"Postres\", \"Otros productos\"]\n  },\n  \"notas_finales\": {\n    \"interaccion_bd\": {\n      \"disponibilidad\": \"Solo mostrar productos con disponibilidad confirmada (disponible = TRUE) desde la base de datos.\",\n      \"precios\": \"Todos los precios se extraen de la base de datos.\",\n      \"verificacion_cliente\": \"Validar que el cliente est\u00e9 registrado antes de aceptar pedidos.\"\n    },\n    \"calculos\": \"Calcular autom\u00e1ticamente subtotales y totales a partir de los precios en la base de datos.\"\n  }\n}\n",
          "maxIterations": 6
        }
      },
      "id": "eb8a0b64-ea74-467d-bcd1-9801692bf705",
      "name": "AGE3",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.6,
      "position": [
        860,
        400
      ]
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2025-06-28T03:58:51.944Z",
  "versionId": "e356cd90-09ef-4b90-a782-f5985072eb02"
}