From 1a92707e3e3ad8e3770a67b7b1211de55148c5b4 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 3 Jul 2026 10:09:52 -0500 Subject: [PATCH] =?UTF-8?q?create=5Fturno:=20corregir=20params=20plantilla?= =?UTF-8?q?=20(solo=20{{1}}=3Dc=C3=B3digo)=20+=20fix=20debug=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- debug_turno_wa.php | 19 ++++++++----------- modules/turnero/api/create_turno.php | 3 ++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/debug_turno_wa.php b/debug_turno_wa.php index 192c2c6..f31b936 100644 --- a/debug_turno_wa.php +++ b/debug_turno_wa.php @@ -109,21 +109,18 @@ if (isset($_GET['test_cel'])) { $testLang = $cfg['turnero_wa_lang'] ?? 'es_CO'; require_once __DIR__ . '/services/WhatsAppService.php'; - // Detectar cuántas variables tiene la plantilla en el body - $bodyText = $tplRow['body_text'] ?? ''; - preg_match_all('/\{\{(\d+)\}\}/', $bodyText, $m); - $numVars = count(array_unique($m[1] ?? [])); - $baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; - $testLink = $baseUrl . '/ver_formulario_enviado.php?token=TEST123'; + $baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; + $testLink = $baseUrl . '/ver_formulario_enviado.php?token=TEST123'; - // Armar params según cuántas variables haya - $bodyParams = array_slice(['Paciente Prueba', 'Consentimiento Informado', 'A001'], 0, max($numVars, 1)); - echo "Variables detectadas en body: {$numVars} → params enviados: " . implode(', ', $bodyParams) . "\n"; - echo "URL: {$testLink}\n\n"; + echo "Plantilla: {$testTpl} [{$testLang}]\n"; + echo "Body: " . ($tplRow['body_text'] ?? '—') . "\n"; + echo "Params: ['A001']\n"; + echo "URL botón: {$testLink}\n\n"; + require_once __DIR__ . '/services/WhatsAppService.php'; try { $wa = new WhatsAppService('turnero'); - $wa->sendTemplateMessage($testCel, $testTpl, $testLang, $bodyParams, [$testLink]); + $wa->sendTemplateMessage($testCel, $testTpl, $testLang, ['A001'], [$testLink]); echo "✅ Mensaje enviado a {$testCel}\n"; } catch (\Throwable $e) { echo "❌ Error: " . $e->getMessage() . "\n"; diff --git a/modules/turnero/api/create_turno.php b/modules/turnero/api/create_turno.php index 0708999..ad1a0ba 100644 --- a/modules/turnero/api/create_turno.php +++ b/modules/turnero/api/create_turno.php @@ -183,11 +183,12 @@ try { $nombreWA = $pacienteNombre ?: 'Paciente'; try { $wa = new WhatsAppService('turnero'); + // La plantilla solo tiene {{1}} = código de turno en el body + botón URL $wa->sendTemplateMessage( $cel, $waTemplate, $waLang, - [$nombreWA, $formularioNomWA ?: $codigo, $codigo], + [$codigo], $enlaceConsentimiento ? [$enlaceConsentimiento] : [] ); } catch (\Throwable $eTmpl) {