up
This commit is contained in:
+25
-7
@@ -4,7 +4,9 @@
|
||||
* Fecha: 13 de noviembre de 2025
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../config/config.php';
|
||||
|
||||
|
||||
|
||||
// Headers para API
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
@@ -18,12 +20,23 @@ class WhatsAppWebhook {
|
||||
private $botService;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = Database::getInstance();
|
||||
$this->whatsappService = new WhatsAppService();
|
||||
$this->botService = new BotService();
|
||||
error_log('[webhook] __construct start');
|
||||
try {
|
||||
$this->db = Database::getInstance();
|
||||
$this->whatsappService = new WhatsAppService();
|
||||
$this->botService = new BotService();
|
||||
} catch (Throwable $t) {
|
||||
error_log('[webhook] constructor failed: ' . $t->getMessage());
|
||||
if (function_exists('writeLog')) {
|
||||
writeLog('ERROR', 'Webhook constructor failed: ' . $t->getMessage(), ['trace' => $t->getTraceAsString()]);
|
||||
}
|
||||
throw $t;
|
||||
}
|
||||
error_log('[webhook] __construct end');
|
||||
}
|
||||
|
||||
public function handleRequest() {
|
||||
error_log('[webhook] handleRequest start, method=' . ($_SERVER['REQUEST_METHOD'] ?? 'unknown'));
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
if ($method === 'GET') {
|
||||
@@ -251,10 +264,15 @@ if (php_sapi_name() !== 'cli') {
|
||||
try {
|
||||
$webhook = new WhatsAppWebhook();
|
||||
$webhook->handleRequest();
|
||||
} catch (Exception $e) {
|
||||
error_log("Fatal error in webhook: " . $e->getMessage());
|
||||
} catch (Throwable $t) {
|
||||
// Manejar excepciones fatales y errores (Throwable)
|
||||
error_log("Fatal error in webhook: " . $t->getMessage());
|
||||
error_log($t->getTraceAsString());
|
||||
if (function_exists('writeLog')) {
|
||||
writeLog('ERROR', 'Fatal error in webhook: ' . $t->getMessage(), ['trace' => $t->getTraceAsString()]);
|
||||
}
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Error fatal del servidor']);
|
||||
echo json_encode(['error' => 'Error fatal del servidor', 'detail' => $t->getMessage()]);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user