{
  "name": "JFCandia_Flujo",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "testwebhook",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -860,
        -340
      ],
      "id": "a3fabd24-cd3b-4d2f-b16e-586cbed6226b",
      "name": "Webhook"
    },
    {
      "parameters": {
        "command": "python \"C:\\Users\\jcandia.SBAD\\Documents\\BallenaAzul\\veterinaria-app\\src\\test_db.py\""
      },
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        -800,
        20
      ],
      "id": "116bea98-0176-4cae-82a8-2162ca60c069",
      "name": "Execute Command"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "xxxxxxxxxxxx",
              "leftValue": "={{$json[\"stdout\"]}}",
              "rightValue": "OK",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -580,
        -380
      ],
      "id": "xxxxxxxxxxxx",
      "name": "If"
    },
    {
      "parameters": {
        "fromEmail": "candia1978@gmail.com",
        "toEmail": "candia1978@gmail.com",
        "subject": "\u2705\u2705\u2705Ejecucion Validacion - DTE",
        "html": "=\u2705\u2705\u2705 El test autom\u00e1tico de Validacion - DTE se ejecut\u00f3 correctamente.\n<br>Fecha: {{ $now }}\u2705\u2705\u2705",
        "options": {
          "ccEmail": ""
        }
      },
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        -340,
        100
      ],
      "id": "xxxxxxxx",
      "name": "Send Email",
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9a3e3ef1-fa95-4597-8ee7-c0f782b08ae4",
              "name": "log",
              "value": "=Fecha: {{ $now }}\nEstado: {{ $json[\"stdout\"].includes('OK') ? 'OK' : 'ERROR' }}\n{{ \n  $json[\"stdout\"].includes('OK') \n    ? '\\nConsulta ejecutada correctamente.\\n-------------------------------' \n    : (\n      '\\n\u274c ERROR DETECTADO:\\n' +\n      (\n        $json[\"stdout\"].split('\\n').find(line => line.startsWith('ERROR:')) \n        || \"No se encontr\u00f3 mensaje de error en la salida.\"\n      ) +\n      (\n        $json[\"stdout\"].includes('no such table')\n          ? '\\nSoluci\u00f3n: Verifica que la tabla exista en la base de datos y que el nombre est\u00e9 bien escrito.'\n          : $json[\"stdout\"].includes('unable to open database file')\n            ? '\\nSoluci\u00f3n: Revisa la ruta del archivo y los permisos de acceso.'\n            : $json[\"stdout\"].includes('Prueba forzada de error')\n              ? '\\nSoluci\u00f3n: El script est\u00e1 configurado para forzar un error. Quita o comenta esa l\u00ednea para probar normalmente.'\n              : $json[\"stdout\"].includes('syntax error')\n                ? '\\nSoluci\u00f3n: Hay un error de sintaxis en la consulta SQL. Revisa la consulta.'\n                : '\\nSoluci\u00f3n: Revisa el mensaje de error y corrige seg\u00fan corresponda.'\n      ) +\n      '\\n-------------------------------'\n    )\n}}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": "=Fecha: {{ $now }} | Estado: {{ $json[\"stdout\"].includes('OK') ? 'OK' : 'ERROR' }} | Salida: {{ $json[\"stdout\"] }}",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -180,
        -360
      ],
      "id": "ff5d0328-3e77-46fc-8f7c-1e876e8344c5",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "operation": "write",
        "fileName": "C:\\Users\\jcandia.SBAD\\Documents\\BallenaAzul\\veterinaria-app\\src\\resultado.json",
        "dataPropertyName": "archivo",
        "options": {
          "append": true
        }
      },
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        580,
        -80
      ],
      "id": "9e36b79e-ecc4-4ca6-b560-1b4581f7c4e5",
      "name": "Read/Write Files from Disk"
    },
    {
      "parameters": {
        "jsCode": "const logText = $json.log + \"\\n\";\nconst buffer = Buffer.from(logText, \"utf8\");\nreturn [\n  {\n    binary: {\n      archivo: {\n        data: buffer.toString(\"base64\"),\n        mimeType: \"text/plain\",\n        fileName: \"test_log.txt\"\n      }\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        180,
        -360
      ],
      "id": "952ed602-48bb-4657-8e5e-24b838e7f52d",
      "name": "Code"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.telegram.org/bot7696471753:AAEe4UsczQcRM0V8uMrxKql5xdjhZQxjtck/sendMessage",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"chat_id\": \"xxxxxxxx\",\n  \"text\": \"\ud83d\udce2 Notificaci\u00f3n de prueba exitosa desde n8n Para Validacion DTE\\n\u23f0 {{$now}}\"\n}\n",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        40,
        20
      ],
      "id": "c7ca532b-071f-4e78-8f7b-5eaf62423df4",
      "name": "HTTP Request"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Execute Command",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Command": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          },
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Read/Write Files from Disk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "82f8847d-a9e9-40f0-b6dd-bc0ef36b5ed1",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "veknus9q8960Vl3m",
  "tags": []
}