From dc5a222ce5f1495d42f5e73a5f00df124225c6b8 Mon Sep 17 00:00:00 2001 From: Isaac_Aracena Date: Wed, 17 Jun 2026 04:00:31 +0000 Subject: [PATCH] Update backup: Chat de WhatsApp - Propuestas Ejecutadas --- chat-de-whatsapp-propuestas-ejecutadas.json | 3404 ++++++++++++++++++- 1 file changed, 3359 insertions(+), 45 deletions(-) diff --git a/chat-de-whatsapp-propuestas-ejecutadas.json b/chat-de-whatsapp-propuestas-ejecutadas.json index 59483cc..0d660e0 100644 --- a/chat-de-whatsapp-propuestas-ejecutadas.json +++ b/chat-de-whatsapp-propuestas-ejecutadas.json @@ -1,5 +1,5 @@ { - "updatedAt": "2026-06-10T03:42:28.252Z", + "updatedAt": "2026-06-15T13:19:17.505Z", "createdAt": "2026-06-08T20:09:28.132Z", "id": "sXH75CXIQ0sEzm1Y", "name": "Chat de WhatsApp - Propuestas Ejecutadas", @@ -50,7 +50,7 @@ }, { "parameters": { - "jsCode": "const input = $json || {};\nconst body = input.body || input;\nconst data = body.data || {};\n\nconst texto = (valor) => String(valor ?? '').trim();\n\nconst limpiarNumero = (valor) =>\n texto(valor)\n .replace('@s.whatsapp.net', '')\n .replace('@c.us', '')\n .replace('@g.us', '')\n .replace(/\\D/g, '');\n\nconst key = data.key || {};\n\nconst remoteJid = texto(key.remoteJid || data.remoteJid || body.remoteJid || '');\nconst managerTelefono = limpiarNumero(remoteJid);\n\nconst pushName =\n texto(data.pushName) ||\n texto(body.pushName) ||\n 'Usuario WhatsApp';\n\nconst message = data.message || {};\n\nconst textoMensaje =\n texto(message.conversation) ||\n texto(message.extendedTextMessage?.text) ||\n texto(data.messageText) ||\n texto(data.text) ||\n texto(body.text) ||\n '';\n\nlet messageType = 'unknown';\n\nif (message.audioMessage) {\n messageType = 'audio';\n} else if (message.imageMessage) {\n messageType = 'image';\n} else if (message.videoMessage) {\n messageType = 'video';\n} else if (textoMensaje) {\n messageType = 'text';\n}\n\nconst tieneMedia = ['audio', 'image', 'video'].includes(messageType);\n\nconst mediaMimeType =\n texto(message.audioMessage?.mimetype) ||\n texto(message.imageMessage?.mimetype) ||\n texto(message.videoMessage?.mimetype) ||\n '';\n\nconst mediaSourceId =\n texto(key.id) ||\n texto(data.id) ||\n texto(data.messageId) ||\n '';\n\nconst normalizarComando = (valor) => {\n const t = texto(valor)\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toUpperCase();\n\n if (t === '/START' || t === 'START' || t === 'INICIAR') return 'START';\n if (t === 'CANCELAR') return 'CANCELAR';\n if (t === 'FOTOS LISTAS' || t === 'FOTOS_LISTAS') return 'FOTOS_LISTAS';\n if (t === 'SIN VIDEO' || t === 'SIN_VIDEO') return 'SIN_VIDEO';\n if (t === 'LISTO') return 'LISTO';\n\n return 'NORMAL';\n};\n\nreturn [\n {\n json: {\n event_id: texto(key.id || data.id || Date.now()),\n fecha_recepcion: new Date().toISOString(),\n\n canal_origen: 'WHATSAPP',\n\n manager_telefono: managerTelefono,\n manager_nombre: pushName,\n usuario_id_origen: managerTelefono,\n\n whatsapp_remote_jid: remoteJid,\n whatsapp_to: remoteJid,\n\n from_me: Boolean(key.fromMe || data.fromMe || false),\n\n message_type: messageType,\n texto: textoMensaje,\n accion_flujo: normalizarComando(textoMensaje),\n\n tiene_media: tieneMedia,\n media_count: tieneMedia ? 1 : 0,\n media_source_id: mediaSourceId,\n media_mime_type: mediaMimeType,\n media_file_name: '',\n\n raw_preview: JSON.stringify(body).slice(0, 4000),\n raw_event: body,\n },\n },\n];" + "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, @@ -928,7 +928,11 @@ "fecha_procesado": "={{ $json.fecha_procesado }}", "session_id": "={{ $json.session_id }}", "canal_origen": "={{ $json.canal_origen }}", - "etapa_recibida": "={{ $json.etapa_recibida }}" + "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": [ @@ -1075,6 +1079,46 @@ "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, @@ -1792,7 +1836,11 @@ "texto": "={{ $json.texto }}", "media_count": "={{ $json.media_count }}", "raw_preview": "={{ $json.raw_preview }}", - "etapa_recibida": "={{ $json.etapa_actual }}" + "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": [ @@ -1939,6 +1987,46 @@ "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, @@ -2441,7 +2529,11 @@ "ejecucion_id": "={{ $json.ejecucion_id }}", "session_id": "={{ $json.session_id }}", "canal_origen": "={{ $json.canal_origen }}", - "etapa_recibida": "={{ $json.etapa_actual }}" + "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": [ @@ -2588,6 +2680,46 @@ "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, @@ -3102,6 +3234,886 @@ ], "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": { @@ -3676,6 +4688,234 @@ } ] ] + }, + "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": { @@ -3686,9 +4926,9 @@ "meta": { "templateCredsSetupCompleted": true }, - "versionId": "480a88db-5bc0-4feb-aa97-442645b0b4e5", - "activeVersionId": "18440aa7-a3c0-4970-a2f6-b5ad4017bb9d", - "versionCounter": 644, + "versionId": "f3b250eb-aec9-4861-b8aa-319f56ae5e72", + "activeVersionId": "f3b250eb-aec9-4861-b8aa-319f56ae5e72", + "versionCounter": 906, "triggerCount": 1, "shared": [ { @@ -3711,9 +4951,9 @@ ], "tags": [], "activeVersion": { - "updatedAt": "2026-06-10T02:20:30.000Z", - "createdAt": "2026-06-10T02:19:46.263Z", - "versionId": "18440aa7-a3c0-4970-a2f6-b5ad4017bb9d", + "updatedAt": "2026-06-15T13:19:24.000Z", + "createdAt": "2026-06-15T13:19:17.509Z", + "versionId": "f3b250eb-aec9-4861-b8aa-319f56ae5e72", "workflowId": "sXH75CXIQ0sEzm1Y", "nodes": [ { @@ -3759,7 +4999,7 @@ }, { "parameters": { - "jsCode": "const input = $json || {};\nconst body = input.body || input;\nconst data = body.data || {};\n\nconst texto = (valor) => String(valor ?? '').trim();\n\nconst limpiarNumero = (valor) =>\n texto(valor)\n .replace('@s.whatsapp.net', '')\n .replace('@c.us', '')\n .replace('@g.us', '')\n .replace(/\\D/g, '');\n\nconst key = data.key || {};\n\nconst remoteJid = texto(key.remoteJid || data.remoteJid || body.remoteJid || '');\nconst managerTelefono = limpiarNumero(remoteJid);\n\nconst pushName =\n texto(data.pushName) ||\n texto(body.pushName) ||\n 'Usuario WhatsApp';\n\nconst message = data.message || {};\n\nconst textoMensaje =\n texto(message.conversation) ||\n texto(message.extendedTextMessage?.text) ||\n texto(data.messageText) ||\n texto(data.text) ||\n texto(body.text) ||\n '';\n\nlet messageType = 'unknown';\n\nif (message.audioMessage) {\n messageType = 'audio';\n} else if (message.imageMessage) {\n messageType = 'image';\n} else if (message.videoMessage) {\n messageType = 'video';\n} else if (textoMensaje) {\n messageType = 'text';\n}\n\nconst tieneMedia = ['audio', 'image', 'video'].includes(messageType);\n\nconst mediaMimeType =\n texto(message.audioMessage?.mimetype) ||\n texto(message.imageMessage?.mimetype) ||\n texto(message.videoMessage?.mimetype) ||\n '';\n\nconst mediaSourceId =\n texto(key.id) ||\n texto(data.id) ||\n texto(data.messageId) ||\n '';\n\nconst normalizarComando = (valor) => {\n const t = texto(valor)\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toUpperCase();\n\n if (t === '/START' || t === 'START' || t === 'INICIAR') return 'START';\n if (t === 'CANCELAR') return 'CANCELAR';\n if (t === 'FOTOS LISTAS' || t === 'FOTOS_LISTAS') return 'FOTOS_LISTAS';\n if (t === 'SIN VIDEO' || t === 'SIN_VIDEO') return 'SIN_VIDEO';\n if (t === 'LISTO') return 'LISTO';\n\n return 'NORMAL';\n};\n\nreturn [\n {\n json: {\n event_id: texto(key.id || data.id || Date.now()),\n fecha_recepcion: new Date().toISOString(),\n\n canal_origen: 'WHATSAPP',\n\n manager_telefono: managerTelefono,\n manager_nombre: pushName,\n usuario_id_origen: managerTelefono,\n\n whatsapp_remote_jid: remoteJid,\n whatsapp_to: remoteJid,\n\n from_me: Boolean(key.fromMe || data.fromMe || false),\n\n message_type: messageType,\n texto: textoMensaje,\n accion_flujo: normalizarComando(textoMensaje),\n\n tiene_media: tieneMedia,\n media_count: tieneMedia ? 1 : 0,\n media_source_id: mediaSourceId,\n media_mime_type: mediaMimeType,\n media_file_name: '',\n\n raw_preview: JSON.stringify(body).slice(0, 4000),\n raw_event: body,\n },\n },\n];" + "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, @@ -4637,7 +5877,11 @@ "fecha_procesado": "={{ $json.fecha_procesado }}", "session_id": "={{ $json.session_id }}", "canal_origen": "={{ $json.canal_origen }}", - "etapa_recibida": "={{ $json.etapa_recibida }}" + "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": [ @@ -4784,6 +6028,46 @@ "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, @@ -5254,8 +6538,8 @@ "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 4768, - 144 + 3904, + -16 ], "id": "dee83381-1061-405c-978f-33403362f74b", "name": "Code — Preparar actualización imagen recibida" @@ -5444,8 +6728,8 @@ "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ - 4976, - 144 + 4112, + -16 ], "id": "392c7a6c-3ab8-4f56-8742-8ab4ffdd5a4c", "name": "Sheets — Actualizar sesión imagen recibida", @@ -5463,8 +6747,8 @@ "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 5184, - 144 + 4320, + -16 ], "id": "ebc7dadc-6ddc-4806-8c19-7d4e2ce567cf", "name": "Code — Preparar confirmación imagen" @@ -5501,7 +6785,11 @@ "texto": "={{ $json.texto }}", "media_count": "={{ $json.media_count }}", "raw_preview": "={{ $json.raw_preview }}", - "etapa_recibida": "={{ $json.etapa_actual }}" + "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": [ @@ -5648,6 +6936,46 @@ "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, @@ -5658,8 +6986,8 @@ "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ - 4496, - 144 + 3632, + -16 ], "id": "f8cf4436-cf35-45d6-acc7-7adfb9e3a2dc", "name": "Sheets - Guardar evento imagen WhatsApp TEST", @@ -5677,8 +7005,8 @@ "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 4544, - 784 + 3200, + 512 ], "id": "75998ea0-d2ec-4614-b18e-824019627d72", "name": "Code - Preparar aviso falta imagen WhatsApp TEST" @@ -5690,8 +7018,8 @@ "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 3088, - 544 + 3536, + 288 ], "id": "b0e3e960-8cc9-453e-bbf2-4e410ab4a178", "name": "Preparar actualización fotos listas" @@ -5868,8 +7196,8 @@ "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ - 3296, - 544 + 3744, + 288 ], "id": "dea8b556-e019-40b3-97fc-04e1a47c1ed6", "name": "Sheets - Actualizar sesión fotos listas WhatsApp TEST", @@ -5887,8 +7215,8 @@ "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 3504, - 544 + 3952, + 288 ], "id": "50b9bdba-c99b-4150-9a85-e57c18e24f5a", "name": "Code - Preparar solicitud videos WhatsApp TEST" @@ -5900,8 +7228,8 @@ "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 2480, - 944 + 3648, + 1824 ], "id": "08b3a87f-00c6-439b-bcbe-131d86d100d5", "name": "Code - Preparar recordatorio videos WhatsApp TEST" @@ -5913,8 +7241,8 @@ "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 2304, - 704 + 3072, + 1056 ], "id": "c4db0aed-c18e-429c-a6ff-299bd94d2797", "name": "CERRAR_SIN_VIDEO" @@ -6091,8 +7419,8 @@ "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.7, "position": [ - 2512, - 704 + 3280, + 1056 ], "id": "27195f01-98fa-4772-b0c6-d82b8241cc83", "name": "Sheets - Actualizar sesión cierre sin video WhatsApp TEST", @@ -6110,11 +7438,1631 @@ "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ - 2720, - 704 + 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": { @@ -6290,7 +9238,13 @@ "index": 0 } ], - [], + [ + { + "node": "Sheets - Guardar evento video WhatsApp TEST", + "type": "main", + "index": 0 + } + ], [ { "node": "CERRAR_SIN_VIDEO", @@ -6298,7 +9252,13 @@ "index": 0 } ], - [], + [ + { + "node": "Code - Preparar cierre con videos WhatsApp TEST", + "type": "main", + "index": 0 + } + ], [ { "node": "Code - Preparar recordatorio videos WhatsApp TEST", @@ -6306,7 +9266,13 @@ "index": 0 } ], - [], + [ + { + "node": "Code - Preparar aviso procesando WhatsApp TEST", + "type": "main", + "index": 0 + } + ], [] ] }, @@ -6537,6 +9503,11 @@ "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 } ] ] @@ -6551,18 +9522,361 @@ } ] ] + }, + "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 18440aa7", + "name": "Version f3b250eb", "description": "", "autosaved": true, "workflowPublishHistory": [ { - "createdAt": "2026-06-10T02:20:30.933Z", - "id": 1277, + "createdAt": "2026-06-15T13:19:24.505Z", + "id": 1393, "workflowId": "sXH75CXIQ0sEzm1Y", - "versionId": "18440aa7-a3c0-4970-a2f6-b5ad4017bb9d", + "versionId": "f3b250eb-aec9-4861-b8aa-319f56ae5e72", "event": "activated", "userId": "0a88c0b1-928e-4412-896e-c5d1c99b2029" }