debug_turno_wa: corregir tabla system_config para token/phone WA
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
f09b7d42fd
commit
eddfe4d16c
+24
-11
@@ -17,12 +17,19 @@ echo "════════════════════════
|
||||
// ── 1. Config WA turnero ──────────────────────────────────────
|
||||
echo "1. CONFIGURACIÓN WHATSAPP\n";
|
||||
echo "─────────────────────────\n";
|
||||
$cfgKeys = ['whatsapp_token','whatsapp_phone_number_id','whatsapp_phone_number_id_turnero',
|
||||
'turnero_wa_template','turnero_wa_lang','turnero_wa_kiosko_enabled'];
|
||||
$cfg = $pdo->query(
|
||||
"SELECT clave, valor FROM lab_config WHERE clave IN ('" . implode("','", $cfgKeys) . "')"
|
||||
// Token y phone IDs viven en system_config; resto en lab_config
|
||||
$sysCfg = $pdo->query(
|
||||
"SELECT config_key AS k, config_value AS v FROM system_config
|
||||
WHERE config_key IN ('whatsapp_token','whatsapp_phone_number_id','whatsapp_phone_number_id_turnero')"
|
||||
)->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||
|
||||
$labCfg = $pdo->query(
|
||||
"SELECT clave AS k, valor AS v FROM lab_config
|
||||
WHERE clave IN ('turnero_wa_template','turnero_wa_lang','turnero_wa_kiosko_enabled')"
|
||||
)->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||
|
||||
$cfg = array_merge($sysCfg, $labCfg);
|
||||
|
||||
$tokenLen = strlen($cfg['whatsapp_token'] ?? '');
|
||||
echo "Token WA: " . ($tokenLen > 0 ? "✅ presente ({$tokenLen} chars)" : "❌ VACÍO") . "\n";
|
||||
echo "Phone ID principal: " . ($cfg['whatsapp_phone_number_id'] ?? '❌ no configurado') . "\n";
|
||||
@@ -102,15 +109,21 @@ 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';
|
||||
|
||||
// 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";
|
||||
|
||||
try {
|
||||
$wa = new WhatsAppService('turnero');
|
||||
$wa->sendTemplateMessage(
|
||||
$testCel,
|
||||
$testTpl,
|
||||
$testLang,
|
||||
['Paciente Prueba', 'Consentimiento Informado', 'A001'],
|
||||
[($_SERVER['HTTPS'] ?? '') === 'on' ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . '/ver_formulario_enviado.php?token=TEST']
|
||||
);
|
||||
$wa->sendTemplateMessage($testCel, $testTpl, $testLang, $bodyParams, [$testLink]);
|
||||
echo "✅ Mensaje enviado a {$testCel}\n";
|
||||
} catch (\Throwable $e) {
|
||||
echo "❌ Error: " . $e->getMessage() . "\n";
|
||||
|
||||
Reference in New Issue
Block a user