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';
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";
+2 -1
View File
@@ -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) {