fix: mensajes automáticos del turnero registrados en canal principal

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 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-03 17:42:39 -05:00
co-authored by Claude Sonnet 4.6
parent 1bd799a501
commit e88fb4cc86
2 changed files with 7 additions and 5 deletions
+3 -2
View File
@@ -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
}
+4 -3
View File
@@ -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();