create_turno: corregir params plantilla (solo {{1}}=código) + fix debug test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-03 10:09:52 -05:00
co-authored by Claude Sonnet 4.6
parent 707ef24572
commit 1a92707e3e
2 changed files with 10 additions and 12 deletions
+8 -11
View File
@@ -109,21 +109,18 @@ if (isset($_GET['test_cel'])) {
$testLang = $cfg['turnero_wa_lang'] ?? 'es_CO'; $testLang = $cfg['turnero_wa_lang'] ?? 'es_CO';
require_once __DIR__ . '/services/WhatsAppService.php'; require_once __DIR__ . '/services/WhatsAppService.php';
// Detectar cuántas variables tiene la plantilla en el body $baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'];
$bodyText = $tplRow['body_text'] ?? ''; $testLink = $baseUrl . '/ver_formulario_enviado.php?token=TEST123';
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';
// Armar params según cuántas variables haya echo "Plantilla: {$testTpl} [{$testLang}]\n";
$bodyParams = array_slice(['Paciente Prueba', 'Consentimiento Informado', 'A001'], 0, max($numVars, 1)); echo "Body: " . ($tplRow['body_text'] ?? '—') . "\n";
echo "Variables detectadas en body: {$numVars} → params enviados: " . implode(', ', $bodyParams) . "\n"; echo "Params: ['A001']\n";
echo "URL: {$testLink}\n\n"; echo "URL botón: {$testLink}\n\n";
require_once __DIR__ . '/services/WhatsAppService.php';
try { try {
$wa = new WhatsAppService('turnero'); $wa = new WhatsAppService('turnero');
$wa->sendTemplateMessage($testCel, $testTpl, $testLang, $bodyParams, [$testLink]); $wa->sendTemplateMessage($testCel, $testTpl, $testLang, ['A001'], [$testLink]);
echo "✅ Mensaje enviado a {$testCel}\n"; echo "✅ Mensaje enviado a {$testCel}\n";
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "❌ Error: " . $e->getMessage() . "\n"; echo "❌ Error: " . $e->getMessage() . "\n";
+2 -1
View File
@@ -183,11 +183,12 @@ try {
$nombreWA = $pacienteNombre ?: 'Paciente'; $nombreWA = $pacienteNombre ?: 'Paciente';
try { try {
$wa = new WhatsAppService('turnero'); $wa = new WhatsAppService('turnero');
// La plantilla solo tiene {{1}} = código de turno en el body + botón URL
$wa->sendTemplateMessage( $wa->sendTemplateMessage(
$cel, $cel,
$waTemplate, $waTemplate,
$waLang, $waLang,
[$nombreWA, $formularioNomWA ?: $codigo, $codigo], [$codigo],
$enlaceConsentimiento ? [$enlaceConsentimiento] : [] $enlaceConsentimiento ? [$enlaceConsentimiento] : []
); );
} catch (\Throwable $eTmpl) { } catch (\Throwable $eTmpl) {