up
This commit is contained in:
lizandrogd
2026-01-20 23:29:06 -05:00
parent b5e2af7f47
commit 81708fbb22
9 changed files with 245 additions and 14 deletions
+48
View File
@@ -0,0 +1,48 @@
<?php
/**
* Script de prueba: enviar plantilla a un número y mostrar logs
* Usage: php send_template_test.php
*/
require_once __DIR__ . '/../config/config_enhanced.php';
require_once __DIR__ . '/../config/config.php';
require_once __DIR__ . '/../services/WhatsAppService.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
$recipient = '573168950803';
$template = 'encuesta_satisfaccin';
$initialLang = 'es';
$candidates = [$initialLang, 'es_ES', 'es_MX', 'es_PE'];
echo "=== TEST: Enviar plantilla '$template' a $recipient ===\n";
try {
$wh = new WhatsAppService();
echo "WhatsAppService initialized successfully.\n";
} catch (Exception $e) {
echo "ERROR initializing WhatsAppService: " . $e->getMessage() . "\n";
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
exit(1);
}
foreach ($candidates as $lang) {
echo "Intentando con language = $lang ...\n";
try {
$result = $wh->sendTemplateMessage($recipient, $template, $lang, []);
echo "Resultado OK (language=$lang):\n";
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
exit(0);
} catch (Exception $e) {
echo "FALLÓ (language=$lang): " . $e->getMessage() . "\n";
// Mostrar detalles si es posible
if (isset($e->getTrace()[0]['args'][0])) {
echo "Detalle trace arg0: " . var_export($e->getTrace()[0]['args'][0], true) . "\n";
}
// continuar con siguiente candidato
}
}
echo "Todos los intentos fallaron. Revisa WhatsApp Business Manager para esa plantilla y los idiomas disponibles.\n";
exit(1);
+45
View File
@@ -0,0 +1,45 @@
<?php
/**
* Actualizar token de WhatsApp en la tabla system_config
* Uso: php update_whatsapp_token.php "TOKEN"
*/
require_once __DIR__ . '/../config/config_enhanced.php';
require_once __DIR__ . '/../config/config.php';
if (PHP_SAPI !== 'cli') {
echo "Use CLI: php update_whatsapp_token.php \"TOKEN\"\n";
exit(1);
}
$token = $argv[1] ?? null;
if (!$token) {
echo "Token requerido como parámetro.\n";
exit(1);
}
try {
$db = Database::getInstance();
$stmt = $db->query("INSERT INTO system_config (config_key, config_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE config_value = VALUES(config_value)", ['whatsapp_token', $token]);
echo "Token actualizado en BD (key=whatsapp_token).\n";
} catch (Exception $e) {
echo "Error actualizando token: " . $e->getMessage() . "\n";
exit(1);
}
// Opcional: escribir también en .env para conveniencia (no requerido)
$envFile = dirname(__DIR__) . '/.env';
if (is_writable($envFile)) {
$contents = file_get_contents($envFile);
if (strpos($contents, 'WHATSAPP_TOKEN=') !== false) {
$new = preg_replace('/^WHATSAPP_TOKEN=.*$/m', 'WHATSAPP_TOKEN="' . addcslashes($token, '"') . '"', $contents);
} else {
$new = $contents . "\nWHATSAPP_TOKEN=\"" . addcslashes($token, '"') . "\"\n";
}
file_put_contents($envFile, $new);
echo ".env actualizado con nuevo token (si existe y es escribible).\n";
} else {
echo ".env no escribible o no existe, omitiendo actualización de .env.\n";
}
exit(0);