From e88fb4cc861e52bb1e9b63ebeaed7672dcb089fa Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 3 Jul 2026 17:42:39 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20mensajes=20autom=C3=A1ticos=20del=20turn?= =?UTF-8?q?ero=20registrados=20en=20canal=20principal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit create_turno.php y send_consentimiento.php enviaban por WhatsAppService('turnero') (nĂºmero correcto) pero sin pasar meta canal='turnero', por lo que saveOutgoingMessage defaulteaba a canal='bot' y quedaban registrados en las conversaciones del principal. Agregado $waMeta = ['canal'=>'turnero'] en ambos archivos para sendTemplateMessage y sendTextMessage (fallback). Co-Authored-By: Claude Sonnet 4.6 --- modules/turnero/api/create_turno.php | 5 +++-- modules/turnero/api/send_consentimiento.php | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/turnero/api/create_turno.php b/modules/turnero/api/create_turno.php index a55ebc2..1d2fb7d 100644 --- a/modules/turnero/api/create_turno.php +++ b/modules/turnero/api/create_turno.php @@ -183,6 +183,7 @@ try { require_once __DIR__ . '/../../../services/WhatsAppService.php'; $nombreWA = $pacienteNombre ?: 'Paciente'; + $waMeta = ['canal' => 'turnero']; try { $wa = new WhatsAppService('turnero'); $rawComps = [ @@ -196,14 +197,14 @@ try { 'parameters' => [['type' => 'text', 'text' => $conToken]], ]; } - $wa->sendTemplateMessage($cel, $waTemplate, $waLang, [], [], $rawComps); + $wa->sendTemplateMessage($cel, $waTemplate, $waLang, [], [], $rawComps, $waMeta); } catch (\Throwable $eTmpl) { try { $msg = "Hola {$nombreWA}, su turno *{$codigo}* ha sido registrado."; if ($enlaceConsentimiento) { $msg .= "\n\nPor favor firme su consentimiento informado antes de ser atendido:\n{$enlaceConsentimiento}"; } - $wa->sendTextMessage($cel, $msg); + $wa->sendTextMessage($cel, $msg, $waMeta); } catch (\Throwable $eTxt) { // Silenciar } diff --git a/modules/turnero/api/send_consentimiento.php b/modules/turnero/api/send_consentimiento.php index c0ac5d0..96ba9cb 100644 --- a/modules/turnero/api/send_consentimiento.php +++ b/modules/turnero/api/send_consentimiento.php @@ -103,7 +103,8 @@ try { WHERE id = ?" ); - $wa = new WhatsAppService('turnero'); + $wa = new WhatsAppService('turnero'); + $waMeta = ['canal' => 'turnero']; $waTemplate = 'consentimiento_turno'; $stmtLang = $pdo->prepare("SELECT language_code FROM message_templates WHERE template_name = ? LIMIT 1"); $stmtLang->execute([$waTemplate]); @@ -153,13 +154,13 @@ try { ['type' => 'button', 'sub_type' => 'url', 'index' => '0', 'parameters' => [['type' => 'text', 'text' => $token]]], ]; - $wa->sendTemplateMessage($celular, $waTemplate, $waLang, [], [], $rawComps); + $wa->sendTemplateMessage($celular, $waTemplate, $waLang, [], [], $rawComps, $waMeta); $enviado = true; } catch (\Throwable $eTemplate) { // Fallback texto plano try { $mensajeTexto = "Hola {$nombrePac}, su turno *{$turno['codigo']}* requiere firma de consentimiento:\n{$enlaceFirma}"; - $wa->sendTextMessage($celular, $mensajeTexto); + $wa->sendTextMessage($celular, $mensajeTexto, $waMeta); $enviado = true; } catch (\Throwable $eTexto) { $erroresEnvio[] = "Formulario '{$formularioNom}': " . $eTexto->getMessage();