From 3d6147bf0db3205dd5aa94b152d62b1e707c56fe Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 3 Jul 2026 15:04:31 -0500 Subject: [PATCH] fix(template): send parameter_name for named-variable templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WhatsApp API returns "(#100) Invalid parameter — Parameter name is missing or empty" for templates that use named variables. - chat.php sendTemplate(): collect params as [{name, value}] objects using data-var-index as the parameter name - WhatsAppService::sendTemplateMessage(): handle {name, value} objects in the indexed-array path by emitting {type, parameter_name, text} (backward-compatible — plain strings still work as positional params) Co-Authored-By: Claude Sonnet 4.6 --- modules/turnero/views/chat.php | 4 ++-- services/WhatsAppService.php | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/turnero/views/chat.php b/modules/turnero/views/chat.php index 219a5d5..2bb791f 100644 --- a/modules/turnero/views/chat.php +++ b/modules/turnero/views/chat.php @@ -998,8 +998,8 @@ async function selectTemplate(tpl) { async function sendTemplate() { if (!_tplSelected || !state.activeUserId) return; const inputs = [...document.querySelectorAll('#tpl-vars-body input[data-var-index]')]; - const params = inputs.map(el => el.value.trim()); - const missing = params.findIndex(p => !p); + const params = inputs.map(el => ({ name: el.dataset.varIndex, value: el.value.trim() })); + const missing = params.findIndex(p => !p.value); if (missing !== -1) { inputs[missing].focus(); return; } const templateName = _tplSelected.template_name; diff --git a/services/WhatsAppService.php b/services/WhatsAppService.php index a15a683..d21e805 100644 --- a/services/WhatsAppService.php +++ b/services/WhatsAppService.php @@ -181,6 +181,13 @@ class WhatsAppService $bpCopy = $bp; unset($bpCopy['name']); $normalizedBody[] = $bpCopy; // already detailed + } elseif (is_array($bp) && isset($bp['name'], $bp['value'])) { + // {name: 'param_name', value: 'text'} — include parameter_name for named-variable templates + $normalizedBody[] = [ + 'type' => 'text', + 'parameter_name' => (string)$bp['name'], + 'text' => (string)$bp['value'], + ]; } elseif (is_string($bp) || is_numeric($bp)) { $normalizedBody[] = [ 'type' => 'text',