{ "updatedAt": "2026-06-15T13:19:17.505Z", "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\nconst audioMsg = message.audioMessage;\nconst imageMsg = message.imageMessage;\nconst videoMsg = message.videoMessage;\nconst documentMsg = message.documentMessage;\n\nconst documentMime = texto(documentMsg?.mimetype);\nconst documentFileName = texto(documentMsg?.fileName);\n\nlet messageType = 'unknown';\n\nif (audioMsg) {\n messageType = 'audio';\n} else if (imageMsg) {\n messageType = 'image';\n} else if (videoMsg) {\n messageType = 'video';\n} else if (documentMsg && documentMime.startsWith('video/')) {\n messageType = 'video';\n} else if (documentMsg && documentMime.startsWith('image/')) {\n messageType = 'image';\n} else if (documentMsg && documentMime.startsWith('audio/')) {\n messageType = 'audio';\n} else if (documentMsg) {\n messageType = 'document';\n} else if (textoMensaje) {\n messageType = 'text';\n}\n\nconst tieneMedia = ['audio', 'image', 'video', 'document'].includes(messageType);\n\nconst mediaMimeType =\n texto(audioMsg?.mimetype) ||\n texto(imageMsg?.mimetype) ||\n texto(videoMsg?.mimetype) ||\n documentMime ||\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: documentFileName,\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 }}", "media_source_id": "={{ $json.media_source_id }}", "media_mime_type": "={{ $json.media_mime_type }}", "media_file_name": "={{ $json.media_file_name }}", "whatsapp_remote_jid": "={{ $json.whatsapp_remote_jid }}" }, "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 }, { "id": "media_source_id", "displayName": "media_source_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_mime_type", "displayName": "media_mime_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_file_name", "displayName": "media_file_name", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "whatsapp_remote_jid", "displayName": "whatsapp_remote_jid", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 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 }}", "media_source_id": "={{ $json.media_source_id }}", "media_mime_type": "={{ $json.media_mime_type }}", "media_file_name": "={{ $json.media_file_name }}", "whatsapp_remote_jid": "={{ $json.whatsapp_remote_jid }}" }, "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 }, { "id": "media_source_id", "displayName": "media_source_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_mime_type", "displayName": "media_mime_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_file_name", "displayName": "media_file_name", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "whatsapp_remote_jid", "displayName": "whatsapp_remote_jid", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 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 }}", "media_source_id": "={{ $json.media_source_id }}", "media_mime_type": "={{ $json.media_mime_type }}", "media_file_name": "={{ $json.media_file_name }}", "whatsapp_remote_jid": "={{ $json.whatsapp_remote_jid }}" }, "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 }, { "id": "media_source_id", "displayName": "media_source_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_mime_type", "displayName": "media_mime_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_file_name", "displayName": "media_file_name", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "whatsapp_remote_jid", "displayName": "whatsapp_remote_jid", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 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" }, { "parameters": { "jsCode": "const data = $json || {};\nconst mediaLista = Array.isArray(data.media_lista) ? data.media_lista : [];\n\nconst sessionId = String(data.session_id || data.session_id_busqueda || '').trim();\nconst ejecucionId = String(data.ejecucion_id || sessionId).trim();\n\nconst items = mediaLista.map((media, index) => {\n const tipo = String(media.message_type || '').toLowerCase();\n const mime = String(media.media_mime_type || '').trim();\n\n let extension = 'bin';\n\n if (mime.includes('ogg')) extension = 'ogg';\n else if (mime.includes('mpeg')) extension = 'mp3';\n else if (mime.includes('mp4')) extension = 'mp4';\n else if (mime.includes('jpeg') || mime.includes('jpg')) extension = 'jpg';\n else if (mime.includes('png')) extension = 'png';\n else if (tipo === 'audio') extension = 'ogg';\n else if (tipo === 'image') extension = 'jpg';\n else if (tipo === 'video') extension = 'mp4';\n\n const mediaSourceId = String(\n media.media_source_id ||\n media.event_id ||\n ''\n ).trim();\n\n const remoteJid = String(\n media.whatsapp_remote_jid ||\n data.whatsapp_remote_jid ||\n data.whatsapp_to ||\n media.manager_telefono ||\n data.manager_telefono ||\n ''\n ).trim();\n\n return {\n json: {\n ...data,\n\n media_index: index + 1,\n media_total: mediaLista.length,\n\n session_id: sessionId,\n ejecucion_id: ejecucionId,\n\n media_event_id: media.event_id || '',\n media_source_id: mediaSourceId,\n media_type: tipo,\n media_mime_type: mime,\n media_extension: extension,\n\n whatsapp_remote_jid: remoteJid,\n\n media_file_name: `${ejecucionId}_${tipo}_${index + 1}.${extension}`,\n\n evento_original: media,\n\n estado_procesamiento: 'MEDIA_ITEM_PREPARADO'\n }\n };\n});\n\nreturn items;" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 4672, 1232 ], "id": "6d74dd89-9530-44d7-ae69-2e771bf8aab9", "name": "Code - Separar media en items WhatsApp TEST" }, { "parameters": { "method": "POST", "url": "https://wsp.gomezleemarketing.com/chat/getBase64FromMediaMessage/botsoporte", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "apikey", "value": "={{'C267126ABB45-4C12-B626-6BAB1833F5D7'}}" }, { "name": "Content-Type", "value": "application/json" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"message\": {\n \"key\": {\n \"id\": \"{{ $json.media_source_id }}\"\n }\n },\n \"convertToMp4\": true\n}", "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 4880, 1232 ], "id": "6c936089-6193-479f-b87b-a98e69e4fa92", "name": "HTTP Request - Obtener media base64 Evolution TEST", "alwaysOutputData": true }, { "parameters": { "jsCode": "const httpItems = $input.all();\nconst mediaItems = $('Code - Separar media en items WhatsApp TEST').all();\n\nconst buscarBase64 = (obj) => {\n if (!obj || typeof obj !== 'object') return '';\n\n if (typeof obj.base64 === 'string') return obj.base64;\n if (typeof obj.data === 'string') return obj.data;\n if (typeof obj.media === 'string') return obj.media;\n\n if (obj.message && typeof obj.message.base64 === 'string') return obj.message.base64;\n if (obj.response && typeof obj.response.base64 === 'string') return obj.response.base64;\n if (obj.data && typeof obj.data.base64 === 'string') return obj.data.base64;\n\n return '';\n};\n\nreturn httpItems.map((item, index) => {\n const respuesta = item.json || {};\n const mediaItem = mediaItems[index]?.json || mediaItems[0]?.json || {};\n\n let base64 = buscarBase64(respuesta);\n\n base64 = String(base64 || '').trim();\n base64 = base64.replace(/^data:.*?;base64,/, '');\n\n if (!base64) {\n throw new Error(`No se encontró base64 para media_source_id: ${mediaItem.media_source_id || 'SIN_ID'}`);\n }\n\n return {\n json: {\n ...mediaItem,\n\n base64_length: base64.length,\n estado_procesamiento: 'MEDIA_BASE64_RECUPERADA'\n },\n binary: {\n data: {\n data: base64,\n mimeType: mediaItem.media_mime_type || 'application/octet-stream',\n fileName: mediaItem.media_file_name || 'media_whatsapp.bin'\n }\n }\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5088, 1232 ], "id": "73f2d7f0-bc17-47cc-9b7a-f477f942bf63", "name": "Code - Convertir base64 a binario WhatsApp TEST" }, { "parameters": { "name": "={{ $json.media_file_name }}", "driveId": { "__rl": true, "mode": "list", "value": "My Drive" }, "folderId": { "__rl": true, "value": "=1G11WZnOwPp7UC2moPE6rEvlPFl7_OoSB", "mode": "id" }, "options": {} }, "type": "n8n-nodes-base.googleDrive", "typeVersion": 3, "position": [ 5328, 1232 ], "id": "c9d49cee-9f7f-4dfe-bf4a-5729a3f64298", "name": "Drive - Subir media WhatsApp TEST", "credentials": { "googleDriveOAuth2Api": { "id": "g23xdGLZRzBGqKgH", "name": "Isaac - Google Drive" } } }, { "parameters": { "jsCode": "const driveItems = $input.all();\nconst mediaItems = $('Code - Convertir base64 a binario WhatsApp TEST').all();\n\nreturn driveItems.map((item, index) => {\n const drive = item.json || {};\n const media = mediaItems[index]?.json || mediaItems[0]?.json || {};\n\n const fileId =\n drive.id ||\n drive.fileId ||\n drive.file_id ||\n '';\n\n const webViewLink =\n drive.webViewLink ||\n drive.webContentLink ||\n (fileId ? `https://drive.google.com/file/d/${fileId}/view` : '');\n\n return {\n json: {\n ...media,\n\n drive_file_id: fileId,\n drive_file_name: media.media_file_name,\n drive_file_url: webViewLink,\n\n estado_procesamiento: 'MEDIA_GUARDADA_EN_DRIVE'\n }\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5536, 1232 ], "id": "4bfe263f-272f-4738-8664-4f60990ad359", "name": "Code - Preparar registro media Drive WhatsApp TEST" }, { "parameters": { "jsCode": "const mediaItems = $('Code - Preparar registro media Drive WhatsApp TEST').all();\n\nconst media = mediaItems.map(item => item.json || {});\n\nconst base = media[0] || {};\n\nconst audios = media.filter(m => String(m.media_type || '').toLowerCase() === 'audio');\nconst imagenes = media.filter(m => String(m.media_type || '').toLowerCase() === 'image');\nconst videos = media.filter(m => String(m.media_type || '').toLowerCase() === 'video');\n\nreturn [\n {\n json: {\n ...base,\n\n session_id: base.session_id || '',\n ejecucion_id: base.ejecucion_id || base.session_id || '',\n\n audio_drive_urls: audios.map(m => m.drive_file_url).filter(Boolean).join('\\n'),\n imagenes_drive_urls: imagenes.map(m => m.drive_file_url).filter(Boolean).join('\\n'),\n videos_drive_urls: videos.map(m => m.drive_file_url).filter(Boolean).join('\\n'),\n\n total_media_drive: media.length,\n total_audio_drive: audios.length,\n total_imagenes_drive: imagenes.length,\n total_videos_drive: videos.length,\n\n ultima_actividad: new Date().toISOString(),\n\n etapa: 'PROCESANDO',\n estado: 'LISTO_PARA_ANALIZAR',\n motivo_revision: 'MEDIA_RECUPERADA',\n\n estado_procesamiento: 'MEDIA_RECUPERADA_Y_REGISTRADA'\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5952, 1232 ], "id": "8ecc5a7e-5520-49e8-909c-1a59a47f28f9", "name": "Code - Consolidar media recuperada 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": 1962428033, "mode": "list", "cachedResultName": "wa_ejecuciones_media", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=1962428033" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "media_event_id": "={{ $json.media_event_id }}", "media_type": "={{ $json.media_type }}", "media_mime_type": "={{ $json.media_mime_type }}", "media_file_name": "={{ $json.drive_file_name }}", "drive_file_id": "={{ $json.drive_file_id }}", "drive_file_url": "={{ $json.drive_file_url }}", "fecha_guardado": "={{ new Date().toISOString() }}", "estado": "=MEDIA_GUARDADA_EN_DRIVE", "media_index": "={{ $json.media_index }}", "media_total": "={{ $json.media_total }}", "whatsapp_remote_jid": "={{ $json.whatsapp_remote_jid }}" }, "matchingColumns": [], "schema": [ { "id": "session_id", "displayName": "session_id", "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": "media_event_id", "displayName": "media_event_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_type", "displayName": "media_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_mime_type", "displayName": "media_mime_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_file_name", "displayName": "media_file_name", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "drive_file_id", "displayName": "drive_file_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "drive_file_url", "displayName": "drive_file_url", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_guardado", "displayName": "fecha_guardado", "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": "media_index", "displayName": "media_index", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_total", "displayName": "media_total", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "whatsapp_remote_jid", "displayName": "whatsapp_remote_jid", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 5744, 1232 ], "id": "900504c8-6e4d-4ce4-bb36-55739dae8408", "name": "Sheets - Guardar media Drive WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "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 }}", "estado": "={{ $json.estado }}", "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": [ 6160, 1232 ], "id": "6f48b6b3-21bb-4f03-af72-68f67c2e0574", "name": "Sheets - Actualizar sesión media recuperada WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $('Code - Consolidar media recuperada WhatsApp TEST').first().json || {};\n\nconst audioUrls = String(data.audio_drive_urls || '').trim();\nconst imagenesUrls = String(data.imagenes_drive_urls || '').trim();\nconst videosUrls = String(data.videos_drive_urls || '').trim();\n\nconst prompt = `\nAnaliza esta ejecución de propuesta usando la evidencia disponible.\n\nIMPORTANTE:\n- La nota de voz contiene la descripción principal de la ejecución.\n- Las imágenes muestran evidencia visual obligatoria.\n- Los videos son evidencia opcional adicional.\n- No inventes datos que no estén claros.\n- Si un dato no aparece, marca \"No identificado\".\n\nDebes devolver SOLO un JSON válido con esta estructura:\n\n{\n \"propuesta_referencia\": \"\",\n \"marca\": \"\",\n \"cliente\": \"\",\n \"pais\": \"\",\n \"ubicacion\": \"\",\n \"fecha_ejecucion\": \"\",\n \"que_se_implemento\": \"\",\n \"comentarios_resultados\": \"\",\n \"resumen_ejecucion\": \"\",\n \"nivel_confianza\": \"\",\n \"requiere_revision\": \"\",\n \"motivo_revision\": \"\"\n}\n\nDatos de control:\nsession_id: ${data.session_id}\nejecucion_id: ${data.ejecucion_id}\nmanager_nombre: ${data.manager_nombre}\nmanager_telefono: ${data.manager_telefono}\n\nArchivos de audio en Drive:\n${audioUrls || 'No hay audio registrado'}\n\nImágenes en Drive:\n${imagenesUrls || 'No hay imágenes registradas'}\n\nVideos en Drive:\n${videosUrls || 'No hay videos registrados'}\n`.trim();\n\nreturn [\n {\n json: {\n ...data,\n gemini_prompt: prompt,\n estado_procesamiento: 'PAQUETE_GEMINI_PREPARADO'\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 6368, 1232 ], "id": "6fefc255-e85b-4028-b9e9-b3f71abe1457", "name": "Code - Preparar paquete análisis Gemini WhatsApp TEST" }, { "parameters": { "rules": { "values": [ { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "leftValue": "={{ String($json.media_type || '').toLowerCase() }}", "rightValue": "audio", "operator": { "type": "string", "operation": "equals" }, "id": "ddf19bdc-2a61-4261-8950-02ea3026ba01" } ], "combinator": "and" }, "renameOutput": true, "outputKey": "audio" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "dcf1d733-7b80-4f67-b6f6-9e965a5bae24", "leftValue": "={{ String($json.media_type || '').toLowerCase() }}", "rightValue": "image", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "=image" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "bb7e48e1-8383-463c-a43e-7e8e5d1ae21d", "leftValue": "={{ String($json.media_type || '').toLowerCase() }}", "rightValue": "video", "operator": { "type": "string", "operation": "equals", "name": "filter.operator.equals" } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "VIDEO" } ] }, "options": {} }, "type": "n8n-nodes-base.switch", "typeVersion": 3.4, "position": [ 5408, 1680 ], "id": "235d1178-5ecf-4225-b1c5-792512a22877", "name": "Switch - Tipo media para Gemini WhatsApp TEST" }, { "parameters": { "jsCode": "const input = $input.first();\nconst data = input.json || {};\nconst binary = input.binary || {};\n\nif (!binary.data) {\n throw new Error('No llegó binary.data al nodo de audio para Gemini');\n}\n\nreturn [\n {\n json: {\n ...data,\n gemini_prompt_audio: `Analiza esta nota de voz de una propuesta ejecutada.\n\nExtrae la mayor cantidad posible de información útil:\n- Nombre o referencia de la propuesta\n- Marca o cliente\n- País\n- Ubicación\n- Fecha de ejecución\n- Qué se implementó\n- Comentarios o resultados observados\n\nNo inventes datos. Si algo no está claro, indica \"No identificado\".`\n },\n binary\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5888, 1504 ], "id": "e3cfe03a-110b-4470-9011-e4705dcde4a7", "name": "Code - Preparar Gemini audio WhatsApp TEST" }, { "parameters": { "resource": "audio", "operation": "analyze", "modelId": { "__rl": true, "value": "models/gemini-2.5-flash-lite", "mode": "list", "cachedResultName": "models/gemini-2.5-flash-lite" }, "text": "={{ $json.gemini_prompt_audio }}", "inputType": "binary", "options": {} }, "type": "@n8n/n8n-nodes-langchain.googleGemini", "typeVersion": 1.2, "position": [ 6096, 1504 ], "id": "18ddf06b-efd7-49b0-b4bf-0f68e4c91a20", "name": "Gemini - Analizar audio WhatsApp TEST", "credentials": { "googlePalmApi": { "id": "6Jdcd9FONxG35YuJ", "name": "Isaac - Gemini Api Gratis" } } }, { "parameters": { "jsCode": "const resultados = $input.all();\nconst fuentes = $('Code - Preparar Gemini audio WhatsApp TEST').all();\n\nconst extraerTexto = (obj) => {\n if (!obj || typeof obj !== 'object') return '';\n\n if (typeof obj.text === 'string') return obj.text;\n if (typeof obj.output === 'string') return obj.output;\n if (typeof obj.response === 'string') return obj.response;\n if (typeof obj.content === 'string') return obj.content;\n\n if (Array.isArray(obj.candidates)) {\n return JSON.stringify(obj.candidates);\n }\n\n return JSON.stringify(obj);\n};\n\nreturn resultados.map((item, index) => {\n const gemini = item.json || {};\n const media = fuentes[index]?.json || fuentes[0]?.json || {};\n\n return {\n json: {\n session_id: media.session_id || '',\n ejecucion_id: media.ejecucion_id || '',\n media_event_id: media.media_event_id || '',\n media_type: 'audio',\n media_file_name: media.media_file_name || '',\n analisis_texto: extraerTexto(gemini),\n fecha_analisis: new Date().toISOString(),\n estado: 'ANALISIS_AUDIO_COMPLETADO',\n media_index: media.media_index || '',\n media_total: media.media_total || ''\n }\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 6304, 1504 ], "id": "2587e982-2403-450c-9419-a9de41d3c5a1", "name": "Code - Normalizar análisis audio WhatsApp TEST" }, { "parameters": { "jsCode": "const input = $input.first();\nconst data = input.json || {};\nconst binary = input.binary || {};\n\nif (!binary.data) {\n throw new Error('No llegó binary.data al nodo de imagen para Gemini');\n}\n\nreturn [\n {\n json: {\n ...data,\n gemini_prompt_imagen: `Analiza esta imagen como evidencia de una propuesta ejecutada.\n\nDescribe:\n- Qué se observa en la imagen\n- Elementos de marca visibles\n- Materiales instalados o implementados\n- Posible ubicación visible\n- Calidad de la implementación\n- Detalles relevantes para documentar la ejecución\n\nNo inventes datos que no sean visibles.`\n },\n binary\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5904, 1728 ], "id": "68e8b0de-373c-48fa-a762-8c0e45d64c15", "name": "Code - Preparar Gemini imagen WhatsApp TEST" }, { "parameters": { "resource": "image", "operation": "analyze", "modelId": { "__rl": true, "value": "models/gemini-2.5-flash-lite", "mode": "list", "cachedResultName": "models/gemini-2.5-flash-lite" }, "text": "={{ $json.gemini_prompt_imagen }}", "inputType": "binary", "options": {} }, "type": "@n8n/n8n-nodes-langchain.googleGemini", "typeVersion": 1.2, "position": [ 6112, 1728 ], "id": "1baf8c8e-95cf-42fe-af4f-fcbc71a557fc", "name": "Gemini - Analizar imagen WhatsApp TEST", "credentials": { "googlePalmApi": { "id": "6Jdcd9FONxG35YuJ", "name": "Isaac - Gemini Api Gratis" } } }, { "parameters": { "jsCode": "const resultados = $input.all();\nconst fuentes = $('Code - Preparar Gemini imagen WhatsApp TEST').all();\n\nconst extraerTexto = (obj) => {\n if (!obj || typeof obj !== 'object') return '';\n\n if (typeof obj.text === 'string') return obj.text;\n if (typeof obj.output === 'string') return obj.output;\n if (typeof obj.response === 'string') return obj.response;\n if (typeof obj.content === 'string') return obj.content;\n\n if (Array.isArray(obj.candidates)) {\n return JSON.stringify(obj.candidates);\n }\n\n return JSON.stringify(obj);\n};\n\nreturn resultados.map((item, index) => {\n const gemini = item.json || {};\n const media = fuentes[index]?.json || fuentes[0]?.json || {};\n\n return {\n json: {\n session_id: media.session_id || '',\n ejecucion_id: media.ejecucion_id || '',\n media_event_id: media.media_event_id || '',\n media_type: 'image',\n media_file_name: media.media_file_name || '',\n analisis_texto: extraerTexto(gemini),\n fecha_analisis: new Date().toISOString(),\n estado: 'ANALISIS_IMAGEN_COMPLETADO',\n media_index: media.media_index || '',\n media_total: media.media_total || ''\n }\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 6320, 1728 ], "id": "e1bc474b-82b0-4a4c-9ef7-e5f52b2b7503", "name": "Code - Normalizar análisis imagen WhatsApp TEST" }, { "parameters": { "jsCode": "const input = $input.first();\nconst data = input.json || {};\nconst binary = input.binary || {};\n\nif (!binary.data) {\n throw new Error('No llegó binary.data al nodo de video para Gemini');\n}\n\nreturn [\n {\n json: {\n ...data,\n gemini_prompt_video: `Analiza este video como evidencia de una propuesta ejecutada.\n\nDescribe:\n- Qué se observa en el video\n- Elementos de marca visibles\n- Materiales instalados o implementados\n- Interacciones o movimientos relevantes\n- Posible ubicación visible\n- Calidad de la implementación\n- Resultados observables\n\nNo inventes datos que no sean visibles.`\n },\n binary\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5776, 1968 ], "id": "5bfc997b-a538-4d96-8d7d-e4abe8e4cf9f", "name": "Code - Preparar Gemini video WhatsApp TEST" }, { "parameters": { "resource": "video", "operation": "analyze", "modelId": { "__rl": true, "value": "models/gemini-2.5-flash-lite", "mode": "list", "cachedResultName": "models/gemini-2.5-flash-lite" }, "text": "={{ $json.gemini_prompt_video }}", "inputType": "binary", "options": {} }, "type": "@n8n/n8n-nodes-langchain.googleGemini", "typeVersion": 1.2, "position": [ 5984, 1968 ], "id": "5767efd8-bfb6-4221-964d-743b417be1aa", "name": "Analyze video", "credentials": { "googlePalmApi": { "id": "6Jdcd9FONxG35YuJ", "name": "Isaac - Gemini Api Gratis" } } }, { "parameters": { "jsCode": "const resultados = $input.all();\nconst fuentes = $('Code - Preparar Gemini video WhatsApp TEST').all();\n\nconst extraerTexto = (obj) => {\n if (!obj || typeof obj !== 'object') return '';\n\n if (typeof obj.text === 'string') return obj.text;\n if (typeof obj.output === 'string') return obj.output;\n if (typeof obj.response === 'string') return obj.response;\n if (typeof obj.content === 'string') return obj.content;\n\n if (Array.isArray(obj.candidates)) {\n return JSON.stringify(obj.candidates);\n }\n\n return JSON.stringify(obj);\n};\n\nreturn resultados.map((item, index) => {\n const gemini = item.json || {};\n const media = fuentes[index]?.json || fuentes[0]?.json || {};\n\n return {\n json: {\n session_id: media.session_id || '',\n ejecucion_id: media.ejecucion_id || '',\n media_event_id: media.media_event_id || '',\n media_type: 'video',\n media_file_name: media.media_file_name || '',\n analisis_texto: extraerTexto(gemini),\n fecha_analisis: new Date().toISOString(),\n estado: 'ANALISIS_VIDEO_COMPLETADO',\n media_index: media.media_index || '',\n media_total: media.media_total || ''\n }\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 6192, 1968 ], "id": "c035db53-87b9-4fc2-9346-d5228bbac7b7", "name": "Code - Normalizar análisis 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": 1107394537, "mode": "list", "cachedResultName": "wa_ejecuciones_analisis_media", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=1107394537" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "media_event_id": "={{ $json.media_event_id }}", "media_type": "={{ $json.media_type }}", "media_file_name": "={{ $json.media_file_name }}", "analisis_texto": "={{ $json.analisis_texto }}", "fecha_analisis": "={{ $json.fecha_analisis }}", "estado": "={{ $json.estado }}", "media_index": "={{ $json.media_index }}", "media_total": "={{ $json.media_total }}" }, "matchingColumns": [], "schema": [ { "id": "session_id", "displayName": "session_id", "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": "media_event_id", "displayName": "media_event_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_type", "displayName": "media_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_file_name", "displayName": "media_file_name", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "analisis_texto", "displayName": "analisis_texto", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_analisis", "displayName": "fecha_analisis", "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": "media_index", "displayName": "media_index", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_total", "displayName": "media_total", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 6784, 1680 ], "id": "55f75826-cb50-4857-b58f-11bce7703b47", "name": "Sheets - Guardar análisis media Gemini WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } } ], "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 } ] ] }, "Code - Filtrar eventos media de sesión WhatsApp TEST": { "main": [ [ { "node": "Code - Separar media en items WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Separar media en items WhatsApp TEST": { "main": [ [ { "node": "HTTP Request - Obtener media base64 Evolution TEST", "type": "main", "index": 0 } ] ] }, "HTTP Request - Obtener media base64 Evolution TEST": { "main": [ [ { "node": "Code - Convertir base64 a binario WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Convertir base64 a binario WhatsApp TEST": { "main": [ [ { "node": "Drive - Subir media WhatsApp TEST", "type": "main", "index": 0 }, { "node": "Switch - Tipo media para Gemini WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Drive - Subir media WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar registro media Drive WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar registro media Drive WhatsApp TEST": { "main": [ [ { "node": "Sheets - Guardar media Drive WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Guardar media Drive WhatsApp TEST": { "main": [ [ { "node": "Code - Consolidar media recuperada WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Consolidar media recuperada WhatsApp TEST": { "main": [ [ { "node": "Sheets - Actualizar sesión media recuperada WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Actualizar sesión media recuperada WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar paquete análisis Gemini WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Switch - Tipo media para Gemini WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar Gemini audio WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar Gemini imagen WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar Gemini video WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar Gemini audio WhatsApp TEST": { "main": [ [ { "node": "Gemini - Analizar audio WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Gemini - Analizar audio WhatsApp TEST": { "main": [ [ { "node": "Code - Normalizar análisis audio WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar Gemini imagen WhatsApp TEST": { "main": [ [ { "node": "Gemini - Analizar imagen WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Gemini - Analizar imagen WhatsApp TEST": { "main": [ [ { "node": "Code - Normalizar análisis imagen WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar Gemini video WhatsApp TEST": { "main": [ [ { "node": "Analyze video", "type": "main", "index": 0 } ] ] }, "Analyze video": { "main": [ [ { "node": "Code - Normalizar análisis video WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Normalizar análisis video WhatsApp TEST": { "main": [ [ { "node": "Sheets - Guardar análisis media Gemini WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Normalizar análisis imagen WhatsApp TEST": { "main": [ [ { "node": "Sheets - Guardar análisis media Gemini WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Normalizar análisis audio WhatsApp TEST": { "main": [ [ { "node": "Sheets - Guardar análisis media Gemini WhatsApp TEST", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1", "binaryMode": "separate" }, "staticData": null, "meta": { "templateCredsSetupCompleted": true }, "versionId": "f3b250eb-aec9-4861-b8aa-319f56ae5e72", "activeVersionId": "f3b250eb-aec9-4861-b8aa-319f56ae5e72", "versionCounter": 906, "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-15T13:19:24.000Z", "createdAt": "2026-06-15T13:19:17.509Z", "versionId": "f3b250eb-aec9-4861-b8aa-319f56ae5e72", "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\nconst audioMsg = message.audioMessage;\nconst imageMsg = message.imageMessage;\nconst videoMsg = message.videoMessage;\nconst documentMsg = message.documentMessage;\n\nconst documentMime = texto(documentMsg?.mimetype);\nconst documentFileName = texto(documentMsg?.fileName);\n\nlet messageType = 'unknown';\n\nif (audioMsg) {\n messageType = 'audio';\n} else if (imageMsg) {\n messageType = 'image';\n} else if (videoMsg) {\n messageType = 'video';\n} else if (documentMsg && documentMime.startsWith('video/')) {\n messageType = 'video';\n} else if (documentMsg && documentMime.startsWith('image/')) {\n messageType = 'image';\n} else if (documentMsg && documentMime.startsWith('audio/')) {\n messageType = 'audio';\n} else if (documentMsg) {\n messageType = 'document';\n} else if (textoMensaje) {\n messageType = 'text';\n}\n\nconst tieneMedia = ['audio', 'image', 'video', 'document'].includes(messageType);\n\nconst mediaMimeType =\n texto(audioMsg?.mimetype) ||\n texto(imageMsg?.mimetype) ||\n texto(videoMsg?.mimetype) ||\n documentMime ||\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: documentFileName,\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 }}", "media_source_id": "={{ $json.media_source_id }}", "media_mime_type": "={{ $json.media_mime_type }}", "media_file_name": "={{ $json.media_file_name }}", "whatsapp_remote_jid": "={{ $json.whatsapp_remote_jid }}" }, "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 }, { "id": "media_source_id", "displayName": "media_source_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_mime_type", "displayName": "media_mime_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_file_name", "displayName": "media_file_name", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "whatsapp_remote_jid", "displayName": "whatsapp_remote_jid", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 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 }}", "media_source_id": "={{ $json.media_source_id }}", "media_mime_type": "={{ $json.media_mime_type }}", "media_file_name": "={{ $json.media_file_name }}", "whatsapp_remote_jid": "={{ $json.whatsapp_remote_jid }}" }, "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 }, { "id": "media_source_id", "displayName": "media_source_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_mime_type", "displayName": "media_mime_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_file_name", "displayName": "media_file_name", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "whatsapp_remote_jid", "displayName": "whatsapp_remote_jid", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 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 }}", "media_source_id": "={{ $json.media_source_id }}", "media_mime_type": "={{ $json.media_mime_type }}", "media_file_name": "={{ $json.media_file_name }}", "whatsapp_remote_jid": "={{ $json.whatsapp_remote_jid }}" }, "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 }, { "id": "media_source_id", "displayName": "media_source_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_mime_type", "displayName": "media_mime_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "media_file_name", "displayName": "media_file_name", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false }, { "id": "whatsapp_remote_jid", "displayName": "whatsapp_remote_jid", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true, "removed": false } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 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" }, { "parameters": { "jsCode": "const data = $json || {};\nconst mediaLista = Array.isArray(data.media_lista) ? data.media_lista : [];\n\nconst sessionId = String(data.session_id || data.session_id_busqueda || '').trim();\nconst ejecucionId = String(data.ejecucion_id || sessionId).trim();\n\nconst items = mediaLista.map((media, index) => {\n const tipo = String(media.message_type || '').toLowerCase();\n const mime = String(media.media_mime_type || '').trim();\n\n let extension = 'bin';\n\n if (mime.includes('ogg')) extension = 'ogg';\n else if (mime.includes('mpeg')) extension = 'mp3';\n else if (mime.includes('mp4')) extension = 'mp4';\n else if (mime.includes('jpeg') || mime.includes('jpg')) extension = 'jpg';\n else if (mime.includes('png')) extension = 'png';\n else if (tipo === 'audio') extension = 'ogg';\n else if (tipo === 'image') extension = 'jpg';\n else if (tipo === 'video') extension = 'mp4';\n\n const mediaSourceId = String(\n media.media_source_id ||\n media.event_id ||\n ''\n ).trim();\n\n const remoteJid = String(\n media.whatsapp_remote_jid ||\n data.whatsapp_remote_jid ||\n data.whatsapp_to ||\n media.manager_telefono ||\n data.manager_telefono ||\n ''\n ).trim();\n\n return {\n json: {\n ...data,\n\n media_index: index + 1,\n media_total: mediaLista.length,\n\n session_id: sessionId,\n ejecucion_id: ejecucionId,\n\n media_event_id: media.event_id || '',\n media_source_id: mediaSourceId,\n media_type: tipo,\n media_mime_type: mime,\n media_extension: extension,\n\n whatsapp_remote_jid: remoteJid,\n\n media_file_name: `${ejecucionId}_${tipo}_${index + 1}.${extension}`,\n\n evento_original: media,\n\n estado_procesamiento: 'MEDIA_ITEM_PREPARADO'\n }\n };\n});\n\nreturn items;" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 4672, 1232 ], "id": "6d74dd89-9530-44d7-ae69-2e771bf8aab9", "name": "Code - Separar media en items WhatsApp TEST" }, { "parameters": { "method": "POST", "url": "https://wsp.gomezleemarketing.com/chat/getBase64FromMediaMessage/botsoporte", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "apikey", "value": "={{'C267126ABB45-4C12-B626-6BAB1833F5D7'}}" }, { "name": "Content-Type", "value": "application/json" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"message\": {\n \"key\": {\n \"id\": \"{{ $json.media_source_id }}\"\n }\n },\n \"convertToMp4\": true\n}", "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.4, "position": [ 4880, 1232 ], "id": "6c936089-6193-479f-b87b-a98e69e4fa92", "name": "HTTP Request - Obtener media base64 Evolution TEST", "alwaysOutputData": true }, { "parameters": { "jsCode": "const httpItems = $input.all();\nconst mediaItems = $('Code - Separar media en items WhatsApp TEST').all();\n\nconst buscarBase64 = (obj) => {\n if (!obj || typeof obj !== 'object') return '';\n\n if (typeof obj.base64 === 'string') return obj.base64;\n if (typeof obj.data === 'string') return obj.data;\n if (typeof obj.media === 'string') return obj.media;\n\n if (obj.message && typeof obj.message.base64 === 'string') return obj.message.base64;\n if (obj.response && typeof obj.response.base64 === 'string') return obj.response.base64;\n if (obj.data && typeof obj.data.base64 === 'string') return obj.data.base64;\n\n return '';\n};\n\nreturn httpItems.map((item, index) => {\n const respuesta = item.json || {};\n const mediaItem = mediaItems[index]?.json || mediaItems[0]?.json || {};\n\n let base64 = buscarBase64(respuesta);\n\n base64 = String(base64 || '').trim();\n base64 = base64.replace(/^data:.*?;base64,/, '');\n\n if (!base64) {\n throw new Error(`No se encontró base64 para media_source_id: ${mediaItem.media_source_id || 'SIN_ID'}`);\n }\n\n return {\n json: {\n ...mediaItem,\n\n base64_length: base64.length,\n estado_procesamiento: 'MEDIA_BASE64_RECUPERADA'\n },\n binary: {\n data: {\n data: base64,\n mimeType: mediaItem.media_mime_type || 'application/octet-stream',\n fileName: mediaItem.media_file_name || 'media_whatsapp.bin'\n }\n }\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5088, 1232 ], "id": "73f2d7f0-bc17-47cc-9b7a-f477f942bf63", "name": "Code - Convertir base64 a binario WhatsApp TEST" }, { "parameters": { "name": "={{ $json.media_file_name }}", "driveId": { "__rl": true, "mode": "list", "value": "My Drive" }, "folderId": { "__rl": true, "value": "=1G11WZnOwPp7UC2moPE6rEvlPFl7_OoSB", "mode": "id" }, "options": {} }, "type": "n8n-nodes-base.googleDrive", "typeVersion": 3, "position": [ 5328, 1232 ], "id": "c9d49cee-9f7f-4dfe-bf4a-5729a3f64298", "name": "Drive - Subir media WhatsApp TEST", "credentials": { "googleDriveOAuth2Api": { "id": "g23xdGLZRzBGqKgH", "name": "Isaac - Google Drive" } } }, { "parameters": { "jsCode": "const driveItems = $input.all();\nconst mediaItems = $('Code - Convertir base64 a binario WhatsApp TEST').all();\n\nreturn driveItems.map((item, index) => {\n const drive = item.json || {};\n const media = mediaItems[index]?.json || mediaItems[0]?.json || {};\n\n const fileId =\n drive.id ||\n drive.fileId ||\n drive.file_id ||\n '';\n\n const webViewLink =\n drive.webViewLink ||\n drive.webContentLink ||\n (fileId ? `https://drive.google.com/file/d/${fileId}/view` : '');\n\n return {\n json: {\n ...media,\n\n drive_file_id: fileId,\n drive_file_name: media.media_file_name,\n drive_file_url: webViewLink,\n\n estado_procesamiento: 'MEDIA_GUARDADA_EN_DRIVE'\n }\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5536, 1232 ], "id": "4bfe263f-272f-4738-8664-4f60990ad359", "name": "Code - Preparar registro media Drive WhatsApp TEST" }, { "parameters": { "jsCode": "const mediaItems = $('Code - Preparar registro media Drive WhatsApp TEST').all();\n\nconst media = mediaItems.map(item => item.json || {});\n\nconst base = media[0] || {};\n\nconst audios = media.filter(m => String(m.media_type || '').toLowerCase() === 'audio');\nconst imagenes = media.filter(m => String(m.media_type || '').toLowerCase() === 'image');\nconst videos = media.filter(m => String(m.media_type || '').toLowerCase() === 'video');\n\nreturn [\n {\n json: {\n ...base,\n\n session_id: base.session_id || '',\n ejecucion_id: base.ejecucion_id || base.session_id || '',\n\n audio_drive_urls: audios.map(m => m.drive_file_url).filter(Boolean).join('\\n'),\n imagenes_drive_urls: imagenes.map(m => m.drive_file_url).filter(Boolean).join('\\n'),\n videos_drive_urls: videos.map(m => m.drive_file_url).filter(Boolean).join('\\n'),\n\n total_media_drive: media.length,\n total_audio_drive: audios.length,\n total_imagenes_drive: imagenes.length,\n total_videos_drive: videos.length,\n\n ultima_actividad: new Date().toISOString(),\n\n etapa: 'PROCESANDO',\n estado: 'LISTO_PARA_ANALIZAR',\n motivo_revision: 'MEDIA_RECUPERADA',\n\n estado_procesamiento: 'MEDIA_RECUPERADA_Y_REGISTRADA'\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5952, 1232 ], "id": "8ecc5a7e-5520-49e8-909c-1a59a47f28f9", "name": "Code - Consolidar media recuperada 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": 1962428033, "mode": "list", "cachedResultName": "wa_ejecuciones_media", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=1962428033" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "media_event_id": "={{ $json.media_event_id }}", "media_type": "={{ $json.media_type }}", "media_mime_type": "={{ $json.media_mime_type }}", "media_file_name": "={{ $json.drive_file_name }}", "drive_file_id": "={{ $json.drive_file_id }}", "drive_file_url": "={{ $json.drive_file_url }}", "fecha_guardado": "={{ new Date().toISOString() }}", "estado": "=MEDIA_GUARDADA_EN_DRIVE", "media_index": "={{ $json.media_index }}", "media_total": "={{ $json.media_total }}", "whatsapp_remote_jid": "={{ $json.whatsapp_remote_jid }}" }, "matchingColumns": [], "schema": [ { "id": "session_id", "displayName": "session_id", "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": "media_event_id", "displayName": "media_event_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_type", "displayName": "media_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_mime_type", "displayName": "media_mime_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_file_name", "displayName": "media_file_name", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "drive_file_id", "displayName": "drive_file_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "drive_file_url", "displayName": "drive_file_url", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_guardado", "displayName": "fecha_guardado", "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": "media_index", "displayName": "media_index", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_total", "displayName": "media_total", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "whatsapp_remote_jid", "displayName": "whatsapp_remote_jid", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 5744, 1232 ], "id": "900504c8-6e4d-4ce4-bb36-55739dae8408", "name": "Sheets - Guardar media Drive WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "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 }}", "estado": "={{ $json.estado }}", "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": [ 6160, 1232 ], "id": "6f48b6b3-21bb-4f03-af72-68f67c2e0574", "name": "Sheets - Actualizar sesión media recuperada WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } }, { "parameters": { "jsCode": "const data = $('Code - Consolidar media recuperada WhatsApp TEST').first().json || {};\n\nconst audioUrls = String(data.audio_drive_urls || '').trim();\nconst imagenesUrls = String(data.imagenes_drive_urls || '').trim();\nconst videosUrls = String(data.videos_drive_urls || '').trim();\n\nconst prompt = `\nAnaliza esta ejecución de propuesta usando la evidencia disponible.\n\nIMPORTANTE:\n- La nota de voz contiene la descripción principal de la ejecución.\n- Las imágenes muestran evidencia visual obligatoria.\n- Los videos son evidencia opcional adicional.\n- No inventes datos que no estén claros.\n- Si un dato no aparece, marca \"No identificado\".\n\nDebes devolver SOLO un JSON válido con esta estructura:\n\n{\n \"propuesta_referencia\": \"\",\n \"marca\": \"\",\n \"cliente\": \"\",\n \"pais\": \"\",\n \"ubicacion\": \"\",\n \"fecha_ejecucion\": \"\",\n \"que_se_implemento\": \"\",\n \"comentarios_resultados\": \"\",\n \"resumen_ejecucion\": \"\",\n \"nivel_confianza\": \"\",\n \"requiere_revision\": \"\",\n \"motivo_revision\": \"\"\n}\n\nDatos de control:\nsession_id: ${data.session_id}\nejecucion_id: ${data.ejecucion_id}\nmanager_nombre: ${data.manager_nombre}\nmanager_telefono: ${data.manager_telefono}\n\nArchivos de audio en Drive:\n${audioUrls || 'No hay audio registrado'}\n\nImágenes en Drive:\n${imagenesUrls || 'No hay imágenes registradas'}\n\nVideos en Drive:\n${videosUrls || 'No hay videos registrados'}\n`.trim();\n\nreturn [\n {\n json: {\n ...data,\n gemini_prompt: prompt,\n estado_procesamiento: 'PAQUETE_GEMINI_PREPARADO'\n }\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 6368, 1232 ], "id": "6fefc255-e85b-4028-b9e9-b3f71abe1457", "name": "Code - Preparar paquete análisis Gemini WhatsApp TEST" }, { "parameters": { "rules": { "values": [ { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "leftValue": "={{ String($json.media_type || '').toLowerCase() }}", "rightValue": "audio", "operator": { "type": "string", "operation": "equals" }, "id": "ddf19bdc-2a61-4261-8950-02ea3026ba01" } ], "combinator": "and" }, "renameOutput": true, "outputKey": "audio" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "dcf1d733-7b80-4f67-b6f6-9e965a5bae24", "leftValue": "={{ String($json.media_type || '').toLowerCase() }}", "rightValue": "image", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "=image" }, { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 3 }, "conditions": [ { "id": "bb7e48e1-8383-463c-a43e-7e8e5d1ae21d", "leftValue": "={{ String($json.media_type || '').toLowerCase() }}", "rightValue": "video", "operator": { "type": "string", "operation": "equals", "name": "filter.operator.equals" } } ], "combinator": "and" }, "renameOutput": true, "outputKey": "VIDEO" } ] }, "options": {} }, "type": "n8n-nodes-base.switch", "typeVersion": 3.4, "position": [ 5408, 1680 ], "id": "235d1178-5ecf-4225-b1c5-792512a22877", "name": "Switch - Tipo media para Gemini WhatsApp TEST" }, { "parameters": { "jsCode": "const input = $input.first();\nconst data = input.json || {};\nconst binary = input.binary || {};\n\nif (!binary.data) {\n throw new Error('No llegó binary.data al nodo de audio para Gemini');\n}\n\nreturn [\n {\n json: {\n ...data,\n gemini_prompt_audio: `Analiza esta nota de voz de una propuesta ejecutada.\n\nExtrae la mayor cantidad posible de información útil:\n- Nombre o referencia de la propuesta\n- Marca o cliente\n- País\n- Ubicación\n- Fecha de ejecución\n- Qué se implementó\n- Comentarios o resultados observados\n\nNo inventes datos. Si algo no está claro, indica \"No identificado\".`\n },\n binary\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5888, 1504 ], "id": "e3cfe03a-110b-4470-9011-e4705dcde4a7", "name": "Code - Preparar Gemini audio WhatsApp TEST" }, { "parameters": { "resource": "audio", "operation": "analyze", "modelId": { "__rl": true, "value": "models/gemini-2.5-flash-lite", "mode": "list", "cachedResultName": "models/gemini-2.5-flash-lite" }, "text": "={{ $json.gemini_prompt_audio }}", "inputType": "binary", "options": {} }, "type": "@n8n/n8n-nodes-langchain.googleGemini", "typeVersion": 1.2, "position": [ 6096, 1504 ], "id": "18ddf06b-efd7-49b0-b4bf-0f68e4c91a20", "name": "Gemini - Analizar audio WhatsApp TEST", "credentials": { "googlePalmApi": { "id": "6Jdcd9FONxG35YuJ", "name": "Isaac - Gemini Api Gratis" } } }, { "parameters": { "jsCode": "const resultados = $input.all();\nconst fuentes = $('Code - Preparar Gemini audio WhatsApp TEST').all();\n\nconst extraerTexto = (obj) => {\n if (!obj || typeof obj !== 'object') return '';\n\n if (typeof obj.text === 'string') return obj.text;\n if (typeof obj.output === 'string') return obj.output;\n if (typeof obj.response === 'string') return obj.response;\n if (typeof obj.content === 'string') return obj.content;\n\n if (Array.isArray(obj.candidates)) {\n return JSON.stringify(obj.candidates);\n }\n\n return JSON.stringify(obj);\n};\n\nreturn resultados.map((item, index) => {\n const gemini = item.json || {};\n const media = fuentes[index]?.json || fuentes[0]?.json || {};\n\n return {\n json: {\n session_id: media.session_id || '',\n ejecucion_id: media.ejecucion_id || '',\n media_event_id: media.media_event_id || '',\n media_type: 'audio',\n media_file_name: media.media_file_name || '',\n analisis_texto: extraerTexto(gemini),\n fecha_analisis: new Date().toISOString(),\n estado: 'ANALISIS_AUDIO_COMPLETADO',\n media_index: media.media_index || '',\n media_total: media.media_total || ''\n }\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 6304, 1504 ], "id": "2587e982-2403-450c-9419-a9de41d3c5a1", "name": "Code - Normalizar análisis audio WhatsApp TEST" }, { "parameters": { "jsCode": "const input = $input.first();\nconst data = input.json || {};\nconst binary = input.binary || {};\n\nif (!binary.data) {\n throw new Error('No llegó binary.data al nodo de imagen para Gemini');\n}\n\nreturn [\n {\n json: {\n ...data,\n gemini_prompt_imagen: `Analiza esta imagen como evidencia de una propuesta ejecutada.\n\nDescribe:\n- Qué se observa en la imagen\n- Elementos de marca visibles\n- Materiales instalados o implementados\n- Posible ubicación visible\n- Calidad de la implementación\n- Detalles relevantes para documentar la ejecución\n\nNo inventes datos que no sean visibles.`\n },\n binary\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5904, 1728 ], "id": "68e8b0de-373c-48fa-a762-8c0e45d64c15", "name": "Code - Preparar Gemini imagen WhatsApp TEST" }, { "parameters": { "resource": "image", "operation": "analyze", "modelId": { "__rl": true, "value": "models/gemini-2.5-flash-lite", "mode": "list", "cachedResultName": "models/gemini-2.5-flash-lite" }, "text": "={{ $json.gemini_prompt_imagen }}", "inputType": "binary", "options": {} }, "type": "@n8n/n8n-nodes-langchain.googleGemini", "typeVersion": 1.2, "position": [ 6112, 1728 ], "id": "1baf8c8e-95cf-42fe-af4f-fcbc71a557fc", "name": "Gemini - Analizar imagen WhatsApp TEST", "credentials": { "googlePalmApi": { "id": "6Jdcd9FONxG35YuJ", "name": "Isaac - Gemini Api Gratis" } } }, { "parameters": { "jsCode": "const resultados = $input.all();\nconst fuentes = $('Code - Preparar Gemini imagen WhatsApp TEST').all();\n\nconst extraerTexto = (obj) => {\n if (!obj || typeof obj !== 'object') return '';\n\n if (typeof obj.text === 'string') return obj.text;\n if (typeof obj.output === 'string') return obj.output;\n if (typeof obj.response === 'string') return obj.response;\n if (typeof obj.content === 'string') return obj.content;\n\n if (Array.isArray(obj.candidates)) {\n return JSON.stringify(obj.candidates);\n }\n\n return JSON.stringify(obj);\n};\n\nreturn resultados.map((item, index) => {\n const gemini = item.json || {};\n const media = fuentes[index]?.json || fuentes[0]?.json || {};\n\n return {\n json: {\n session_id: media.session_id || '',\n ejecucion_id: media.ejecucion_id || '',\n media_event_id: media.media_event_id || '',\n media_type: 'image',\n media_file_name: media.media_file_name || '',\n analisis_texto: extraerTexto(gemini),\n fecha_analisis: new Date().toISOString(),\n estado: 'ANALISIS_IMAGEN_COMPLETADO',\n media_index: media.media_index || '',\n media_total: media.media_total || ''\n }\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 6320, 1728 ], "id": "e1bc474b-82b0-4a4c-9ef7-e5f52b2b7503", "name": "Code - Normalizar análisis imagen WhatsApp TEST" }, { "parameters": { "jsCode": "const input = $input.first();\nconst data = input.json || {};\nconst binary = input.binary || {};\n\nif (!binary.data) {\n throw new Error('No llegó binary.data al nodo de video para Gemini');\n}\n\nreturn [\n {\n json: {\n ...data,\n gemini_prompt_video: `Analiza este video como evidencia de una propuesta ejecutada.\n\nDescribe:\n- Qué se observa en el video\n- Elementos de marca visibles\n- Materiales instalados o implementados\n- Interacciones o movimientos relevantes\n- Posible ubicación visible\n- Calidad de la implementación\n- Resultados observables\n\nNo inventes datos que no sean visibles.`\n },\n binary\n }\n];" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 5776, 1968 ], "id": "5bfc997b-a538-4d96-8d7d-e4abe8e4cf9f", "name": "Code - Preparar Gemini video WhatsApp TEST" }, { "parameters": { "resource": "video", "operation": "analyze", "modelId": { "__rl": true, "value": "models/gemini-2.5-flash-lite", "mode": "list", "cachedResultName": "models/gemini-2.5-flash-lite" }, "text": "={{ $json.gemini_prompt_video }}", "inputType": "binary", "options": {} }, "type": "@n8n/n8n-nodes-langchain.googleGemini", "typeVersion": 1.2, "position": [ 5984, 1968 ], "id": "5767efd8-bfb6-4221-964d-743b417be1aa", "name": "Analyze video", "credentials": { "googlePalmApi": { "id": "6Jdcd9FONxG35YuJ", "name": "Isaac - Gemini Api Gratis" } } }, { "parameters": { "jsCode": "const resultados = $input.all();\nconst fuentes = $('Code - Preparar Gemini video WhatsApp TEST').all();\n\nconst extraerTexto = (obj) => {\n if (!obj || typeof obj !== 'object') return '';\n\n if (typeof obj.text === 'string') return obj.text;\n if (typeof obj.output === 'string') return obj.output;\n if (typeof obj.response === 'string') return obj.response;\n if (typeof obj.content === 'string') return obj.content;\n\n if (Array.isArray(obj.candidates)) {\n return JSON.stringify(obj.candidates);\n }\n\n return JSON.stringify(obj);\n};\n\nreturn resultados.map((item, index) => {\n const gemini = item.json || {};\n const media = fuentes[index]?.json || fuentes[0]?.json || {};\n\n return {\n json: {\n session_id: media.session_id || '',\n ejecucion_id: media.ejecucion_id || '',\n media_event_id: media.media_event_id || '',\n media_type: 'video',\n media_file_name: media.media_file_name || '',\n analisis_texto: extraerTexto(gemini),\n fecha_analisis: new Date().toISOString(),\n estado: 'ANALISIS_VIDEO_COMPLETADO',\n media_index: media.media_index || '',\n media_total: media.media_total || ''\n }\n };\n});" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 6192, 1968 ], "id": "c035db53-87b9-4fc2-9346-d5228bbac7b7", "name": "Code - Normalizar análisis 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": 1107394537, "mode": "list", "cachedResultName": "wa_ejecuciones_analisis_media", "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nbeuaW2lxvWJYVFD-E0uJRhTGzUa-nuH2WYItHdTsKk/edit#gid=1107394537" }, "columns": { "mappingMode": "defineBelow", "value": { "session_id": "={{ $json.session_id }}", "ejecucion_id": "={{ $json.ejecucion_id }}", "media_event_id": "={{ $json.media_event_id }}", "media_type": "={{ $json.media_type }}", "media_file_name": "={{ $json.media_file_name }}", "analisis_texto": "={{ $json.analisis_texto }}", "fecha_analisis": "={{ $json.fecha_analisis }}", "estado": "={{ $json.estado }}", "media_index": "={{ $json.media_index }}", "media_total": "={{ $json.media_total }}" }, "matchingColumns": [], "schema": [ { "id": "session_id", "displayName": "session_id", "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": "media_event_id", "displayName": "media_event_id", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_type", "displayName": "media_type", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_file_name", "displayName": "media_file_name", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "analisis_texto", "displayName": "analisis_texto", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "fecha_analisis", "displayName": "fecha_analisis", "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": "media_index", "displayName": "media_index", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }, { "id": "media_total", "displayName": "media_total", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true } ], "attemptToConvertTypes": false, "convertFieldsToString": false }, "options": {} }, "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ 6784, 1680 ], "id": "55f75826-cb50-4857-b58f-11bce7703b47", "name": "Sheets - Guardar análisis media Gemini WhatsApp TEST", "credentials": { "googleSheetsOAuth2Api": { "id": "K0hDZh3a85MpOHCs", "name": "Google Sheets account 2" } } } ], "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 } ] ] }, "Code - Filtrar eventos media de sesión WhatsApp TEST": { "main": [ [ { "node": "Code - Separar media en items WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Separar media en items WhatsApp TEST": { "main": [ [ { "node": "HTTP Request - Obtener media base64 Evolution TEST", "type": "main", "index": 0 } ] ] }, "HTTP Request - Obtener media base64 Evolution TEST": { "main": [ [ { "node": "Code - Convertir base64 a binario WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Convertir base64 a binario WhatsApp TEST": { "main": [ [ { "node": "Drive - Subir media WhatsApp TEST", "type": "main", "index": 0 }, { "node": "Switch - Tipo media para Gemini WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Drive - Subir media WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar registro media Drive WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar registro media Drive WhatsApp TEST": { "main": [ [ { "node": "Sheets - Guardar media Drive WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Guardar media Drive WhatsApp TEST": { "main": [ [ { "node": "Code - Consolidar media recuperada WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Consolidar media recuperada WhatsApp TEST": { "main": [ [ { "node": "Sheets - Actualizar sesión media recuperada WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Sheets - Actualizar sesión media recuperada WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar paquete análisis Gemini WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Switch - Tipo media para Gemini WhatsApp TEST": { "main": [ [ { "node": "Code - Preparar Gemini audio WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar Gemini imagen WhatsApp TEST", "type": "main", "index": 0 } ], [ { "node": "Code - Preparar Gemini video WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar Gemini audio WhatsApp TEST": { "main": [ [ { "node": "Gemini - Analizar audio WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Gemini - Analizar audio WhatsApp TEST": { "main": [ [ { "node": "Code - Normalizar análisis audio WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar Gemini imagen WhatsApp TEST": { "main": [ [ { "node": "Gemini - Analizar imagen WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Gemini - Analizar imagen WhatsApp TEST": { "main": [ [ { "node": "Code - Normalizar análisis imagen WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Preparar Gemini video WhatsApp TEST": { "main": [ [ { "node": "Analyze video", "type": "main", "index": 0 } ] ] }, "Analyze video": { "main": [ [ { "node": "Code - Normalizar análisis video WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Normalizar análisis video WhatsApp TEST": { "main": [ [ { "node": "Sheets - Guardar análisis media Gemini WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Normalizar análisis imagen WhatsApp TEST": { "main": [ [ { "node": "Sheets - Guardar análisis media Gemini WhatsApp TEST", "type": "main", "index": 0 } ] ] }, "Code - Normalizar análisis audio WhatsApp TEST": { "main": [ [ { "node": "Sheets - Guardar análisis media Gemini WhatsApp TEST", "type": "main", "index": 0 } ] ] } }, "authors": "Isaac Aracena", "name": "Version f3b250eb", "description": "", "autosaved": true, "workflowPublishHistory": [ { "createdAt": "2026-06-15T13:19:24.505Z", "id": 1393, "workflowId": "sXH75CXIQ0sEzm1Y", "versionId": "f3b250eb-aec9-4861-b8aa-319f56ae5e72", "event": "activated", "userId": "0a88c0b1-928e-4412-896e-c5d1c99b2029" } ] } }