diff --git a/debug_turno_wa.php b/debug_turno_wa.php index 4ca04bd..51cf082 100644 --- a/debug_turno_wa.php +++ b/debug_turno_wa.php @@ -191,7 +191,18 @@ if (isset($_GET['test_cel'])) { require_once __DIR__ . '/services/WhatsAppService.php'; try { $wa = new WhatsAppService('turnero'); - $wa->sendTemplateMessage($testCel, $testTpl, $testLang, ['A001'], [$testLink]); + $rawComps = [ + ['type' => 'body', 'parameters' => [['type' => 'text', 'text' => 'A001']]] + ]; + if ($testLink) { + $rawComps[] = [ + 'type' => 'button', + 'sub_type' => 'url', + 'index' => '0', + 'parameters' => [['type' => 'text', 'text' => $testLink]], + ]; + } + $wa->sendTemplateMessage($testCel, $testTpl, $testLang, [], [], $rawComps); 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 30f505a..6e51279 100644 --- a/modules/turnero/api/create_turno.php +++ b/modules/turnero/api/create_turno.php @@ -184,13 +184,18 @@ try { $nombreWA = $pacienteNombre ?: 'Paciente'; try { $wa = new WhatsAppService('turnero'); - $wa->sendTemplateMessage( - $cel, - $waTemplate, - $waLang, - [$codigo], - $enlaceConsentimiento ? [$enlaceConsentimiento] : [] - ); + $rawComps = [ + ['type' => 'body', 'parameters' => [['type' => 'text', 'text' => $codigo]]] + ]; + if ($enlaceConsentimiento) { + $rawComps[] = [ + 'type' => 'button', + 'sub_type' => 'url', + 'index' => '0', + 'parameters' => [['type' => 'text', 'text' => $enlaceConsentimiento]], + ]; + } + $wa->sendTemplateMessage($cel, $waTemplate, $waLang, [], [], $rawComps); } catch (\Throwable $eTmpl) { try { $msg = "Hola {$nombreWA}, su turno *{$codigo}* ha sido registrado.";