Files
nabeh/backend/public/debug-chatbot.php
2026-05-22 00:31:48 +03:00

46 lines
1.5 KiB
PHP

<?php
require_once dirname(__DIR__) . '/app/bootstrap.php';
header('Content-Type: application/json');
$rules = \App\Core\Database::select("SELECT * FROM chatbot_rules");
foreach ($rules as &$rule) {
if (!empty($rule['gemini_api_key'])) {
$rule['gemini_api_key_set'] = true;
unset($rule['gemini_api_key']);
} else {
$rule['gemini_api_key_set'] = false;
}
}
$logs = \App\Core\Database::select("SELECT * FROM messages_log ORDER BY id DESC LIMIT 20");
$sessions = \App\Core\Database::select("SELECT * FROM whatsapp_sessions");
// Check Node.js gateway status from the PHP environment
$gatewayUrl = rtrim(getenv('WHATSAPP_GATEWAY_URL') ?: 'http://localhost:3722', '/');
$ch = curl_init($gatewayUrl . '/health');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$healthResponse = curl_exec($ch);
$healthHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$healthError = curl_error($ch);
curl_close($ch);
echo json_encode([
'env' => [
'WHATSAPP_GATEWAY_URL' => getenv('WHATSAPP_GATEWAY_URL'),
'WEBHOOK_SECRET_SET' => !empty(getenv('WEBHOOK_SECRET')),
'APP_URL' => getenv('APP_URL')
],
'gateway_health' => [
'url' => $gatewayUrl . '/health',
'http_code' => $healthHttpCode,
'response' => json_decode($healthResponse, true) ?: $healthResponse,
'error' => $healthError
],
'chatbot_rules' => $rules,
'messages_log' => $logs,
'whatsapp_sessions' => $sessions
], JSON_PRETTY_PRINT);