{
  "name": "FlujoEjemplo001",
  "nodes": [
    {
      "parameters": {
        "multipleMethods": true,
        "path": "asistente-interno",
        "responseMode": "responseNode",
        "options": {
          "allowedOrigins": "*"
        }
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        -208,
        496
      ],
      "id": "9ecfe886-b0ac-46ed-b641-ec45f45b252f",
      "name": "Webhook",
      "alwaysOutputData": false,
      "executeOnce": false,
      "retryOnFail": false
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "3cf4d57c-db41-4e9f-aefb-e3fc032f9389",
              "leftValue": "={{ $('Webhook').item.json.body.mensaje }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        464,
        496
      ],
      "id": "96f44c38-5d30-4ffd-810e-ad7876356079",
      "name": "If"
    },
    {
      "parameters": {
        "jsCode": "return items.map(item =>{\n  const compara = ['urgente', 'urgent', 'urgentes', 'prioridad']; \n  const mensaje = item.json.body.mensaje.toString().toLowerCase();\n  let prioridad = 'baja';\n  for (const key in compara) {\n    const element = compara[key];\n    if (mensaje.includes(element)){\n      prioridad = 'Alta';\n      break\n    }\n  }\n  item.json.body.prioridad = prioridad;\n  return item;\n})"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        16,
        496
      ],
      "id": "d34cd335-ee01-4ab2-9e56-9703485dfc4f",
      "name": "Code"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "20ccdf18-4814-40d6-b986-b27c5d9e1472",
              "name": "usuario",
              "value": "={{ $json.body.usuario }}",
              "type": "string"
            },
            {
              "id": "a94af057-6026-4e3c-9aab-1b9d61745f6d",
              "name": "mensaje",
              "value": "={{ $json.body.mensaje }}",
              "type": "string"
            },
            {
              "id": "c61601f0-24eb-46b9-807d-f0ce3cddffd2",
              "name": "prioridad",
              "value": "={{ $json.body.prioridad }}",
              "type": "string"
            },
            {
              "id": "f884ee7d-d35d-4a38-bfb0-ac9b546cd073",
              "name": "fecha",
              "value": "={{ $now.format('yyyy-MM-dd') }}",
              "type": "string"
            },
            {
              "id": "02d90844-da88-4adc-8b3f-bdc4fa1c2739",
              "name": "flujo",
              "value": "={{ $workflow.name }}",
              "type": "string"
            },
            {
              "id": "b8a0fbf8-596d-481d-9685-eb2986a949fc",
              "name": "executive",
              "value": "={{ $execution.id }}",
              "type": "string"
            },
            {
              "id": "28a858a8-df82-4d1a-8afe-35ce8a0783bf",
              "name": "id",
              "value": "={{ $execution.mode }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        496
      ],
      "id": "3f40d7c5-9ced-4cae-8eed-0b50ea83647b",
      "name": "campos"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "cc9Wjc0aXwUTJ0TK",
          "mode": "id",
          "cachedResultUrl": "/workflow/cc9Wjc0aXwUTJ0TK"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {}
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.3,
      "position": [
        688,
        400
      ],
      "id": "afeebde2-51f5-4815-9def-1d9122779964",
      "name": "Call 'AgenteIAClasificador'"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"estado\": {{ $json.ok }}\n}  ",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        1584,
        400
      ],
      "id": "b8be9fc6-9d79-42ae-9c87-f5bcc74e0f2f",
      "name": "RespuestaPositiva"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"estado\": \"error\",\n  \"detalle\":\"Mensaje vacio\",\n  \"usuario\":\"{{ $json.mensaje }}\"\n} ",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        688,
        592
      ],
      "id": "4ab8bcbd-034d-41fb-ad0f-e860ee9a62e1",
      "name": "RespuestaNegativa"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.categoria }}",
                    "rightValue": "IT",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "a9d902fa-9ab1-4382-a39e-d97f7281d6ff"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "IT"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "a239a379-e754-41d7-b97d-3313d7bdc062",
                    "leftValue": "={{ $json.categoria }}",
                    "rightValue": "legal",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Legal"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "547d6b3d-8980-494f-9d9a-8f3c4b5fdb9a",
                    "leftValue": "={{ $json.categoria }}",
                    "rightValue": "facilities",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Facilities"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        912,
        368
      ],
      "id": "945805f7-6076-4fb6-afd8-6d4848e0ee0b",
      "name": "Switch"
    },
    {
      "parameters": {
        "chatId": "1674824514",
        "text": "=Te estoy notificando lo siguiente se envio una actividad relacionado con la siguiente Categoria:{{ $json.categoria }} y con un nivel de confianza {{ $json.confianza }} quien la envio:{{ $('campos').item.json.usuario }} tiene una prioroidad {{ $('campos').item.json.prioridad }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1136,
        400
      ],
      "id": "8b6ddb47-ddf0-4eef-827a-0bd57fe859ee",
      "name": "telegram",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "20ccdf18-4814-40d6-b986-b27c5d9e1472",
              "name": "usuario",
              "value": "={{ $('Webhook').item.json.body.usuario }}",
              "type": "string"
            },
            {
              "id": "a94af057-6026-4e3c-9aab-1b9d61745f6d",
              "name": "mensaje",
              "value": "={{ $('Webhook').item.json.body.mensaje }}",
              "type": "string"
            },
            {
              "id": "c61601f0-24eb-46b9-807d-f0ce3cddffd2",
              "name": "prioridad",
              "value": "={{ $('Code').item.json.body.prioridad }}",
              "type": "string"
            },
            {
              "id": "f884ee7d-d35d-4a38-bfb0-ac9b546cd073",
              "name": "fecha",
              "value": "={{ $now.format('yyyy-MM-dd') }}",
              "type": "string"
            },
            {
              "id": "02d90844-da88-4adc-8b3f-bdc4fa1c2739",
              "name": "flujo",
              "value": "={{ $workflow.name }}",
              "type": "string"
            },
            {
              "id": "b8a0fbf8-596d-481d-9685-eb2986a949fc",
              "name": "executive",
              "value": "={{ $execution.id }}",
              "type": "string"
            },
            {
              "id": "28a858a8-df82-4d1a-8afe-35ce8a0783bf",
              "name": "id",
              "value": "={{ $execution.mode }}",
              "type": "string"
            },
            {
              "id": "59a914b9-679a-4937-ac3a-dcae3357687c",
              "name": "mensaje_telegram",
              "value": "={{ $json.result.text }}",
              "type": "string"
            },
            {
              "id": "dba98fae-22e3-4467-8a23-ee0ea0df226a",
              "name": "ok",
              "value": "={{ $json.ok }}",
              "type": "boolean"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1360,
        400
      ],
      "id": "410d90c4-ad6b-4340-bda7-9ba0e8dedfb6",
      "name": "resultado"
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "<!DOCTYPE html>\n<html lang=\"es\">\n\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Asistente Interno</title>\n    <link href=\"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap\" rel=\"stylesheet\">\n    <style>\n        :root {\n            --primary: #6366f1;\n            --primary-hover: #4f46e5;\n            --bg-start: #0f172a;\n            --bg-end: #1e1b4b;\n            --text-main: #f8fafc;\n            --text-muted: #94a3b8;\n            --glass-bg: rgba(255, 255, 255, 0.05);\n            --glass-border: rgba(255, 255, 255, 0.1);\n        }\n\n        * {\n            box-sizing: border-box;\n            margin: 0;\n            padding: 0;\n            font-family: 'Inter', sans-serif;\n        }\n\n        body {\n            min-height: 100vh;\n            display: flex;\n            align-items: center;\n            justify-content: center;\n            background: linear-gradient(135deg, var(--bg-start), var(--bg-end));\n            color: var(--text-main);\n            padding: 20px;\n        }\n\n        .container {\n            width: 100%;\n            max-width: 420px;\n            background: var(--glass-bg);\n            backdrop-filter: blur(16px);\n            -webkit-backdrop-filter: blur(16px);\n            border: 1px solid var(--glass-border);\n            border-radius: 24px;\n            padding: 40px 32px;\n            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);\n            animation: slideUp 0.6s ease-out;\n        }\n\n        @keyframes slideUp {\n            from {\n                opacity: 0;\n                transform: translateY(20px);\n            }\n\n            to {\n                opacity: 1;\n                transform: translateY(0);\n            }\n        }\n\n        .header {\n            text-align: center;\n            margin-bottom: 32px;\n        }\n\n        .header h1 {\n            font-size: 24px;\n            font-weight: 600;\n            margin-bottom: 8px;\n            background: linear-gradient(to right, #818cf8, #c084fc);\n            -webkit-background-clip: text;\n            -webkit-text-fill-color: transparent;\n        }\n\n        .header p {\n            color: var(--text-muted);\n            font-size: 14px;\n        }\n\n        .form-group {\n            margin-bottom: 24px;\n        }\n\n        .form-group label {\n            display: block;\n            font-size: 14px;\n            font-weight: 500;\n            margin-bottom: 8px;\n            color: var(--text-main);\n        }\n\n        .form-control {\n            width: 100%;\n            background: rgba(0, 0, 0, 0.2);\n            border: 1px solid var(--glass-border);\n            border-radius: 12px;\n            padding: 14px 16px;\n            color: var(--text-main);\n            font-size: 15px;\n            transition: all 0.3s ease;\n        }\n\n        .form-control::placeholder {\n            color: var(--text-muted);\n        }\n\n        .form-control:focus {\n            outline: none;\n            border-color: var(--primary);\n            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);\n            background: rgba(0, 0, 0, 0.3);\n        }\n\n        textarea.form-control {\n            resize: vertical;\n            min-height: 120px;\n        }\n\n        .submit-btn {\n            width: 100%;\n            background: var(--primary);\n            color: white;\n            border: none;\n            border-radius: 12px;\n            padding: 16px;\n            font-size: 16px;\n            font-weight: 600;\n            cursor: pointer;\n            transition: all 0.3s ease;\n            display: flex;\n            justify-content: center;\n            align-items: center;\n            gap: 8px;\n        }\n\n        .submit-btn:hover {\n            background: var(--primary-hover);\n            transform: translateY(-2px);\n            box-shadow: 0 10px 20px -10px var(--primary);\n        }\n\n        .submit-btn:active {\n            transform: translateY(0);\n        }\n\n        .submit-btn.loading {\n            opacity: 0.8;\n            cursor: not-allowed;\n            pointer-events: none;\n        }\n\n        .spinner {\n            display: none;\n            width: 20px;\n            height: 20px;\n            border: 3px solid rgba(255, 255, 255, 0.3);\n            border-radius: 50%;\n            border-top-color: white;\n            animation: spin 1s ease-in-out infinite;\n        }\n\n        @keyframes spin {\n            to {\n                transform: rotate(360deg);\n            }\n        }\n\n        .status-message {\n            margin-top: 16px;\n            padding: 12px;\n            border-radius: 8px;\n            font-size: 14px;\n            text-align: center;\n            opacity: 0;\n            transition: opacity 0.3s ease;\n            display: none;\n        }\n\n        .status-message.success {\n            display: block;\n            background: rgba(16, 185, 129, 0.1);\n            color: #34d399;\n            border: 1px solid rgba(16, 185, 129, 0.2);\n            opacity: 1;\n        }\n\n        .status-message.error {\n            display: block;\n            background: rgba(239, 68, 68, 0.1);\n            color: #f87171;\n            border: 1px solid rgba(239, 68, 68, 0.2);\n            opacity: 1;\n        }\n    </style>\n</head>\n\n<body>\n\n    <div class=\"container\">\n        <div class=\"header\">\n            <h1>Asistente Interno</h1>\n            <p>Env\u00eda tu petici\u00f3n de forma segura y r\u00e1pida.</p>\n        </div>\n\n        <form id=\"apiRequestForm\">\n            <div class=\"form-group\">\n                <label for=\"usuario\">Usuario</label>\n                <input type=\"text\" id=\"usuario\" class=\"form-control\" placeholder=\"Ej. jperez\" required\n                    autocomplete=\"username\">\n            </div>\n\n            <div class=\"form-group\">\n                <label for=\"mensaje\">Mensaje</label>\n                <textarea id=\"mensaje\" class=\"form-control\" placeholder=\"Escribe tu petici\u00f3n aqu\u00ed...\"\n                    required></textarea>\n            </div>\n\n            <button type=\"submit\" class=\"submit-btn\" id=\"submitBtn\">\n                <span>Enviar Petici\u00f3n</span>\n                <div class=\"spinner\" id=\"spinner\"></div>\n            </button>\n        </form>\n\n        <div id=\"statusMessage\" class=\"status-message\"></div>\n    </div>\n\n    <script>\n        document.getElementById('apiRequestForm').addEventListener('submit', async function (e) {\n            e.preventDefault();\n\n            const usuario = document.getElementById('usuario').value.trim();\n            const mensaje = document.getElementById('mensaje').value.trim();\n            const submitBtn = document.getElementById('submitBtn');\n            const spinner = document.getElementById('spinner');\n            const btnText = submitBtn.querySelector('span');\n            const statusMessage = document.getElementById('statusMessage');\n\n            // Reset status\n            statusMessage.className = 'status-message';\n            statusMessage.textContent = '';\n\n            // Set loading state\n            submitBtn.classList.add('loading');\n            btnText.textContent = 'Enviando...';\n            spinner.style.display = 'block';\n\n            const payload = {\n                usuario: usuario,\n                mensaje: mensaje\n            };\n\n            const webhookUrl = 'http://localhost:5678/webhook-test/asistente-interno';\n\n            try {\n                const response = await fetch(webhookUrl, {\n                    method: 'POST',\n                    headers: {\n                        'Content-Type': 'application/json'\n                    },\n                    body: JSON.stringify(payload)\n                });\n\n                if (response.ok) {\n                    statusMessage.textContent = '\u00a1Petici\u00f3n enviada con \u00e9xito!';\n                    statusMessage.classList.add('success');\n                    this.reset(); // Clear form\n                } else {\n                    throw new Error('Error en la respuesta del servidor');\n                }\n            } catch (error) {\n                console.error('Error:', error);\n                statusMessage.textContent = 'Hubo un error al enviar la petici\u00f3n. Intenta de nuevo.';\n                statusMessage.classList.add('error');\n            } finally {\n                // Reset loading state\n                submitBtn.classList.remove('loading');\n                btnText.textContent = 'Enviar Petici\u00f3n';\n                spinner.style.display = 'none';\n\n                // Hide status message after 5 seconds\n                setTimeout(() => {\n                    statusMessage.className = 'status-message';\n                }, 5000);\n            }\n        });\n    </script>\n</body>\n\n</html>",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        16,
        272
      ],
      "id": "f08c53b2-89a3-41f9-9d46-ae5baec24db6",
      "name": "PaginaWeb",
      "alwaysOutputData": false
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "PaginaWeb",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Call 'AgenteIAClasificador'",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "RespuestaNegativa",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "campos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "campos": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call 'AgenteIAClasificador'": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "telegram",
            "type": "main",
            "index": 0
          }
        ],
        [],
        [],
        []
      ]
    },
    "telegram": {
      "main": [
        [
          {
            "node": "resultado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "resultado": {
      "main": [
        [
          {
            "node": "RespuestaPositiva",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PaginaWeb": {
      "main": [
        []
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "9a83d5c4-dc11-4267-9cab-ecaf25a9975a",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "RceYN4K22pa16X1z",
  "tags": [
    {
      "updatedAt": "2026-03-18T06:36:57.910Z",
      "createdAt": "2026-03-18T06:36:57.910Z",
      "id": "Y8lIAmQ79VYNbGjw",
      "name": "FlujoPrincipal"
    }
  ]
}