{ "updatedAt": "2026-06-10T03:42:28.252Z", "createdAt": "2026-06-08T20:09:28.132Z", "id": "sXH75CXIQ0sEzm1Y", "name": "Chat de WhatsApp - Propuestas Ejecutadas", "description": null, "active": true, "isArchived": false, "nodes": [ { "parameters": { "method": "POST", "url": "={{'https://wsp.gomezleemarketing.com'}}/message/sendText/{{'botsoporte'}}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "apikey", "value": "={{'C267126ABB45-4C12-B626-6BAB1833F5D7'}}" } ] }, "sendBody": true, "bodyParameters": { "parameters": [ { "name": "number", "value": "={{ $json.whatsapp_to || $json.whatsapp_remote_jid || $json.manager_telefono }}" }, { "name": "delay", "value": "={{ 1000 }}" }, { "name": "text", "value": "={{ $json.whatsapp_text || $json.telegram_text || $json.texto_respuesta || $json.mensaje || $json.text || 'Mensaje sin contenido' }}" } ] }, "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 7744, -112 ], "id": "b1d4c2c3-c77f-4b9d-b4ca-c40535c26299", "name": "WhatsApp - Enviar mensaje TEST" }, { "parameters": { "jsCode": "const input = $json || {};\nconst body = input.body || input;\nconst data = body.data || {};\n\nconst texto = (valor) => String(valor ?? '').trim();\n\nconst limpiarNumero = (valor) =>\n texto(valor)\n .replace('@s.whatsapp.net', '')\n .replace('@c.us', '')\n .replace('@g.us', '')\n .replace(/\\D/g, '');\n\nconst key = data.key || {};\n\nconst remoteJid = texto(key.remoteJid || data.remoteJid || body.remoteJid || '');\nconst managerTelefono = limpiarNumero(remoteJid);\n\nconst pushName =\n texto(data.pushName) ||\n texto(body.pushName) ||\n 'Usuario WhatsApp';\n\nconst message = data.message || {};\n\nconst textoMensaje =\n texto(message.conversation) ||\n texto(message.extendedTextMessage?.text) ||\n texto(data.messageText) ||\n texto(data.text) ||\n texto(body.text) ||\n '';\n\nlet messageType = 'unknown';\n\nif (message.audioMessage) {\n messageType = 'audio';\n} else if (message.imageMessage) {\n messageType = 'image';\n} else if (message.videoMessage) {\n messageType = 'video';\n} else if (textoMensaje) {\n messageType = 'text';\n}\n\nconst tieneMedia = ['audio', 'image', 'video'].includes(messageType);\n\nconst mediaMimeType =\n texto(message.audioMessage?.mimetype) ||\n texto(message.imageMessage?.mimetype) ||\n texto(message.videoMessage?.mimetype) ||\n '';\n\nconst mediaSourceId =\n texto(key.id) ||\n texto(data.id) ||\n texto(data.messageId) ||\n '';\n\nconst normalizarComando = (valor) => {\n const t = texto(valor)\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toUpperCase();\n\n if (t === '/START' || t === 'START' || t === 'INICIAR') return 'START';\n if (t === 'CANCELAR') return 'CANCELAR';\n if (t === 'FOTOS LISTAS' || t === 'FOTOS_LISTAS') return 'FOTOS_LISTAS';\n if (t === 'SIN VIDEO' || t === 'SIN_VIDEO') return 'SIN_VIDEO';\n if (t === 'LISTO') return 'LISTO';\n\n return 'NORMAL';\n};\n\nreturn [\n {\n json: {\n event_id: texto(key.id || data.id || Date.now()),\n fecha_recepcion: new Date().toISOString(),\n\n canal_origen: 'WHATSAPP',\n\n manager_telefono: managerTelefono,\n manager_nombre: pushName,\n usuario_id_origen: managerTelefono,\n\n whatsapp_remote_jid: remoteJid,\n whatsapp_to: remoteJid,\n\n from_me: Boolean(key.fromMe || data.fromMe || false),\n\n message_type: messageType,\n texto: textoMensaje,\n accion_flujo: normalizarComando(textoMensaje),\n\n tiene_media: tieneMedia,\n media_count: tieneMedia ? 1 : 0,\n media_source_id: mediaSourceId,\n media_mime_type: mediaMimeType,\n media_file_name: '',\n\n raw_preview: JSON.stringify(body).slice(0, 4000),\n raw_event: body,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 208, -256 ], "id": "35e401ba-acce-429c-b811-58a45c032869", "name": "Code - Normalizar evento WhatsApp TEST" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "f2be1fb5-b047-4614-a1f2-9a4d65ef5cc7", "leftValue": "={{ $json.manager_telefono === '18298946645' }}", "rightValue": "={{ $json.manager_telefono === '18298946645' }}", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ 480, -256 ], "id": "3b65e795-a7f8-415c-8c04-7cde544c4350", "name": "Mi numero TESTING" }, { "parameters": { "httpMethod": "POST", "path": "factura", "options": {} }, "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [ 0, -256 ], "id": "bbdd46ca-d2f0-4c42-8e14-d9591168cf4d", "name": "Webhook - Evolution WhatsApp TEST", "webhookId": "e2e6c9c2-6c1e-453d-85f1-271056935828" }, { "parameters": { "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 848, -272 ], "id": "653ca576-1661-49aa-80cb-62b7ec46a1c0", "name": "Sheets - Leer sesiones existentes", "alwaysOutputData": true, "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const evento = $('Code - Normalizar evento WhatsApp TEST').first().json || {};\nconst sesiones = $input.all().map((item) => item.json || {});\n\nconst texto = (valor) => String(valor ?? '').trim();\n\nconst estadosAbiertos = new Set([\n 'ACTIVA',\n 'PENDIENTE',\n 'EN_PROCESO',\n 'PROCESANDO',\n 'LISTO_PARA_RECUPERAR_MEDIA',\n 'LISTO_PARA_ANALIZAR',\n]);\n\nconst etapasAbiertas = new Set([\n 'ESPERANDO_AUDIO',\n 'ESPERANDO_IMAGENES',\n 'ESPERANDO_VIDEOS',\n 'PROCESANDO',\n]);\n\nconst managerTelefono = texto(evento.manager_telefono);\nconst accion = texto(evento.accion_flujo || 'NORMAL');\n\nconst sesionActiva = sesiones\n .filter((row) => texto(row.manager_telefono) === managerTelefono)\n .filter((row) => {\n const estado = texto(row.estado).toUpperCase();\n const etapa = texto(row.etapa).toUpperCase();\n\n return estadosAbiertos.has(estado) || etapasAbiertas.has(etapa);\n })\n .sort((a, b) => {\n return new Date(b.ultima_actividad || b.fecha_inicio || 0) - new Date(a.ultima_actividad || a.fecha_inicio || 0);\n })[0] || null;\n\nconst suffix = Math.random().toString(36).slice(2, 6).toUpperCase();\nconst sessionId = `WA_${Date.now()}_${managerTelefono.slice(-4)}_${suffix}`;\n\nlet decision = '';\n\nif (accion === 'START') {\n decision = sesionActiva ? 'AVISO_SESION_ACTIVA' : 'CREAR_SESION';\n} else if (accion === 'CANCELAR') {\n decision = sesionActiva ? 'CANCELAR_SESION' : 'SIN_SESION_PARA_CANCELAR';\n} else {\n decision = sesionActiva ? 'CONTINUAR_SESION' : 'SIN_SESION_ACTIVA';\n}\n\nreturn [\n {\n json: {\n ...evento,\n\n sesion_activa_encontrada: Boolean(sesionActiva),\n sesion_activa: sesionActiva,\n\n session_id: sesionActiva ? texto(sesionActiva.session_id) : sessionId,\n ejecucion_id: sesionActiva ? texto(sesionActiva.ejecucion_id || sesionActiva.session_id) : sessionId,\n\n decision_flujo: decision,\n\n nueva_sesion: {\n session_id: sessionId,\n manager_telefono: managerTelefono,\n manager_nombre: texto(evento.manager_nombre),\n canal_origen: 'WHATSAPP',\n fecha_inicio: new Date().toISOString(),\n ultima_actividad: new Date().toISOString(),\n etapa: 'ESPERANDO_AUDIO',\n audio_count: 0,\n imagenes_count: 0,\n videos_count: 0,\n estado: 'ACTIVA',\n ejecucion_id: sessionId,\n motivo_revision: '',\n },\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1040, -272 ], "id": "91675542-137d-4976-9c1c-3ba26bb1ddab", "name": "Code - Resolver sesión WhatsApp TEST" }, { "parameters": { "rules": { "values": [ { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "leftValue": "={{ $json.decision_flujo === 'CREAR_SESION' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true }, "id": "acec6506-977a-412d-b08a-fbcc8de4b0b8" } ], "combinator": "and" }, "renameOutput": true, "outputKey": "CREAR_SESION" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "5c9dcfa5-9b15-428c-ad80-c277b0671658", "leftValue": "={{ $json.decision_flujo === 'AVISO_SESION_ACTIVA' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "AVISO_SESION_ACTIVA" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "966402b5-4517-45c2-8a87-0a7aa4e5e682", "leftValue": "={{ $json.decision_flujo === 'SIN_SESION_ACTIVA' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "SIN_SESION_ACTIVA" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "698f3da3-29d2-472f-b625-af387891035e", "leftValue": "={{ $json.decision_flujo === 'CANCELAR_SESION' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "CANCELAR_SESION" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "d5feac06-4493-494e-ac1e-36c007f0de79", "leftValue": "={{ $json.decision_flujo === 'SIN_SESION_PARA_CANCELAR' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "SIN_SESION_PARA_CANCELAR" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "950979b7-b930-4260-a392-52277a742e43", "leftValue": "={{ $json.decision_flujo === 'CONTINUAR_SESION' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "CONTINUAR_SESION" } ] }, "options": {} }, "type": "n8n-nodes-base.switch", "typeVersion": 3.4, "position": [ 1264, -336 ], "id": "50d7bb39-3a6d-4906-b695-e6b09ba5c545", "name": "Switch - Decisión sesión WhatsApp TEST" }, { "parameters": { "jsCode": "const datos = $('Code - Resolver sesión WhatsApp TEST').first().json || {};\n\nconst mensaje = [\n '📸 *Propuestas Ejecutadas - GLM*',\n '',\n `¡Hola, ${datos.manager_nombre || 'equipo'}! Bienvenido al registro de propuestas ejecutadas.`,\n '',\n 'Este proceso permite documentar ejecuciones reales para alimentar el banco de evidencias de Fulgencio Fumado.',\n '',\n '*Paso 1 de 3 — Nota de voz obligatoria*',\n '',\n 'Envía una nota de voz indicando:',\n '',\n '• Nombre o referencia de la propuesta ejecutada',\n '• Marca o cliente',\n '• País',\n '• Ubicación de la ejecución',\n '• Fecha de ejecución',\n '• Qué se implementó',\n '• Comentarios o resultados observados',\n '',\n 'Importante: registra una sola propuesta ejecutada a la vez.',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3104, -2304 ], "id": "304baef0-fda7-43ce-8bfe-24ed684ced3b", "name": "Code - Preparar bienvenida WhatsApp TEST" }, { "parameters": { "jsCode": "const datos = $json || {};\n\nconst etapa = String(datos.sesion_activa?.etapa || '').trim() || 'pendiente';\n\nconst mensaje = [\n '⚠️ Ya tienes un reporte de propuesta ejecutada en proceso.',\n '',\n `Etapa actual: ${etapa}`,\n '',\n 'Completa ese reporte antes de iniciar uno nuevo.',\n '',\n 'Si deseas cancelarlo, escribe: CANCELAR',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3136, -1856 ], "id": "bf9701ac-00d2-47c3-a495-ddaad66ed0be", "name": "Code - Preparar aviso sesión activa WhatsApp TEST" }, { "parameters": { "operation": "append", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.nueva_sesion.session_id }}", "manager_telefono": "={{ $json.nueva_sesion.manager_telefono }}", "manager_nombre": "={{ $json.nueva_sesion.manager_nombre }}", "canal_origen": "={{ $json.nueva_sesion.canal_origen }}", "fecha_inicio": "={{ $json.nueva_sesion.fecha_inicio }}", "ultima_actividad": "={{ $json.nueva_sesion.ultima_actividad }}", "etapa": "={{ $json.nueva_sesion.etapa }}", "audio_count": "={{ $json.nueva_sesion.audio_count }}", "imagenes_count": "={{ $json.nueva_sesion.imagenes_count }}", "videos_count": "={{ $json.nueva_sesion.videos_count }}", "estado": "={{ $json.nueva_sesion.estado }}", "ejecucion_id": "={{ $json.nueva_sesion.ejecucion_id }}", "motivo_revision": "={{ $json.nueva_sesion.motivo_revision }}" }, "matchingColumns": [], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 2896, -2304 ], "id": "cff69027-2e70-4be6-ad78-80ae6680ca75", "name": "Sheets - Crear sesión WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const datos = $json || {};\n\nconst texto = (valor) => String(valor ?? '').trim();\n\nconst etapa = texto(datos.sesion_activa?.etapa).toUpperCase();\nconst tipoMensaje = texto(datos.message_type).toLowerCase();\nconst accion = texto(datos.accion_flujo).toUpperCase();\n\nconst imagenesCount = Number(datos.sesion_activa?.imagenes_count || 0);\nconst videosCount = Number(datos.sesion_activa?.videos_count || 0);\n\nlet paso_decision = 'NO_DEFINIDO';\n\n// --------------------------------------------------\n// 1. Cancelación global\n// --------------------------------------------------\nif (accion === 'CANCELAR') {\n paso_decision = 'CANCELAR_SESION';\n\n// --------------------------------------------------\n// 2. Paso 1: esperando nota de voz\n// --------------------------------------------------\n} else if (etapa === 'ESPERANDO_AUDIO') {\n if (tipoMensaje === 'audio') {\n paso_decision = 'GUARDAR_AUDIO';\n } else {\n paso_decision = 'PEDIR_AUDIO';\n }\n\n// --------------------------------------------------\n// 3. Paso 2: esperando imágenes obligatorias\n// --------------------------------------------------\n} else if (etapa === 'ESPERANDO_IMAGENES') {\n if (tipoMensaje === 'image') {\n paso_decision = 'GUARDAR_IMAGEN';\n } else if (accion === 'FOTOS_LISTAS') {\n // Solo permite avanzar si ya hay al menos una imagen registrada.\n if (imagenesCount > 0) {\n paso_decision = 'FOTOS_LISTAS';\n } else {\n paso_decision = 'PEDIR_IMAGENES';\n }\n } else {\n paso_decision = 'PEDIR_IMAGENES';\n }\n\n// --------------------------------------------------\n// 4. Paso 3: esperando videos opcionales\n// --------------------------------------------------\n} else if (etapa === 'ESPERANDO_VIDEOS') {\n if (tipoMensaje === 'video') {\n paso_decision = 'GUARDAR_VIDEO';\n } else if (accion === 'SIN_VIDEO') {\n paso_decision = 'CERRAR_SIN_VIDEO';\n } else if (accion === 'LISTO') {\n paso_decision = 'CERRAR_CON_VIDEOS';\n } else {\n paso_decision = 'PEDIR_VIDEOS';\n }\n\n// --------------------------------------------------\n// 5. Sesión en procesamiento\n// --------------------------------------------------\n} else if (etapa === 'PROCESANDO') {\n paso_decision = 'AVISO_PROCESANDO';\n\n// --------------------------------------------------\n// 6. Etapa no reconocida\n// --------------------------------------------------\n} else {\n paso_decision = 'ETAPA_NO_RECONOCIDA';\n}\n\nreturn [\n {\n json: {\n ...datos,\n\n etapa_actual: etapa,\n tipo_mensaje_actual: tipoMensaje,\n accion_actual: accion,\n\n imagenes_count_actual: imagenesCount,\n videos_count_actual: videosCount,\n\n paso_decision,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1552, 144 ], "id": "28aaa567-1c39-49ac-802d-38e001d71cc2", "name": "Code - Resolver paso activo WhatsApp TEST" }, { "parameters": { "rules": { "values": [ { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "leftValue": "={{ $json.paso_decision === 'GUARDAR_AUDIO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true }, "id": "c7fef2d7-50ce-467a-b125-30ae7fba3a58" } ], "combinator": "and" }, "renameOutput": true, "outputKey": "GUARDAR_AUDIO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "8da042cf-54e6-460f-b505-2b17c4f4ff3c", "leftValue": "={{ $json.paso_decision === 'PEDIR_AUDIO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "PEDIR_AUDIO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "ecf52241-ef7e-4a9a-8823-b9e3b438da61", "leftValue": "={{ $json.paso_decision === 'GUARDAR_AUDIO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "GUARDAR_AUDIO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "04433553-d0ee-4391-a4f4-926197ac4c0c", "leftValue": "={{ $json.paso_decision === 'PEDIR_AUDIO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "PEDIR_AUDIO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "8637dc0f-59b6-40ac-8bc4-baf869829598", "leftValue": "={{ $json.paso_decision === 'GUARDAR_IMAGEN' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "GUARDAR_IMAGEN" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "4096e616-2517-48ab-b6c4-2712f763ec1d", "leftValue": "={{ $json.paso_decision === 'FOTOS_LISTAS' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "FOTOS_LISTAS" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "d1dd1d5c-8e25-4147-876e-5e7227784f6f", "leftValue": "={{ $json.paso_decision === 'PEDIR_IMAGENES' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "PEDIR_IMAGENES" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "bddbb16a-0463-47dd-9a6c-03c3635043f1", "leftValue": "={{ $json.paso_decision === 'GUARDAR_VIDEO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "GUARDAR_VIDEO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "fe05ba35-0ccc-417a-a4e8-b907611932e4", "leftValue": "={{ $json.paso_decision === 'CERRAR_SIN_VIDEO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "CERRAR_SIN_VIDEO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "94647ac0-ee80-4c96-9f25-8a847704b6a0", "leftValue": "={{ $json.paso_decision === 'CERRAR_CON_VIDEOS' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "CERRAR_CON_VIDEOS" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "3038a656-50ae-4738-b2ff-a6276bd06522", "leftValue": "={{ $json.paso_decision === 'PEDIR_VIDEOS' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "PEDIR_VIDEOS" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "1b20a524-2289-4d37-8372-9a839dadc971", "leftValue": "={{ $json.paso_decision === 'AVISO_PROCESANDO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "AVISO_PROCESANDO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "0943bbd0-f5b7-43c4-9b01-7f6bea244894", "leftValue": "={{ $json.paso_decision === 'ETAPA_NO_RECONOCIDA' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "ETAPA_NO_RECONOCIDA" } ] }, "options": {} }, "type": "n8n-nodes-base.switch", "typeVersion": 3.4, "position": [ 1904, 416 ], "id": "b8b395eb-8f3f-4006-8ad8-d426f7e0792a", "name": "Switch - Paso activo WhatsApp TEST" }, { "parameters": { "jsCode": "const datos = $json || {};\n\nconst mensaje = [\n '🎙️ Aún necesito la nota de voz obligatoria para iniciar el reporte.',\n '',\n 'Por favor envía una nota de voz indicando:',\n '',\n '• Nombre o referencia de la propuesta ejecutada',\n '• Marca o cliente',\n '• País',\n '• Ubicación de la ejecución',\n '• Fecha de ejecución',\n '• Qué se implementó',\n '• Comentarios o resultados observados',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2912, -224 ], "id": "30196ae5-1d82-46e3-9296-32ffa6122ae1", "name": "Code - Preparar solicitud audio WhatsApp TEST" }, { "parameters": { "operation": "append", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 306129743, "mode": "list", "cachedResultName": "wa_ejecuciones_eventos", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=306129743" }, "columns": { "mappingMode": "defineBelow", "value": { "event_id": "={{ $json.event_id }}", "fecha_recepcion": "={{ $json.fecha_recepcion }}", "manager_telefono": "={{ $json.manager_telefono }}", "manager_nombre": "={{ $json.manager_nombre }}", "message_type": "={{ $json.message_type }}", "texto": "={{ $json.texto }}", "comando": "={{ $json.accion_flujo }}", "tiene_media": "={{ $json.tiene_media }}", "media_count": "={{ $json.media_count }}", "raw_preview": "={{ $json.raw_preview }}", "estado": "={{ $json.estado }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "fecha_procesado": "={{ $json.fecha_procesado }}", "session_id": "={{ $json.session_id }}", "canal_origen": "={{ $json.canal_origen }}", "etapa_recibida": "={{ $json.etapa_recibida }}" }, "matchingColumns": [], "schema": [ { "id": "event_id", "displayName": "event_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_recepcion", "displayName": "fecha_recepcion", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "message_type", "displayName": "message_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "texto", "displayName": "texto", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "comando", "displayName": "comando", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "tiene_media", "displayName": "tiene_media", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_count", "displayName": "media_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "raw_preview", "displayName": "raw_preview", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_procesado", "displayName": "fecha_procesado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa_recibida", "displayName": "etapa_recibida", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 2624, -608 ], "id": "4b7309e9-5602-4c88-b29f-42e44179f445", "name": "Sheets - Guardar evento audio WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const datos = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\n\nreturn [\n {\n json: {\n ...datos,\n session_id: datos.session_id,\n ultima_actividad: new Date().toISOString(),\n etapa: 'ESPERANDO_IMAGENES',\n estado: 'ACTIVA',\n audio_count: Number(datos.sesion_activa?.audio_count || 0) + 1,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2832, -608 ], "id": "25599b76-fe73-44b6-80f5-1d8ba9616fd1", "name": "Code - Preparar actualización audio recibido WhatsApp TEST" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ultima_actividad": "={{ $json.ultima_actividad }}", "etapa": "={{ $json.etapa }}", "estado": "={{ $json.estado }}", "audio_count": "={{ $json.audio_count }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3040, -608 ], "id": "35b5002d-7c69-4f31-89de-dc5457961a42", "name": "Sheets - Actualizar sesión audio recibido WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const datos = $('Code - Preparar actualización audio recibido WhatsApp TEST').first().json || {};\n\nconst mensaje = [\n '✅ Nota de voz recibida.',\n '',\n '*Paso 2 de 3 — Imágenes obligatorias*',\n '',\n 'Ahora envía al menos una foto de la propuesta ejecutada.',\n '',\n 'Puedes enviar varias imágenes seguidas.',\n '',\n 'Cuando termines de enviar las imágenes, escribe: FOTOS LISTAS',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3264, -608 ], "id": "7c1c09aa-4670-47d0-a5a5-3713adf6b6fb", "name": "Code - Preparar solicitud imágenes WhatsApp TEST" }, { "parameters": { "jsCode": "const datos = $json || {};\n\nreturn [\n {\n json: {\n ...datos,\n session_id: datos.session_id,\n ultima_actividad: new Date().toISOString(),\n etapa: 'CANCELADA',\n estado: 'CANCELADA',\n motivo_revision: 'CANCELADO_POR_USUARIO',\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3008, -1040 ], "id": "dd118cad-907f-4bab-89ef-8d75dc2d70cb", "name": "Code - Preparar cancelación sesión WhatsApp TEST" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ultima_actividad": "={{ $json.ultima_actividad }}", "etapa": "={{ $json.etapa }}", "estado": "={{ $json.estado }}", "motivo_revision": "={{ $json.motivo_revision }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3216, -1040 ], "id": "ac83d38f-7d91-408a-bb43-f8950ccc40a6", "name": "Sheets - Cancelar sesión WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const datos = $('Code - Preparar cancelación sesión WhatsApp TEST').first().json || {};\n\nconst mensaje = [\n '✅ Reporte cancelado correctamente.',\n '',\n 'Ya puedes iniciar un nuevo reporte escribiendo:',\n '',\n '/start',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3472, -1104 ], "id": "119da00c-cea5-4184-90e5-ad4a408271bb", "name": "Code - Preparar mensaje cancelación WhatsApp TEST" }, { "parameters": { "jsCode": "const datos = $json || {};\n\nconst mensaje = [\n '⚠️ No tienes un reporte activo para cancelar.',\n '',\n 'Para iniciar uno nuevo, escribe:',\n '',\n '/start',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3216, -1488 ], "id": "be56aeb8-916d-46b2-b2a2-b544a4bdbd01", "name": "ode - Preparar sin sesión para cancelar WhatsApp TEST" }, { "parameters": { "jsCode": "const evento = $json || {};\nconst base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst ahora = new Date().toISOString();\n\nconst imagenesActuales = Number(sesion.imagenes_count || 0);\n\nreturn [\n {\n json: {\n ...base,\n ...evento,\n\n session_id: base.session_id || sesion.session_id || evento.session_id || '',\n manager_telefono: sesion.manager_telefono || base.manager_telefono || evento.manager_telefono || '',\n manager_nombre: sesion.manager_nombre || base.manager_nombre || evento.manager_nombre || '',\n canal_origen: sesion.canal_origen || base.canal_origen || 'WHATSAPP',\n\n fecha_inicio: sesion.fecha_inicio || '',\n ultima_actividad: ahora,\n\n // IMPORTANTE:\n // Después de recibir una imagen, todavía seguimos esperando más imágenes\n // hasta que el usuario escriba FOTOS LISTAS.\n etapa: 'ESPERANDO_IMAGENES',\n\n audio_count: Number(sesion.audio_count || 0),\n imagenes_count: imagenesActuales + 1,\n videos_count: Number(sesion.videos_count || 0),\n\n estado: sesion.estado || 'ACTIVA',\n ejecucion_id: sesion.ejecucion_id || base.ejecucion_id || base.session_id || '',\n motivo_revision: sesion.motivo_revision || '',\n\n whatsapp_to: base.whatsapp_to || base.whatsapp_remote_jid || evento.whatsapp_to || evento.whatsapp_remote_jid || ''\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3904, -16 ], "id": "dee83381-1061-405c-978f-33403362f74b", "name": "Code — Preparar actualización imagen recibida" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "motivo_revision": "={{ $json.motivo_revision }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "estado": "={{ $json.estado }}", "videos_count": "={{ $json.videos_count }}", "imagenes_count": "={{ $json.imagenes_count }}", "audio_count": "={{ $json.audio_count }}", "etapa": "={{ $json.etapa }}", "ultima_actividad": "={{ $json.ultima_actividad }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 4112, -16 ], "id": "392c7a6c-3ab8-4f56-8742-8ab4ffdd5a4c", "name": "Sheets — Actualizar sesión imagen recibida", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\n\nconst nombre = String(data.manager_nombre || base.manager_nombre || '').trim();\nconst saludo = nombre ? `, ${nombre}` : '';\n\nconst telefono = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefono.includes('@s.whatsapp.net')\n ? telefono\n : `${telefono.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `✅ Imagen recibida${saludo}.\n\nPuedes enviar más fotos si hace falta.\n\nCuando termines de enviar las imágenes, escribe *FOTOS LISTAS*.`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 4320, -16 ], "id": "ebc7dadc-6ddc-4806-8c19-7d4e2ce567cf", "name": "Code — Preparar confirmación imagen" }, { "parameters": { "operation": "append", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 306129743, "mode": "list", "cachedResultName": "wa_ejecuciones_eventos", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=306129743" }, "columns": { "mappingMode": "defineBelow", "value": { "event_id": "=", "manager_telefono": "=", "manager_nombre": "=", "tiene_media": "=", "estado": "=IMAGEN_RECIBIDA", "session_id": "={{ $json.session_id }}", "canal_origen": "=WHATSAPP", "fecha_recepcion": "={{ $json.fecha_recepcion }}", "message_type": "={{ $json.message_type }}", "texto": "={{ $json.texto }}", "media_count": "={{ $json.media_count }}", "raw_preview": "={{ $json.raw_preview }}", "etapa_recibida": "={{ $json.etapa_actual }}" }, "matchingColumns": [], "schema": [ { "id": "event_id", "displayName": "event_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_recepcion", "displayName": "fecha_recepcion", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "message_type", "displayName": "message_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "texto", "displayName": "texto", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "comando", "displayName": "comando", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "tiene_media", "displayName": "tiene_media", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_count", "displayName": "media_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "raw_preview", "displayName": "raw_preview", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_procesado", "displayName": "fecha_procesado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa_recibida", "displayName": "etapa_recibida", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3632, -16 ], "id": "f8cf4436-cf35-45d6-acc7-7adfb9e3a2dc", "name": "Sheets - Guardar evento imagen WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $json || {};\n\nconst telefono = data.manager_telefono || data.whatsapp_to || '';\nconst nombre = String(data.manager_nombre || '').trim();\n\nconst saludo = nombre ? `, ${nombre}` : '';\n\nreturn [\n {\n json: {\n ...data,\n\n whatsapp_to: telefono,\n\n whatsapp_text: `📸 Necesito que me envíes al menos una imagen${saludo}.\n\nLa nota de voz ya fue recibida, pero para completar el reporte de propuesta ejecutada hace falta una foto de evidencia.\n\nPor favor envía una imagen y luego escribe *LISTO* cuando termines.`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3200, 512 ], "id": "75998ea0-d2ec-4614-b18e-824019627d72", "name": "Code - Preparar aviso falta imagen WhatsApp TEST" }, { "parameters": { "jsCode": "const base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst ahora = new Date().toISOString();\n\nreturn [\n {\n json: {\n ...base,\n\n session_id: base.session_id || sesion.session_id || '',\n manager_telefono: sesion.manager_telefono || base.manager_telefono || '',\n manager_nombre: sesion.manager_nombre || base.manager_nombre || '',\n canal_origen: sesion.canal_origen || base.canal_origen || 'WHATSAPP',\n\n fecha_inicio: sesion.fecha_inicio || '',\n ultima_actividad: ahora,\n\n // Avanzamos al paso 3\n etapa: 'ESPERANDO_VIDEOS',\n\n audio_count: Number(sesion.audio_count || 0),\n imagenes_count: Number(sesion.imagenes_count || 0),\n videos_count: Number(sesion.videos_count || 0),\n\n estado: 'ACTIVA',\n ejecucion_id: sesion.ejecucion_id || base.ejecucion_id || base.session_id || '',\n motivo_revision: sesion.motivo_revision || '',\n\n whatsapp_to: base.whatsapp_to || base.whatsapp_remote_jid || ''\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3536, 288 ], "id": "b0e3e960-8cc9-453e-bbf2-4e410ab4a178", "name": "Preparar actualización fotos listas" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ultima_actividad": "={{ $json.ultima_actividad }}", "etapa": "={{ $json.etapa }}", "audio_count": "={{ $json.audio_count }}", "imagenes_count": "={{ $json.imagenes_count }}", "videos_count": "={{ $json.videos_count }}", "estado": "={{ $json.estado }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "motivo_revision": "={{ $json.motivo_revision }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3744, 288 ], "id": "dea8b556-e019-40b3-97fc-04e1a47c1ed6", "name": "Sheets - Actualizar sesión fotos listas WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst nombre = String(\n data.manager_nombre ||\n sesion.manager_nombre ||\n base.manager_nombre ||\n ''\n).trim();\n\nconst saludo = nombre ? `, ${nombre}` : '';\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n sesion.manager_telefono ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `✅ Fotos registradas correctamente${saludo}.\n\n*Paso 3 de 3 — Videos opcionales*\n\nPuedes enviar uno o varios videos de la ejecución si tienes.\n\nSi no tienes videos, escribe: *SIN VIDEO*\n\nSi enviaste videos y ya terminaste, escribe: *LISTO*`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3952, 288 ], "id": "50b9bdba-c99b-4150-9a85-e57c18e24f5a", "name": "Code - Preparar solicitud videos WhatsApp TEST" }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n sesion.manager_telefono ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `🎥 Ya estamos en el paso de videos opcionales.\n\nPuedes enviar uno o varios videos de la ejecución.\n\nSi no tienes videos, escribe: *SIN VIDEO*\n\nSi ya enviaste videos y terminaste, escribe: *LISTO*`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3648, 1824 ], "id": "08b3a87f-00c6-439b-bcbe-131d86d100d5", "name": "Code - Preparar recordatorio videos WhatsApp TEST" }, { "parameters": { "jsCode": "const base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst ahora = new Date().toISOString();\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n sesion.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n\n session_id: base.session_id || sesion.session_id || '',\n manager_telefono: sesion.manager_telefono || base.manager_telefono || '',\n manager_nombre: sesion.manager_nombre || base.manager_nombre || '',\n canal_origen: sesion.canal_origen || base.canal_origen || 'WHATSAPP',\n\n fecha_inicio: sesion.fecha_inicio || '',\n ultima_actividad: ahora,\n\n etapa: 'PROCESANDO',\n estado: 'LISTO_PARA_RECUPERAR_MEDIA',\n\n audio_count: Number(sesion.audio_count || 0),\n imagenes_count: Number(sesion.imagenes_count || 0),\n videos_count: Number(sesion.videos_count || 0),\n\n ejecucion_id: sesion.ejecucion_id || base.ejecucion_id || base.session_id || '',\n motivo_revision: 'SIN_VIDEO_REPORTADO',\n\n whatsapp_to: whatsappTo\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3072, 1056 ], "id": "c4db0aed-c18e-429c-a6ff-299bd94d2797", "name": "CERRAR_SIN_VIDEO" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ultima_actividad": "={{ $json.ultima_actividad }}", "etapa": "={{ $json.etapa }}", "audio_count": "={{ $json.audio_count }}", "imagenes_count": "={{ $json.imagenes_count }}", "videos_count": "={{ $json.videos_count }}", "estado": "={{ $json.estado }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "motivo_revision": "={{ $json.motivo_revision }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3280, 1056 ], "id": "27195f01-98fa-4772-b0c6-d82b8241cc83", "name": "Sheets - Actualizar sesión cierre sin video WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('CERRAR_SIN_VIDEO').first().json || {};\n\nconst nombre = String(\n data.manager_nombre ||\n base.manager_nombre ||\n ''\n).trim();\n\nconst saludo = nombre ? `, ${nombre}` : '';\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `✅ Reporte recibido completo${saludo}.\n\nRegistré que no hay videos para esta ejecución.\n\nAhora voy a preparar el procesamiento de la nota de voz y las imágenes recibidas.`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3488, 1056 ], "id": "6384ba4f-b6d0-46c3-bfbe-63cf5f59a7e3", "name": "Code - Preparar confirmación cierre sin video WhatsApp TEST" }, { "parameters": { "operation": "append", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 306129743, "mode": "list", "cachedResultName": "wa_ejecuciones_eventos", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=306129743" }, "columns": { "mappingMode": "defineBelow", "value": { "event_id": "={{ $json.event_id }}", "fecha_recepcion": "={{ $json.fecha_recepcion }}", "manager_telefono": "={{ $json.manager_telefono }}", "manager_nombre": "={{ $json.manager_nombre }}", "message_type": "={{ $json.message_type }}", "texto": "={{ $json.texto }}", "comando": "={{ $json.accion_flujo }}", "tiene_media": "={{ $json.tiene_media }}", "media_count": "={{ $json.media_count }}", "raw_preview": "={{ $json.raw_preview }}", "estado": "=VIDEO_RECIBIDO", "ejecucion_id": "={{ $json.ejecucion_id }}", "session_id": "={{ $json.session_id }}", "canal_origen": "={{ $json.canal_origen }}", "etapa_recibida": "={{ $json.etapa_actual }}" }, "matchingColumns": [], "schema": [ { "id": "event_id", "displayName": "event_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_recepcion", "displayName": "fecha_recepcion", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "message_type", "displayName": "message_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "texto", "displayName": "texto", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "comando", "displayName": "comando", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "tiene_media", "displayName": "tiene_media", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_count", "displayName": "media_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "raw_preview", "displayName": "raw_preview", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_procesado", "displayName": "fecha_procesado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa_recibida", "displayName": "etapa_recibida", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3344, 688 ], "id": "c98b3d5e-cf77-46c6-9d5e-2b6222949656", "name": "Sheets - Guardar evento video WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const evento = $json || {};\nconst base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst ahora = new Date().toISOString();\n\nconst videosActuales = Number(sesion.videos_count || 0);\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n evento.whatsapp_to ||\n evento.whatsapp_remote_jid ||\n sesion.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...evento,\n\n session_id: base.session_id || sesion.session_id || evento.session_id || '',\n manager_telefono: sesion.manager_telefono || base.manager_telefono || evento.manager_telefono || '',\n manager_nombre: sesion.manager_nombre || base.manager_nombre || evento.manager_nombre || '',\n canal_origen: sesion.canal_origen || base.canal_origen || 'WHATSAPP',\n\n fecha_inicio: sesion.fecha_inicio || '',\n ultima_actividad: ahora,\n\n // Seguimos en videos hasta que el usuario escriba LISTO\n etapa: 'ESPERANDO_VIDEOS',\n\n audio_count: Number(sesion.audio_count || 0),\n imagenes_count: Number(sesion.imagenes_count || 0),\n videos_count: videosActuales + 1,\n\n estado: sesion.estado || 'ACTIVA',\n ejecucion_id: sesion.ejecucion_id || base.ejecucion_id || base.session_id || '',\n motivo_revision: sesion.motivo_revision || '',\n\n whatsapp_to: whatsappTo\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3552, 688 ], "id": "7bc3bb63-803e-43e9-9df7-1ed53a7597cb", "name": "Code - Preparar actualización video recibido WhatsApp TEST" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "motivo_revision": "={{ $json.motivo_revision }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "estado": "={{ $json.estado }}", "videos_count": "={{ $json.videos_count }}", "imagenes_count": "={{ $json.imagenes_count }}", "audio_count": "={{ $json.audio_count }}", "etapa": "={{ $json.etapa }}", "ultima_actividad": "={{ $json.ultima_actividad }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3760, 688 ], "id": "27556223-2f6f-464f-819a-a035a66e3aad", "name": "Sheets - Actualizar sesión video recibido WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('Code - Preparar actualización video recibido WhatsApp TEST').first().json || {};\n\nconst nombre = String(\n data.manager_nombre ||\n base.manager_nombre ||\n ''\n).trim();\n\nconst saludo = nombre ? `, ${nombre}` : '';\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `✅ Video recibido${saludo}.\n\nPuedes enviar más videos si hace falta.\n\nCuando termines, escribe *LISTO* para cerrar el reporte.`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3968, 688 ], "id": "ce363661-867f-4c31-b730-a7aaf88453cc", "name": "Code - Preparar confirmación video WhatsApp TEST" }, { "parameters": { "jsCode": "const base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst ahora = new Date().toISOString();\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n sesion.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n\n session_id: base.session_id || sesion.session_id || '',\n manager_telefono: sesion.manager_telefono || base.manager_telefono || '',\n manager_nombre: sesion.manager_nombre || base.manager_nombre || '',\n canal_origen: sesion.canal_origen || base.canal_origen || 'WHATSAPP',\n\n fecha_inicio: sesion.fecha_inicio || '',\n ultima_actividad: ahora,\n\n etapa: 'PROCESANDO',\n estado: 'LISTO_PARA_RECUPERAR_MEDIA',\n\n audio_count: Number(sesion.audio_count || 0),\n imagenes_count: Number(sesion.imagenes_count || 0),\n videos_count: Number(sesion.videos_count || 0),\n\n ejecucion_id: sesion.ejecucion_id || base.ejecucion_id || base.session_id || '',\n motivo_revision: 'CON_VIDEO_REPORTADO',\n\n whatsapp_to: whatsappTo\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3408, 1472 ], "id": "b2d8579c-f7b8-486a-a502-3b0e91912628", "name": "Code - Preparar cierre con videos WhatsApp TEST" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ultima_actividad": "={{ $json.ultima_actividad }}", "etapa": "={{ $json.etapa }}", "audio_count": "={{ $json.audio_count }}", "imagenes_count": "={{ $json.imagenes_count }}", "videos_count": "={{ $json.videos_count }}", "estado": "={{ $json.estado }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "motivo_revision": "={{ $json.motivo_revision }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3616, 1472 ], "id": "ccb46bd5-6e01-42d5-89ab-54e4622265be", "name": "Sheets - Actualizar sesión cierre con videos WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('Code - Preparar cierre con videos WhatsApp TEST').first().json || {};\n\nconst nombre = String(\n data.manager_nombre ||\n base.manager_nombre ||\n ''\n).trim();\n\nconst saludo = nombre ? `, ${nombre}` : '';\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `✅ Reporte recibido completo${saludo}.\n\nRegistré la nota de voz, las imágenes y los videos enviados.\n\nAhora voy a preparar el procesamiento de toda la evidencia recibida.`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3824, 1472 ], "id": "19fa8906-79eb-4845-a969-66d3b661d27d", "name": "Code - Preparar confirmación cierre con videos WhatsApp TEST" }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n sesion.manager_telefono ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `⏳ Tu reporte ya fue recibido y está pendiente de procesamiento.\n\nPor favor espera mientras se prepara el análisis de la evidencia.`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3712, 2064 ], "id": "b5960269-5fca-4d10-b2ef-eda72eb68b10", "name": "Code - Preparar aviso procesando WhatsApp TEST" }, { "parameters": { "jsCode": "const data = $json || {};\n\nreturn [\n {\n json: {\n ...data,\n\n session_id_busqueda: data.session_id || '',\n estado_procesamiento: 'BUSCAR_EVENTOS_MEDIA'\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3936, 1232 ], "id": "6cee8abe-abb5-4818-ac8c-1f49f0905bcc", "name": "Code - Preparar búsqueda eventos media WhatsApp TEST" }, { "parameters": { "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 306129743, "mode": "list", "cachedResultName": "wa_ejecuciones_eventos", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=306129743" }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 4192, 1232 ], "id": "e49fc551-3ddb-4041-88fd-c4329ef64d54", "name": "Sheets - Leer eventos WhatsApp TEST", "alwaysOutputData": true, "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const cierre = $('Code - Preparar búsqueda eventos media WhatsApp TEST').first().json || {};\nconst sessionId = String(cierre.session_id_busqueda || cierre.session_id || '').trim();\n\nconst eventos = $input.all().map(item => item.json || {});\n\nconst eventosSesion = eventos.filter(evento => {\n return String(evento.session_id || '').trim() === sessionId;\n});\n\nconst eventosMedia = eventosSesion.filter(evento => {\n const tipo = String(evento.message_type || '').toLowerCase();\n return ['audio', 'image', 'video'].includes(tipo);\n});\n\nconst audios = eventosMedia.filter(e => String(e.message_type || '').toLowerCase() === 'audio');\nconst imagenes = eventosMedia.filter(e => String(e.message_type || '').toLowerCase() === 'image');\nconst videos = eventosMedia.filter(e => String(e.message_type || '').toLowerCase() === 'video');\n\nreturn [\n {\n json: {\n ...cierre,\n\n total_eventos_sesion: eventosSesion.length,\n total_media: eventosMedia.length,\n\n audio_count_real: audios.length,\n imagenes_count_real: imagenes.length,\n videos_count_real: videos.length,\n\n eventos_audio: audios,\n eventos_imagenes: imagenes,\n eventos_videos: videos,\n\n media_lista: eventosMedia,\n\n estado_procesamiento: 'EVENTOS_MEDIA_FILTRADOS'\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 4432, 1232 ], "id": "6c7e217e-6200-46d8-892a-adc9b273e4a7", "name": "Code - Filtrar eventos media de sesión WhatsApp TEST" } ], "connections": { "Code - Normalizar evento WhatsApp TEST": { "main": [ [ { "node": "Mi numero TESTING", "type": "main", "index": 0 } ] ] }, "Mi numero TESTING": { "main": [ [ { "node": "Sheets - Leer sesiones existentes", "type": "main", "index": 0 } ] ] }, "Webhook - Evolution WhatsApp TEST": { "main": [ [ { "node": "Code - Normalizar evento WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "WhatsApp - Enviar mensaje TEST": { "main": [ [] ] }, "Sheets - Leer sesiones existentes": { "main": [ [ { "node": "Code - Resolver sesión WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Resolver sesión WhatsApp TEST": { "main": [ [ { "node": "Switch - Decisión sesión WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Switch - Decisión sesión WhatsApp TEST": { "main": [ [ { "node": "Sheets - Crear sesión WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar aviso sesión activa WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "ode - Preparar sin sesión para cancelar WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar cancelación sesión WhatsApp TEST", "type": "main", "index": 0 } ], [], [ { "node": "Code - Resolver paso activo WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar bienvenida WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Crear sesión WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar bienvenida WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Resolver paso activo WhatsApp TEST": { "main": [ [ { "node": "Switch - Paso activo WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Switch - Paso activo WhatsApp TEST": { "main": [ [ { "node": "Sheets - Guardar evento audio WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar solicitud audio WhatsApp TEST", "type": "main", "index": 0 } ], [], [], [ { "node": "Sheets - Guardar evento imagen WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Preparar actualización fotos listas", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar aviso falta imagen WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Sheets - Guardar evento video WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "CERRAR_SIN_VIDEO", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar cierre con videos WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar recordatorio videos WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar aviso procesando WhatsApp TEST", "type": "main", "index": 0 } ], [] ] }, "Code - Preparar solicitud audio WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Guardar evento audio WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar actualización audio recibido WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar actualización audio recibido WhatsApp TEST": { "main": [ [ { "node": "Sheets - Actualizar sesión audio recibido WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Actualizar sesión audio recibido WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar solicitud imágenes WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar aviso sesión activa WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar solicitud imágenes WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar cancelación sesión WhatsApp TEST": { "main": [ [ { "node": "Sheets - Cancelar sesión WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Cancelar sesión WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar mensaje cancelación WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar mensaje cancelación WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "ode - Preparar sin sesión para cancelar WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code — Preparar actualización imagen recibida": { "main": [ [ { "node": "Sheets — Actualizar sesión imagen recibida", "type": "main", "index": 0 } ] ] }, "Sheets — Actualizar sesión imagen recibida": { "main": [ [ { "node": "Code — Preparar confirmación imagen", "type": "main", "index": 0 } ] ] }, "Sheets - Guardar evento imagen WhatsApp TEST": { "main": [ [ { "node": "Code — Preparar actualización imagen recibida", "type": "main", "index": 0 } ] ] }, "Code - Preparar aviso falta imagen WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code — Preparar confirmación imagen": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Preparar actualización fotos listas": { "main": [ [ { "node": "Sheets - Actualizar sesión fotos listas WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Actualizar sesión fotos listas WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar solicitud videos WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar solicitud videos WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar recordatorio videos WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "CERRAR_SIN_VIDEO": { "main": [ [ { "node": "Sheets - Actualizar sesión cierre sin video WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Actualizar sesión cierre sin video WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar confirmación cierre sin video WhatsApp TEST", "type": "main", "index": 0 }, { "node": "Code - Preparar búsqueda eventos media WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar confirmación cierre sin video WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Guardar evento video WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar actualización video recibido WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar actualización video recibido WhatsApp TEST": { "main": [ [ { "node": "Sheets - Actualizar sesión video recibido WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Actualizar sesión video recibido WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar confirmación video WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar confirmación video WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar cierre con videos WhatsApp TEST": { "main": [ [ { "node": "Sheets - Actualizar sesión cierre con videos WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Actualizar sesión cierre con videos WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar confirmación cierre con videos WhatsApp TEST", "type": "main", "index": 0 }, { "node": "Code - Preparar búsqueda eventos media WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar confirmación cierre con videos WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar aviso procesando WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar búsqueda eventos media WhatsApp TEST": { "main": [ [ { "node": "Sheets - Leer eventos WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Leer eventos WhatsApp TEST": { "main": [ [ { "node": "Code - Filtrar eventos media de sesión WhatsApp TEST", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1", "binaryMode": "separate" }, "staticData": null, "meta": { "templateCredsSetupCompleted": true }, "versionId": "480a88db-5bc0-4feb-aa97-442645b0b4e5", "activeVersionId": "18440aa7-a3c0-4970-a2f6-b5ad4017bb9d", "versionCounter": 644, "triggerCount": 1, "shared": [ { "updatedAt": "2026-06-08T20:09:28.138Z", "createdAt": "2026-06-08T20:09:28.138Z", "role": "workflow:owner", "workflowId": "sXH75CXIQ0sEzm1Y", "projectId": "PJpTANzTXIFibWsW", "project": { "updatedAt": "2026-04-22T14:25:09.686Z", "createdAt": "2026-04-22T14:22:54.790Z", "id": "PJpTANzTXIFibWsW", "name": "Isaac Aracena ", "type": "personal", "icon": null, "description": null, "creatorId": "0a88c0b1-928e-4412-896e-c5d1c99b2029" } } ], "tags": [], "activeVersion": { "updatedAt": "2026-06-10T02:20:30.000Z", "createdAt": "2026-06-10T02:19:46.263Z", "versionId": "18440aa7-a3c0-4970-a2f6-b5ad4017bb9d", "workflowId": "sXH75CXIQ0sEzm1Y", "nodes": [ { "parameters": { "method": "POST", "url": "={{'https://wsp.gomezleemarketing.com'}}/message/sendText/{{'botsoporte'}}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "apikey", "value": "={{'C267126ABB45-4C12-B626-6BAB1833F5D7'}}" } ] }, "sendBody": true, "bodyParameters": { "parameters": [ { "name": "number", "value": "={{ $json.whatsapp_to || $json.whatsapp_remote_jid || $json.manager_telefono }}" }, { "name": "delay", "value": "={{ 1000 }}" }, { "name": "text", "value": "={{ $json.whatsapp_text || $json.telegram_text || $json.texto_respuesta || $json.mensaje || $json.text || 'Mensaje sin contenido' }}" } ] }, "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 7744, -112 ], "id": "b1d4c2c3-c77f-4b9d-b4ca-c40535c26299", "name": "WhatsApp - Enviar mensaje TEST" }, { "parameters": { "jsCode": "const input = $json || {};\nconst body = input.body || input;\nconst data = body.data || {};\n\nconst texto = (valor) => String(valor ?? '').trim();\n\nconst limpiarNumero = (valor) =>\n texto(valor)\n .replace('@s.whatsapp.net', '')\n .replace('@c.us', '')\n .replace('@g.us', '')\n .replace(/\\D/g, '');\n\nconst key = data.key || {};\n\nconst remoteJid = texto(key.remoteJid || data.remoteJid || body.remoteJid || '');\nconst managerTelefono = limpiarNumero(remoteJid);\n\nconst pushName =\n texto(data.pushName) ||\n texto(body.pushName) ||\n 'Usuario WhatsApp';\n\nconst message = data.message || {};\n\nconst textoMensaje =\n texto(message.conversation) ||\n texto(message.extendedTextMessage?.text) ||\n texto(data.messageText) ||\n texto(data.text) ||\n texto(body.text) ||\n '';\n\nlet messageType = 'unknown';\n\nif (message.audioMessage) {\n messageType = 'audio';\n} else if (message.imageMessage) {\n messageType = 'image';\n} else if (message.videoMessage) {\n messageType = 'video';\n} else if (textoMensaje) {\n messageType = 'text';\n}\n\nconst tieneMedia = ['audio', 'image', 'video'].includes(messageType);\n\nconst mediaMimeType =\n texto(message.audioMessage?.mimetype) ||\n texto(message.imageMessage?.mimetype) ||\n texto(message.videoMessage?.mimetype) ||\n '';\n\nconst mediaSourceId =\n texto(key.id) ||\n texto(data.id) ||\n texto(data.messageId) ||\n '';\n\nconst normalizarComando = (valor) => {\n const t = texto(valor)\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toUpperCase();\n\n if (t === '/START' || t === 'START' || t === 'INICIAR') return 'START';\n if (t === 'CANCELAR') return 'CANCELAR';\n if (t === 'FOTOS LISTAS' || t === 'FOTOS_LISTAS') return 'FOTOS_LISTAS';\n if (t === 'SIN VIDEO' || t === 'SIN_VIDEO') return 'SIN_VIDEO';\n if (t === 'LISTO') return 'LISTO';\n\n return 'NORMAL';\n};\n\nreturn [\n {\n json: {\n event_id: texto(key.id || data.id || Date.now()),\n fecha_recepcion: new Date().toISOString(),\n\n canal_origen: 'WHATSAPP',\n\n manager_telefono: managerTelefono,\n manager_nombre: pushName,\n usuario_id_origen: managerTelefono,\n\n whatsapp_remote_jid: remoteJid,\n whatsapp_to: remoteJid,\n\n from_me: Boolean(key.fromMe || data.fromMe || false),\n\n message_type: messageType,\n texto: textoMensaje,\n accion_flujo: normalizarComando(textoMensaje),\n\n tiene_media: tieneMedia,\n media_count: tieneMedia ? 1 : 0,\n media_source_id: mediaSourceId,\n media_mime_type: mediaMimeType,\n media_file_name: '',\n\n raw_preview: JSON.stringify(body).slice(0, 4000),\n raw_event: body,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 208, -256 ], "id": "35e401ba-acce-429c-b811-58a45c032869", "name": "Code - Normalizar evento WhatsApp TEST" }, { "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "f2be1fb5-b047-4614-a1f2-9a4d65ef5cc7", "leftValue": "={{ $json.manager_telefono === '18298946645' }}", "rightValue": "={{ $json.manager_telefono === '18298946645' }}", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "options": {} }, "type": "n8n-nodes-base.if", "typeVersion": 2.3, "position": [ 480, -256 ], "id": "3b65e795-a7f8-415c-8c04-7cde544c4350", "name": "Mi numero TESTING" }, { "parameters": { "httpMethod": "POST", "path": "factura", "options": {} }, "type": "n8n-nodes-base.webhook", "typeVersion": 2.1, "position": [ 0, -256 ], "id": "bbdd46ca-d2f0-4c42-8e14-d9591168cf4d", "name": "Webhook - Evolution WhatsApp TEST", "webhookId": "e2e6c9c2-6c1e-453d-85f1-271056935828" }, { "parameters": { "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 848, -272 ], "id": "653ca576-1661-49aa-80cb-62b7ec46a1c0", "name": "Sheets - Leer sesiones existentes", "alwaysOutputData": true, "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const evento = $('Code - Normalizar evento WhatsApp TEST').first().json || {};\nconst sesiones = $input.all().map((item) => item.json || {});\n\nconst texto = (valor) => String(valor ?? '').trim();\n\nconst estadosAbiertos = new Set([\n 'ACTIVA',\n 'PENDIENTE',\n 'EN_PROCESO',\n 'PROCESANDO',\n 'LISTO_PARA_RECUPERAR_MEDIA',\n 'LISTO_PARA_ANALIZAR',\n]);\n\nconst etapasAbiertas = new Set([\n 'ESPERANDO_AUDIO',\n 'ESPERANDO_IMAGENES',\n 'ESPERANDO_VIDEOS',\n 'PROCESANDO',\n]);\n\nconst managerTelefono = texto(evento.manager_telefono);\nconst accion = texto(evento.accion_flujo || 'NORMAL');\n\nconst sesionActiva = sesiones\n .filter((row) => texto(row.manager_telefono) === managerTelefono)\n .filter((row) => {\n const estado = texto(row.estado).toUpperCase();\n const etapa = texto(row.etapa).toUpperCase();\n\n return estadosAbiertos.has(estado) || etapasAbiertas.has(etapa);\n })\n .sort((a, b) => {\n return new Date(b.ultima_actividad || b.fecha_inicio || 0) - new Date(a.ultima_actividad || a.fecha_inicio || 0);\n })[0] || null;\n\nconst suffix = Math.random().toString(36).slice(2, 6).toUpperCase();\nconst sessionId = `WA_${Date.now()}_${managerTelefono.slice(-4)}_${suffix}`;\n\nlet decision = '';\n\nif (accion === 'START') {\n decision = sesionActiva ? 'AVISO_SESION_ACTIVA' : 'CREAR_SESION';\n} else if (accion === 'CANCELAR') {\n decision = sesionActiva ? 'CANCELAR_SESION' : 'SIN_SESION_PARA_CANCELAR';\n} else {\n decision = sesionActiva ? 'CONTINUAR_SESION' : 'SIN_SESION_ACTIVA';\n}\n\nreturn [\n {\n json: {\n ...evento,\n\n sesion_activa_encontrada: Boolean(sesionActiva),\n sesion_activa: sesionActiva,\n\n session_id: sesionActiva ? texto(sesionActiva.session_id) : sessionId,\n ejecucion_id: sesionActiva ? texto(sesionActiva.ejecucion_id || sesionActiva.session_id) : sessionId,\n\n decision_flujo: decision,\n\n nueva_sesion: {\n session_id: sessionId,\n manager_telefono: managerTelefono,\n manager_nombre: texto(evento.manager_nombre),\n canal_origen: 'WHATSAPP',\n fecha_inicio: new Date().toISOString(),\n ultima_actividad: new Date().toISOString(),\n etapa: 'ESPERANDO_AUDIO',\n audio_count: 0,\n imagenes_count: 0,\n videos_count: 0,\n estado: 'ACTIVA',\n ejecucion_id: sessionId,\n motivo_revision: '',\n },\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1040, -272 ], "id": "91675542-137d-4976-9c1c-3ba26bb1ddab", "name": "Code - Resolver sesión WhatsApp TEST" }, { "parameters": { "rules": { "values": [ { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "leftValue": "={{ $json.decision_flujo === 'CREAR_SESION' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true }, "id": "acec6506-977a-412d-b08a-fbcc8de4b0b8" } ], "combinator": "and" }, "renameOutput": true, "outputKey": "CREAR_SESION" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "5c9dcfa5-9b15-428c-ad80-c277b0671658", "leftValue": "={{ $json.decision_flujo === 'AVISO_SESION_ACTIVA' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "AVISO_SESION_ACTIVA" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "966402b5-4517-45c2-8a87-0a7aa4e5e682", "leftValue": "={{ $json.decision_flujo === 'SIN_SESION_ACTIVA' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "SIN_SESION_ACTIVA" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "698f3da3-29d2-472f-b625-af387891035e", "leftValue": "={{ $json.decision_flujo === 'CANCELAR_SESION' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "CANCELAR_SESION" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "d5feac06-4493-494e-ac1e-36c007f0de79", "leftValue": "={{ $json.decision_flujo === 'SIN_SESION_PARA_CANCELAR' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "SIN_SESION_PARA_CANCELAR" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "950979b7-b930-4260-a392-52277a742e43", "leftValue": "={{ $json.decision_flujo === 'CONTINUAR_SESION' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "CONTINUAR_SESION" } ] }, "options": {} }, "type": "n8n-nodes-base.switch", "typeVersion": 3.4, "position": [ 1264, -336 ], "id": "50d7bb39-3a6d-4906-b695-e6b09ba5c545", "name": "Switch - Decisión sesión WhatsApp TEST" }, { "parameters": { "jsCode": "const datos = $('Code - Resolver sesión WhatsApp TEST').first().json || {};\n\nconst mensaje = [\n '📸 *Propuestas Ejecutadas - GLM*',\n '',\n `¡Hola, ${datos.manager_nombre || 'equipo'}! Bienvenido al registro de propuestas ejecutadas.`,\n '',\n 'Este proceso permite documentar ejecuciones reales para alimentar el banco de evidencias de Fulgencio Fumado.',\n '',\n '*Paso 1 de 3 — Nota de voz obligatoria*',\n '',\n 'Envía una nota de voz indicando:',\n '',\n '• Nombre o referencia de la propuesta ejecutada',\n '• Marca o cliente',\n '• País',\n '• Ubicación de la ejecución',\n '• Fecha de ejecución',\n '• Qué se implementó',\n '• Comentarios o resultados observados',\n '',\n 'Importante: registra una sola propuesta ejecutada a la vez.',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3104, -2304 ], "id": "304baef0-fda7-43ce-8bfe-24ed684ced3b", "name": "Code - Preparar bienvenida WhatsApp TEST" }, { "parameters": { "jsCode": "const datos = $json || {};\n\nconst etapa = String(datos.sesion_activa?.etapa || '').trim() || 'pendiente';\n\nconst mensaje = [\n '⚠️ Ya tienes un reporte de propuesta ejecutada en proceso.',\n '',\n `Etapa actual: ${etapa}`,\n '',\n 'Completa ese reporte antes de iniciar uno nuevo.',\n '',\n 'Si deseas cancelarlo, escribe: CANCELAR',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3136, -1856 ], "id": "bf9701ac-00d2-47c3-a495-ddaad66ed0be", "name": "Code - Preparar aviso sesión activa WhatsApp TEST" }, { "parameters": { "operation": "append", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.nueva_sesion.session_id }}", "manager_telefono": "={{ $json.nueva_sesion.manager_telefono }}", "manager_nombre": "={{ $json.nueva_sesion.manager_nombre }}", "canal_origen": "={{ $json.nueva_sesion.canal_origen }}", "fecha_inicio": "={{ $json.nueva_sesion.fecha_inicio }}", "ultima_actividad": "={{ $json.nueva_sesion.ultima_actividad }}", "etapa": "={{ $json.nueva_sesion.etapa }}", "audio_count": "={{ $json.nueva_sesion.audio_count }}", "imagenes_count": "={{ $json.nueva_sesion.imagenes_count }}", "videos_count": "={{ $json.nueva_sesion.videos_count }}", "estado": "={{ $json.nueva_sesion.estado }}", "ejecucion_id": "={{ $json.nueva_sesion.ejecucion_id }}", "motivo_revision": "={{ $json.nueva_sesion.motivo_revision }}" }, "matchingColumns": [], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 2896, -2304 ], "id": "cff69027-2e70-4be6-ad78-80ae6680ca75", "name": "Sheets - Crear sesión WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const datos = $json || {};\n\nconst texto = (valor) => String(valor ?? '').trim();\n\nconst etapa = texto(datos.sesion_activa?.etapa).toUpperCase();\nconst tipoMensaje = texto(datos.message_type).toLowerCase();\nconst accion = texto(datos.accion_flujo).toUpperCase();\n\nconst imagenesCount = Number(datos.sesion_activa?.imagenes_count || 0);\nconst videosCount = Number(datos.sesion_activa?.videos_count || 0);\n\nlet paso_decision = 'NO_DEFINIDO';\n\n// --------------------------------------------------\n// 1. Cancelación global\n// --------------------------------------------------\nif (accion === 'CANCELAR') {\n paso_decision = 'CANCELAR_SESION';\n\n// --------------------------------------------------\n// 2. Paso 1: esperando nota de voz\n// --------------------------------------------------\n} else if (etapa === 'ESPERANDO_AUDIO') {\n if (tipoMensaje === 'audio') {\n paso_decision = 'GUARDAR_AUDIO';\n } else {\n paso_decision = 'PEDIR_AUDIO';\n }\n\n// --------------------------------------------------\n// 3. Paso 2: esperando imágenes obligatorias\n// --------------------------------------------------\n} else if (etapa === 'ESPERANDO_IMAGENES') {\n if (tipoMensaje === 'image') {\n paso_decision = 'GUARDAR_IMAGEN';\n } else if (accion === 'FOTOS_LISTAS') {\n // Solo permite avanzar si ya hay al menos una imagen registrada.\n if (imagenesCount > 0) {\n paso_decision = 'FOTOS_LISTAS';\n } else {\n paso_decision = 'PEDIR_IMAGENES';\n }\n } else {\n paso_decision = 'PEDIR_IMAGENES';\n }\n\n// --------------------------------------------------\n// 4. Paso 3: esperando videos opcionales\n// --------------------------------------------------\n} else if (etapa === 'ESPERANDO_VIDEOS') {\n if (tipoMensaje === 'video') {\n paso_decision = 'GUARDAR_VIDEO';\n } else if (accion === 'SIN_VIDEO') {\n paso_decision = 'CERRAR_SIN_VIDEO';\n } else if (accion === 'LISTO') {\n paso_decision = 'CERRAR_CON_VIDEOS';\n } else {\n paso_decision = 'PEDIR_VIDEOS';\n }\n\n// --------------------------------------------------\n// 5. Sesión en procesamiento\n// --------------------------------------------------\n} else if (etapa === 'PROCESANDO') {\n paso_decision = 'AVISO_PROCESANDO';\n\n// --------------------------------------------------\n// 6. Etapa no reconocida\n// --------------------------------------------------\n} else {\n paso_decision = 'ETAPA_NO_RECONOCIDA';\n}\n\nreturn [\n {\n json: {\n ...datos,\n\n etapa_actual: etapa,\n tipo_mensaje_actual: tipoMensaje,\n accion_actual: accion,\n\n imagenes_count_actual: imagenesCount,\n videos_count_actual: videosCount,\n\n paso_decision,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1552, 144 ], "id": "28aaa567-1c39-49ac-802d-38e001d71cc2", "name": "Code - Resolver paso activo WhatsApp TEST" }, { "parameters": { "rules": { "values": [ { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "leftValue": "={{ $json.paso_decision === 'GUARDAR_AUDIO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true }, "id": "c7fef2d7-50ce-467a-b125-30ae7fba3a58" } ], "combinator": "and" }, "renameOutput": true, "outputKey": "GUARDAR_AUDIO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "8da042cf-54e6-460f-b505-2b17c4f4ff3c", "leftValue": "={{ $json.paso_decision === 'PEDIR_AUDIO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "PEDIR_AUDIO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "ecf52241-ef7e-4a9a-8823-b9e3b438da61", "leftValue": "={{ $json.paso_decision === 'GUARDAR_AUDIO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "GUARDAR_AUDIO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "04433553-d0ee-4391-a4f4-926197ac4c0c", "leftValue": "={{ $json.paso_decision === 'PEDIR_AUDIO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "PEDIR_AUDIO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "8637dc0f-59b6-40ac-8bc4-baf869829598", "leftValue": "={{ $json.paso_decision === 'GUARDAR_IMAGEN' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "GUARDAR_IMAGEN" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "4096e616-2517-48ab-b6c4-2712f763ec1d", "leftValue": "={{ $json.paso_decision === 'FOTOS_LISTAS' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "FOTOS_LISTAS" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "d1dd1d5c-8e25-4147-876e-5e7227784f6f", "leftValue": "={{ $json.paso_decision === 'PEDIR_IMAGENES' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "PEDIR_IMAGENES" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "bddbb16a-0463-47dd-9a6c-03c3635043f1", "leftValue": "={{ $json.paso_decision === 'GUARDAR_VIDEO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "GUARDAR_VIDEO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "fe05ba35-0ccc-417a-a4e8-b907611932e4", "leftValue": "={{ $json.paso_decision === 'CERRAR_SIN_VIDEO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "CERRAR_SIN_VIDEO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "94647ac0-ee80-4c96-9f25-8a847704b6a0", "leftValue": "={{ $json.paso_decision === 'CERRAR_CON_VIDEOS' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "CERRAR_CON_VIDEOS" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "3038a656-50ae-4738-b2ff-a6276bd06522", "leftValue": "={{ $json.paso_decision === 'PEDIR_VIDEOS' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "PEDIR_VIDEOS" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "1b20a524-2289-4d37-8372-9a839dadc971", "leftValue": "={{ $json.paso_decision === 'AVISO_PROCESANDO' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "AVISO_PROCESANDO" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "0943bbd0-f5b7-43c4-9b01-7f6bea244894", "leftValue": "={{ $json.paso_decision === 'ETAPA_NO_RECONOCIDA' }}", "rightValue": "", "operator": { "type": "boolean", "operation": "true", "singleValue": true } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "ETAPA_NO_RECONOCIDA" } ] }, "options": {} }, "type": "n8n-nodes-base.switch", "typeVersion": 3.4, "position": [ 1904, 416 ], "id": "b8b395eb-8f3f-4006-8ad8-d426f7e0792a", "name": "Switch - Paso activo WhatsApp TEST" }, { "parameters": { "jsCode": "const datos = $json || {};\n\nconst mensaje = [\n '🎙️ Aún necesito la nota de voz obligatoria para iniciar el reporte.',\n '',\n 'Por favor envía una nota de voz indicando:',\n '',\n '• Nombre o referencia de la propuesta ejecutada',\n '• Marca o cliente',\n '• País',\n '• Ubicación de la ejecución',\n '• Fecha de ejecución',\n '• Qué se implementó',\n '• Comentarios o resultados observados',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2912, -224 ], "id": "30196ae5-1d82-46e3-9296-32ffa6122ae1", "name": "Code - Preparar solicitud audio WhatsApp TEST" }, { "parameters": { "operation": "append", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 306129743, "mode": "list", "cachedResultName": "wa_ejecuciones_eventos", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=306129743" }, "columns": { "mappingMode": "defineBelow", "value": { "event_id": "={{ $json.event_id }}", "fecha_recepcion": "={{ $json.fecha_recepcion }}", "manager_telefono": "={{ $json.manager_telefono }}", "manager_nombre": "={{ $json.manager_nombre }}", "message_type": "={{ $json.message_type }}", "texto": "={{ $json.texto }}", "comando": "={{ $json.accion_flujo }}", "tiene_media": "={{ $json.tiene_media }}", "media_count": "={{ $json.media_count }}", "raw_preview": "={{ $json.raw_preview }}", "estado": "={{ $json.estado }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "fecha_procesado": "={{ $json.fecha_procesado }}", "session_id": "={{ $json.session_id }}", "canal_origen": "={{ $json.canal_origen }}", "etapa_recibida": "={{ $json.etapa_recibida }}" }, "matchingColumns": [], "schema": [ { "id": "event_id", "displayName": "event_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_recepcion", "displayName": "fecha_recepcion", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "message_type", "displayName": "message_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "texto", "displayName": "texto", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "comando", "displayName": "comando", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "tiene_media", "displayName": "tiene_media", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_count", "displayName": "media_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "raw_preview", "displayName": "raw_preview", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_procesado", "displayName": "fecha_procesado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa_recibida", "displayName": "etapa_recibida", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 2624, -608 ], "id": "4b7309e9-5602-4c88-b29f-42e44179f445", "name": "Sheets - Guardar evento audio WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const datos = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\n\nreturn [\n {\n json: {\n ...datos,\n session_id: datos.session_id,\n ultima_actividad: new Date().toISOString(),\n etapa: 'ESPERANDO_IMAGENES',\n estado: 'ACTIVA',\n audio_count: Number(datos.sesion_activa?.audio_count || 0) + 1,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2832, -608 ], "id": "25599b76-fe73-44b6-80f5-1d8ba9616fd1", "name": "Code - Preparar actualización audio recibido WhatsApp TEST" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ultima_actividad": "={{ $json.ultima_actividad }}", "etapa": "={{ $json.etapa }}", "estado": "={{ $json.estado }}", "audio_count": "={{ $json.audio_count }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3040, -608 ], "id": "35b5002d-7c69-4f31-89de-dc5457961a42", "name": "Sheets - Actualizar sesión audio recibido WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const datos = $('Code - Preparar actualización audio recibido WhatsApp TEST').first().json || {};\n\nconst mensaje = [\n '✅ Nota de voz recibida.',\n '',\n '*Paso 2 de 3 — Imágenes obligatorias*',\n '',\n 'Ahora envía al menos una foto de la propuesta ejecutada.',\n '',\n 'Puedes enviar varias imágenes seguidas.',\n '',\n 'Cuando termines de enviar las imágenes, escribe: FOTOS LISTAS',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3264, -608 ], "id": "7c1c09aa-4670-47d0-a5a5-3713adf6b6fb", "name": "Code - Preparar solicitud imágenes WhatsApp TEST" }, { "parameters": { "jsCode": "const datos = $json || {};\n\nreturn [\n {\n json: {\n ...datos,\n session_id: datos.session_id,\n ultima_actividad: new Date().toISOString(),\n etapa: 'CANCELADA',\n estado: 'CANCELADA',\n motivo_revision: 'CANCELADO_POR_USUARIO',\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3008, -1040 ], "id": "dd118cad-907f-4bab-89ef-8d75dc2d70cb", "name": "Code - Preparar cancelación sesión WhatsApp TEST" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ultima_actividad": "={{ $json.ultima_actividad }}", "etapa": "={{ $json.etapa }}", "estado": "={{ $json.estado }}", "motivo_revision": "={{ $json.motivo_revision }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3216, -1040 ], "id": "ac83d38f-7d91-408a-bb43-f8950ccc40a6", "name": "Sheets - Cancelar sesión WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const datos = $('Code - Preparar cancelación sesión WhatsApp TEST').first().json || {};\n\nconst mensaje = [\n '✅ Reporte cancelado correctamente.',\n '',\n 'Ya puedes iniciar un nuevo reporte escribiendo:',\n '',\n '/start',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3472, -1104 ], "id": "119da00c-cea5-4184-90e5-ad4a408271bb", "name": "Code - Preparar mensaje cancelación WhatsApp TEST" }, { "parameters": { "jsCode": "const datos = $json || {};\n\nconst mensaje = [\n '⚠️ No tienes un reporte activo para cancelar.',\n '',\n 'Para iniciar uno nuevo, escribe:',\n '',\n '/start',\n].join('\\n');\n\nreturn [\n {\n json: {\n ...datos,\n whatsapp_to: datos.whatsapp_to || datos.whatsapp_remote_jid,\n whatsapp_text: mensaje,\n },\n },\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3216, -1488 ], "id": "be56aeb8-916d-46b2-b2a2-b544a4bdbd01", "name": "ode - Preparar sin sesión para cancelar WhatsApp TEST" }, { "parameters": { "jsCode": "const evento = $json || {};\nconst base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst ahora = new Date().toISOString();\n\nconst imagenesActuales = Number(sesion.imagenes_count || 0);\n\nreturn [\n {\n json: {\n ...base,\n ...evento,\n\n session_id: base.session_id || sesion.session_id || evento.session_id || '',\n manager_telefono: sesion.manager_telefono || base.manager_telefono || evento.manager_telefono || '',\n manager_nombre: sesion.manager_nombre || base.manager_nombre || evento.manager_nombre || '',\n canal_origen: sesion.canal_origen || base.canal_origen || 'WHATSAPP',\n\n fecha_inicio: sesion.fecha_inicio || '',\n ultima_actividad: ahora,\n\n // IMPORTANTE:\n // Después de recibir una imagen, todavía seguimos esperando más imágenes\n // hasta que el usuario escriba FOTOS LISTAS.\n etapa: 'ESPERANDO_IMAGENES',\n\n audio_count: Number(sesion.audio_count || 0),\n imagenes_count: imagenesActuales + 1,\n videos_count: Number(sesion.videos_count || 0),\n\n estado: sesion.estado || 'ACTIVA',\n ejecucion_id: sesion.ejecucion_id || base.ejecucion_id || base.session_id || '',\n motivo_revision: sesion.motivo_revision || '',\n\n whatsapp_to: base.whatsapp_to || base.whatsapp_remote_jid || evento.whatsapp_to || evento.whatsapp_remote_jid || ''\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 4768, 144 ], "id": "dee83381-1061-405c-978f-33403362f74b", "name": "Code — Preparar actualización imagen recibida" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "motivo_revision": "={{ $json.motivo_revision }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "estado": "={{ $json.estado }}", "videos_count": "={{ $json.videos_count }}", "imagenes_count": "={{ $json.imagenes_count }}", "audio_count": "={{ $json.audio_count }}", "etapa": "={{ $json.etapa }}", "ultima_actividad": "={{ $json.ultima_actividad }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 4976, 144 ], "id": "392c7a6c-3ab8-4f56-8742-8ab4ffdd5a4c", "name": "Sheets — Actualizar sesión imagen recibida", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\n\nconst nombre = String(data.manager_nombre || base.manager_nombre || '').trim();\nconst saludo = nombre ? `, ${nombre}` : '';\n\nconst telefono = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefono.includes('@s.whatsapp.net')\n ? telefono\n : `${telefono.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `✅ Imagen recibida${saludo}.\n\nPuedes enviar más fotos si hace falta.\n\nCuando termines de enviar las imágenes, escribe *FOTOS LISTAS*.`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5184, 144 ], "id": "ebc7dadc-6ddc-4806-8c19-7d4e2ce567cf", "name": "Code — Preparar confirmación imagen" }, { "parameters": { "operation": "append", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 306129743, "mode": "list", "cachedResultName": "wa_ejecuciones_eventos", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=306129743" }, "columns": { "mappingMode": "defineBelow", "value": { "event_id": "=", "manager_telefono": "=", "manager_nombre": "=", "tiene_media": "=", "estado": "=IMAGEN_RECIBIDA", "session_id": "={{ $json.session_id }}", "canal_origen": "=WHATSAPP", "fecha_recepcion": "={{ $json.fecha_recepcion }}", "message_type": "={{ $json.message_type }}", "texto": "={{ $json.texto }}", "media_count": "={{ $json.media_count }}", "raw_preview": "={{ $json.raw_preview }}", "etapa_recibida": "={{ $json.etapa_actual }}" }, "matchingColumns": [], "schema": [ { "id": "event_id", "displayName": "event_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_recepcion", "displayName": "fecha_recepcion", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "message_type", "displayName": "message_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "texto", "displayName": "texto", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "comando", "displayName": "comando", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "tiene_media", "displayName": "tiene_media", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_count", "displayName": "media_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "raw_preview", "displayName": "raw_preview", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_procesado", "displayName": "fecha_procesado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa_recibida", "displayName": "etapa_recibida", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 4496, 144 ], "id": "f8cf4436-cf35-45d6-acc7-7adfb9e3a2dc", "name": "Sheets - Guardar evento imagen WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $json || {};\n\nconst telefono = data.manager_telefono || data.whatsapp_to || '';\nconst nombre = String(data.manager_nombre || '').trim();\n\nconst saludo = nombre ? `, ${nombre}` : '';\n\nreturn [\n {\n json: {\n ...data,\n\n whatsapp_to: telefono,\n\n whatsapp_text: `📸 Necesito que me envíes al menos una imagen${saludo}.\n\nLa nota de voz ya fue recibida, pero para completar el reporte de propuesta ejecutada hace falta una foto de evidencia.\n\nPor favor envía una imagen y luego escribe *LISTO* cuando termines.`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 4544, 784 ], "id": "75998ea0-d2ec-4614-b18e-824019627d72", "name": "Code - Preparar aviso falta imagen WhatsApp TEST" }, { "parameters": { "jsCode": "const base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst ahora = new Date().toISOString();\n\nreturn [\n {\n json: {\n ...base,\n\n session_id: base.session_id || sesion.session_id || '',\n manager_telefono: sesion.manager_telefono || base.manager_telefono || '',\n manager_nombre: sesion.manager_nombre || base.manager_nombre || '',\n canal_origen: sesion.canal_origen || base.canal_origen || 'WHATSAPP',\n\n fecha_inicio: sesion.fecha_inicio || '',\n ultima_actividad: ahora,\n\n // Avanzamos al paso 3\n etapa: 'ESPERANDO_VIDEOS',\n\n audio_count: Number(sesion.audio_count || 0),\n imagenes_count: Number(sesion.imagenes_count || 0),\n videos_count: Number(sesion.videos_count || 0),\n\n estado: 'ACTIVA',\n ejecucion_id: sesion.ejecucion_id || base.ejecucion_id || base.session_id || '',\n motivo_revision: sesion.motivo_revision || '',\n\n whatsapp_to: base.whatsapp_to || base.whatsapp_remote_jid || ''\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3088, 544 ], "id": "b0e3e960-8cc9-453e-bbf2-4e410ab4a178", "name": "Preparar actualización fotos listas" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ultima_actividad": "={{ $json.ultima_actividad }}", "etapa": "={{ $json.etapa }}", "audio_count": "={{ $json.audio_count }}", "imagenes_count": "={{ $json.imagenes_count }}", "videos_count": "={{ $json.videos_count }}", "estado": "={{ $json.estado }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "motivo_revision": "={{ $json.motivo_revision }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 3296, 544 ], "id": "dea8b556-e019-40b3-97fc-04e1a47c1ed6", "name": "Sheets - Actualizar sesión fotos listas WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst nombre = String(\n data.manager_nombre ||\n sesion.manager_nombre ||\n base.manager_nombre ||\n ''\n).trim();\n\nconst saludo = nombre ? `, ${nombre}` : '';\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n sesion.manager_telefono ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `✅ Fotos registradas correctamente${saludo}.\n\n*Paso 3 de 3 — Videos opcionales*\n\nPuedes enviar uno o varios videos de la ejecución si tienes.\n\nSi no tienes videos, escribe: *SIN VIDEO*\n\nSi enviaste videos y ya terminaste, escribe: *LISTO*`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 3504, 544 ], "id": "50b9bdba-c99b-4150-9a85-e57c18e24f5a", "name": "Code - Preparar solicitud videos WhatsApp TEST" }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n sesion.manager_telefono ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `🎥 Ya estamos en el paso de videos opcionales.\n\nPuedes enviar uno o varios videos de la ejecución.\n\nSi no tienes videos, escribe: *SIN VIDEO*\n\nSi ya enviaste videos y terminaste, escribe: *LISTO*`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2480, 944 ], "id": "08b3a87f-00c6-439b-bcbe-131d86d100d5", "name": "Code - Preparar recordatorio videos WhatsApp TEST" }, { "parameters": { "jsCode": "const base = $('Code - Resolver paso activo WhatsApp TEST').first().json || {};\nconst sesion = base.sesion_activa || {};\n\nconst ahora = new Date().toISOString();\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n base.whatsapp_remote_jid ||\n sesion.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n\n session_id: base.session_id || sesion.session_id || '',\n manager_telefono: sesion.manager_telefono || base.manager_telefono || '',\n manager_nombre: sesion.manager_nombre || base.manager_nombre || '',\n canal_origen: sesion.canal_origen || base.canal_origen || 'WHATSAPP',\n\n fecha_inicio: sesion.fecha_inicio || '',\n ultima_actividad: ahora,\n\n etapa: 'PROCESANDO',\n estado: 'LISTO_PARA_RECUPERAR_MEDIA',\n\n audio_count: Number(sesion.audio_count || 0),\n imagenes_count: Number(sesion.imagenes_count || 0),\n videos_count: Number(sesion.videos_count || 0),\n\n ejecucion_id: sesion.ejecucion_id || base.ejecucion_id || base.session_id || '',\n motivo_revision: 'SIN_VIDEO_REPORTADO',\n\n whatsapp_to: whatsappTo\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2304, 704 ], "id": "c4db0aed-c18e-429c-a6ff-299bd94d2797", "name": "CERRAR_SIN_VIDEO" }, { "parameters": { "operation": "update", "documentId": { "__rl": true, "value": "1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk", "mode": "list", "cachedResultName": "Fulgencio - Propuestas Ejecutadas", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit?usp=drivesdk" }, "sheetName": { "__rl": true, "value": 616166581, "mode": "list", "cachedResultName": "wa_ejecuciones_sesiones", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=616166581" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ultima_actividad": "={{ $json.ultima_actividad }}", "etapa": "={{ $json.etapa }}", "audio_count": "={{ $json.audio_count }}", "imagenes_count": "={{ $json.imagenes_count }}", "videos_count": "={{ $json.videos_count }}", "estado": "={{ $json.estado }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "motivo_revision": "={{ $json.motivo_revision }}" }, "matchingColumns": [ "session_id" ], "schema": [ { "id": "session_id", "displayName": "session_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "manager_telefono", "displayName": "manager_telefono", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "manager_nombre", "displayName": "manager_nombre", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "canal_origen", "displayName": "canal_origen", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_inicio", "displayName": "fecha_inicio", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ultima_actividad", "displayName": "ultima_actividad", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "etapa", "displayName": "etapa", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "audio_count", "displayName": "audio_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "imagenes_count", "displayName": "imagenes_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "videos_count", "displayName": "videos_count", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "estado", "displayName": "estado", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "ejecucion_id", "displayName": "ejecucion_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "motivo_revision", "displayName": "motivo_revision", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "row_number", "displayName": "row_number", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true, "readOnly": true, "removed": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 2512, 704 ], "id": "27195f01-98fa-4772-b0c6-d82b8241cc83", "name": "Sheets - Actualizar sesión cierre sin video WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $json || {};\nconst base = $('CERRAR_SIN_VIDEO').first().json || {};\n\nconst nombre = String(\n data.manager_nombre ||\n base.manager_nombre ||\n ''\n).trim();\n\nconst saludo = nombre ? `, ${nombre}` : '';\n\nconst telefonoBase = String(\n base.whatsapp_to ||\n data.whatsapp_to ||\n data.whatsapp_remote_jid ||\n data.manager_telefono ||\n base.manager_telefono ||\n ''\n).trim();\n\nconst whatsappTo = telefonoBase.includes('@s.whatsapp.net')\n ? telefonoBase\n : `${telefonoBase.replace(/\\D/g, '')}@s.whatsapp.net`;\n\nreturn [\n {\n json: {\n ...base,\n ...data,\n\n whatsapp_to: whatsappTo,\n\n whatsapp_text: `✅ Reporte recibido completo${saludo}.\n\nRegistré que no hay videos para esta ejecución.\n\nAhora voy a preparar el procesamiento de la nota de voz y las imágenes recibidas.`\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 2720, 704 ], "id": "6384ba4f-b6d0-46c3-bfbe-63cf5f59a7e3", "name": "Code - Preparar confirmación cierre sin video WhatsApp TEST" } ], "connections": { "Code - Normalizar evento WhatsApp TEST": { "main": [ [ { "node": "Mi numero TESTING", "type": "main", "index": 0 } ] ] }, "Mi numero TESTING": { "main": [ [ { "node": "Sheets - Leer sesiones existentes", "type": "main", "index": 0 } ] ] }, "Webhook - Evolution WhatsApp TEST": { "main": [ [ { "node": "Code - Normalizar evento WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "WhatsApp - Enviar mensaje TEST": { "main": [ [] ] }, "Sheets - Leer sesiones existentes": { "main": [ [ { "node": "Code - Resolver sesión WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Resolver sesión WhatsApp TEST": { "main": [ [ { "node": "Switch - Decisión sesión WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Switch - Decisión sesión WhatsApp TEST": { "main": [ [ { "node": "Sheets - Crear sesión WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar aviso sesión activa WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "ode - Preparar sin sesión para cancelar WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar cancelación sesión WhatsApp TEST", "type": "main", "index": 0 } ], [], [ { "node": "Code - Resolver paso activo WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar bienvenida WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Crear sesión WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar bienvenida WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Resolver paso activo WhatsApp TEST": { "main": [ [ { "node": "Switch - Paso activo WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Switch - Paso activo WhatsApp TEST": { "main": [ [ { "node": "Sheets - Guardar evento audio WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar solicitud audio WhatsApp TEST", "type": "main", "index": 0 } ], [], [], [ { "node": "Sheets - Guardar evento imagen WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Preparar actualización fotos listas", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar aviso falta imagen WhatsApp TEST", "type": "main", "index": 0 } ], [], [ { "node": "CERRAR_SIN_VIDEO", "type": "main", "index": 0 } ], [], [ { "node": "Code - Preparar recordatorio videos WhatsApp TEST", "type": "main", "index": 0 } ], [], [] ] }, "Code - Preparar solicitud audio WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Guardar evento audio WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar actualización audio recibido WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar actualización audio recibido WhatsApp TEST": { "main": [ [ { "node": "Sheets - Actualizar sesión audio recibido WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Actualizar sesión audio recibido WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar solicitud imágenes WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar aviso sesión activa WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar solicitud imágenes WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar cancelación sesión WhatsApp TEST": { "main": [ [ { "node": "Sheets - Cancelar sesión WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Cancelar sesión WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar mensaje cancelación WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar mensaje cancelación WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "ode - Preparar sin sesión para cancelar WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code — Preparar actualización imagen recibida": { "main": [ [ { "node": "Sheets — Actualizar sesión imagen recibida", "type": "main", "index": 0 } ] ] }, "Sheets — Actualizar sesión imagen recibida": { "main": [ [ { "node": "Code — Preparar confirmación imagen", "type": "main", "index": 0 } ] ] }, "Sheets - Guardar evento imagen WhatsApp TEST": { "main": [ [ { "node": "Code — Preparar actualización imagen recibida", "type": "main", "index": 0 } ] ] }, "Code - Preparar aviso falta imagen WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code — Preparar confirmación imagen": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Preparar actualización fotos listas": { "main": [ [ { "node": "Sheets - Actualizar sesión fotos listas WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Actualizar sesión fotos listas WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar solicitud videos WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar solicitud videos WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar recordatorio videos WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] }, "CERRAR_SIN_VIDEO": { "main": [ [ { "node": "Sheets - Actualizar sesión cierre sin video WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Actualizar sesión cierre sin video WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar confirmación cierre sin video WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar confirmación cierre sin video WhatsApp TEST": { "main": [ [ { "node": "WhatsApp - Enviar mensaje TEST", "type": "main", "index": 0 } ] ] } }, "authors": "Isaac Aracena", "name": "Version 18440aa7", "description": "", "autosaved": true, "workflowPublishHistory": [ { "createdAt": "2026-06-10T02:20:30.933Z", "id": 1277, "workflowId": "sXH75CXIQ0sEzm1Y", "versionId": "18440aa7-a3c0-4970-a2f6-b5ad4017bb9d", "event": "activated", "userId": "0a88c0b1-928e-4412-896e-c5d1c99b2029" } ] } }