From 1bd799a501f9cddb49d7dcacb7a34aeb9cd58a58 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 3 Jul 2026 17:37:33 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20corregir=20env=C3=ADo=20de=20plantillas?= =?UTF-8?q?=20con=20variables=20nombradas=20en=20chat=20turnero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit El parámetro_name enviado a WhatsApp era el índice numérico ("1") en vez del nombre real de la variable ("name", "fecha", etc.), causando el error #100 Invalid parameter. Ahora se detecta si las variables son nombradas o numéricas y se construye el payload correctamente, igual que conversations.php. Co-Authored-By: Claude Sonnet 4.6 --- modules/turnero/views/chat.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/turnero/views/chat.php b/modules/turnero/views/chat.php index 3f9f5da..cf7e389 100644 --- a/modules/turnero/views/chat.php +++ b/modules/turnero/views/chat.php @@ -1178,7 +1178,7 @@ const nuevoMensaje = (() => { row.className = 'tpl-var-row'; const ph = v.example || v.placeholder || v.label; row.innerHTML = `` + - ``; + ``; varsBody.appendChild(row); }); } @@ -1193,9 +1193,9 @@ const nuevoMensaje = (() => { async function enviar() { if (!_phone || !_tpl) return; const inputs = [...document.querySelectorAll('#nv-vars-body input[data-var-index]')]; - const params = inputs.map(el => ({ name: el.dataset.varIndex, value: el.value.trim() })); - const missing = params.findIndex(p => !p.value); + const missing = inputs.findIndex(el => !el.value.trim()); if (missing !== -1) { inputs[missing].focus(); return; } + const params = _buildParams(inputs); const templateName = _tpl.template_name; const templateLang = _tpl.language_code; @@ -1293,7 +1293,7 @@ async function selectTemplate(tpl) { const label = v.label || ('Variable ' + v.index); const ph = v.example || v.placeholder || label; row.innerHTML = `` + - ``; + ``; varsBody.appendChild(row); }); } @@ -1302,12 +1302,28 @@ async function selectTemplate(tpl) { } } +function _buildParams(inputs) { + const hasNamed = inputs.some(el => { + const n = (el.dataset.varPlaceholder || '').replace(/\{\{|\}\}/g, '').trim(); + return n && !/^\d+$/.test(n); + }); + if (hasNamed) { + const obj = {}; + inputs.forEach(el => { + const n = (el.dataset.varPlaceholder || '').replace(/\{\{|\}\}/g, '').trim() || el.dataset.varIndex; + obj[n] = el.value.trim(); + }); + return obj; + } + return inputs.map(el => el.value.trim()); +} + async function sendTemplate() { if (!_tplSelected || !state.activeUserId) return; const inputs = [...document.querySelectorAll('#tpl-vars-body input[data-var-index]')]; - const params = inputs.map(el => ({ name: el.dataset.varIndex, value: el.value.trim() })); - const missing = params.findIndex(p => !p.value); + const missing = inputs.findIndex(el => !el.value.trim()); if (missing !== -1) { inputs[missing].focus(); return; } + const params = _buildParams(inputs); const templateName = _tplSelected.template_name; const templateLang = _tplSelected.language_code;