send_consentimiento: read wa template from lab_config instead of hardcoding

Was sending 'consentimiento_turno' (plain text fallback) while the
configured template is 'consentimiento_turno_v2'. Now reads
turnero_wa_template and turnero_wa_lang from lab_config, matching
the same logic used in create_turno.php (kiosk).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-21 17:18:24 -05:00
co-authored by Claude Sonnet 4.6
parent 26bb9e1844
commit 7a08e63e44
+11 -2
View File
@@ -84,6 +84,15 @@ function generarUuid(): string
);
}
// ── Leer config de WhatsApp (igual que create_turno.php) ─────
$stmtCfg = $pdo->prepare(
"SELECT clave, valor FROM lab_config WHERE clave IN ('turnero_wa_template','turnero_wa_lang')"
);
$stmtCfg->execute();
$cfgWA = $stmtCfg->fetchAll(PDO::FETCH_KEY_PAIR);
$waTemplateName = $cfgWA['turnero_wa_template'] ?? 'consentimiento_turno';
$waLangFallback = $cfgWA['turnero_wa_lang'] ?? 'es';
$pdo->beginTransaction();
$consentimientosResultado = [];
$erroresEnvio = [];
@@ -105,10 +114,10 @@ try {
$wa = new WhatsAppService('turnero');
$waMeta = ['canal' => 'turnero'];
$waTemplate = 'consentimiento_turno';
$waTemplate = $waTemplateName;
$stmtLang = $pdo->prepare("SELECT language_code FROM message_templates WHERE template_name = ? LIMIT 1");
$stmtLang->execute([$waTemplate]);
$waLang = $stmtLang->fetchColumn() ?: 'es';
$waLang = $stmtLang->fetchColumn() ?: $waLangFallback;
$baseUrl = defined('BASE_URL') ? rtrim(BASE_URL, '/') : (
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http')