From: Aleksey Filippov Date: Thu, 29 Jan 2026 08:04:28 +0000 (+0300) Subject: fix diagnostic X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=030becd8a5e40bb24bafff6bd29e8e29a8f2f29e;p=erp24_rep%2Fyii-erp24%2F.git fix diagnostic --- diff --git a/erp24/controllers/DiagnosticController.php b/erp24/controllers/DiagnosticController.php index 0e5e6f59..644f028f 100644 --- a/erp24/controllers/DiagnosticController.php +++ b/erp24/controllers/DiagnosticController.php @@ -273,6 +273,69 @@ class DiagnosticController extends Controller } } + /** + * Тестирование Telegram бота (продакшн) + */ + public function actionTestTelegramProd(): Response + { + Yii::$app->response->format = Response::FORMAT_JSON; + + $token = getenv('TELEGRAM_BOT_TOKEN_PROD') ?: ''; + + if (empty($token)) { + return $this->asJson([ + 'success' => false, + 'message' => 'TELEGRAM_BOT_TOKEN_PROD не настроен', + 'hint' => 'Установите TELEGRAM_BOT_TOKEN_PROD в .env файле', + ]); + } + + if (strpos($token, '000000000') === 0) { + return $this->asJson([ + 'success' => false, + 'message' => 'TELEGRAM_BOT_TOKEN_PROD содержит placeholder значение', + 'hint' => 'Замените placeholder на реальный токен бота', + ]); + } + + try { + $client = new Client(['timeout' => 10]); + $url = "https://api.telegram.org/bot{$token}/getMe"; + + $startTime = microtime(true); + $response = $client->get($url); + $duration = round((microtime(true) - $startTime) * 1000, 2); + + $data = json_decode($response->getBody()->getContents(), true); + + if ($data['ok'] ?? false) { + return $this->asJson([ + 'success' => true, + 'message' => 'Telegram Prod бот подключен успешно', + 'data' => [ + 'bot_id' => $data['result']['id'] ?? 'N/A', + 'bot_name' => $data['result']['first_name'] ?? 'N/A', + 'bot_username' => '@' . ($data['result']['username'] ?? 'N/A'), + 'can_read_messages' => $data['result']['can_read_all_group_messages'] ?? false, + 'duration_ms' => $duration, + ], + ]); + } + + return $this->asJson([ + 'success' => false, + 'message' => 'Telegram Prod API вернул ошибку', + 'error' => $data['description'] ?? 'Unknown error', + ]); + } catch (GuzzleException $e) { + return $this->asJson([ + 'success' => false, + 'message' => 'Ошибка подключения к Telegram Prod API', + 'error' => $e->getMessage(), + ]); + } + } + /** * Тестирование Telegram Salebot бота */ @@ -352,9 +415,11 @@ class DiagnosticController extends Controller ]); } - $token = $botType === 'salebot' - ? getenv('TELEGRAM_BOT_TOKEN_SALEBOT') - : getenv('TELEGRAM_BOT_TOKEN'); + $token = match ($botType) { + 'prod' => getenv('TELEGRAM_BOT_TOKEN_PROD'), + 'salebot' => getenv('TELEGRAM_BOT_TOKEN_SALEBOT'), + default => getenv('TELEGRAM_BOT_TOKEN'), + }; if (empty($token) || strpos($token, '000000000') === 0) { return $this->asJson([ @@ -370,7 +435,11 @@ class DiagnosticController extends Controller $message = "🔧 *Тестовое сообщение ERP24*\n\n" . "Время: " . date('Y-m-d H:i:s') . "\n" . "Сервер: " . gethostname() . "\n" - . "Бот: " . ($botType === 'salebot' ? 'Salebot' : 'Main') . "\n" + . "Бот: " . match ($botType) { + 'prod' => 'Prod', + 'salebot' => 'Salebot', + default => 'Dev', + } . "\n" . "Пользователь: " . (Yii::$app->user->identity->name ?? 'N/A'); $response = $client->post($url, [ @@ -479,9 +548,13 @@ class DiagnosticController extends Controller $rabbitResult = $this->actionTestRabbitmq(); $results['rabbitmq'] = json_decode($rabbitResult->content, true); - // Telegram Main + // Telegram Dev $telegramResult = $this->actionTestTelegram(); - $results['telegram_main'] = json_decode($telegramResult->content, true); + $results['telegram_dev'] = json_decode($telegramResult->content, true); + + // Telegram Prod + $telegramProdResult = $this->actionTestTelegramProd(); + $results['telegram_prod'] = json_decode($telegramProdResult->content, true); // Telegram Salebot $salebotResult = $this->actionTestTelegramSalebot(); @@ -497,7 +570,7 @@ class DiagnosticController extends Controller // Summary $successCount = 0; $failCount = 0; - foreach (['postgresql', 'db_remote', 'rabbitmq', 'telegram_main', 'telegram_salebot', 'queue'] as $key) { + foreach (['postgresql', 'db_remote', 'rabbitmq', 'telegram_dev', 'telegram_prod', 'telegram_salebot', 'queue'] as $key) { if ($results[$key]['success'] ?? false) { $successCount++; } else { @@ -536,7 +609,12 @@ class DiagnosticController extends Controller 'POSTGRES_SCHEMA' => 'Схема PostgreSQL', 'POSTGRES_USER' => 'Пользователь PostgreSQL', 'RABBIT_HOST' => 'Хост RabbitMQ', + 'TELEGRAM_BOT_TOKEN_PROD' => 'Токен Telegram (Prod)', 'TELEGRAM_BOT_TOKEN_SALEBOT' => 'Токен Salebot', + 'TELEGRAM_CHAT_CHANNEL_ID' => 'ID основного канала', + 'TELEGRAM_CHAT_CHANNEL_ERP_ID' => 'ID ERP канала', + 'TELEGRAM_ORDER_CONTROL_CHAT_ID_DEV' => 'ID канала контроля заказов (Dev)', + 'TELEGRAM_ORDER_CONTROL_CHAT_ID_PROD' => 'ID канала контроля заказов (Prod)', 'DB_REMOTE_HOST' => 'Хост внешней БД', 'DB_REMOTE_PORT' => 'Порт внешней БД', 'DB_REMOTE_SCHEMA' => 'Схема внешней БД', @@ -609,9 +687,13 @@ class DiagnosticController extends Controller 'configured' => !empty(getenv('RABBIT_USER')) && !empty(getenv('RABBIT_PASSWORD')), ], 'telegram' => [ - 'name' => 'Telegram Bot (основной)', + 'name' => 'Telegram Bot (Dev)', 'configured' => !empty(getenv('TELEGRAM_BOT_TOKEN')) && strpos(getenv('TELEGRAM_BOT_TOKEN'), '000000000') !== 0, ], + 'telegram_prod' => [ + 'name' => 'Telegram Bot (Prod)', + 'configured' => !empty(getenv('TELEGRAM_BOT_TOKEN_PROD')) && strpos(getenv('TELEGRAM_BOT_TOKEN_PROD'), '000000000') !== 0, + ], 'telegram_salebot' => [ 'name' => 'Telegram Bot (Salebot)', 'configured' => !empty(getenv('TELEGRAM_BOT_TOKEN_SALEBOT')) && strpos(getenv('TELEGRAM_BOT_TOKEN_SALEBOT'), '000000000') !== 0, diff --git a/erp24/views/diagnostic/index.php b/erp24/views/diagnostic/index.php index c79ad0f4..d94f4b77 100644 --- a/erp24/views/diagnostic/index.php +++ b/erp24/views/diagnostic/index.php @@ -499,11 +499,11 @@ $this->params['breadcrumbs'][] = $this->title;

📱 Telegram боты

- +
-
📱
+
🔧
-
Telegram Bot (основной)
+
Telegram Bot (Dev)
Сконфигурирован @@ -520,6 +520,27 @@ $this->params['breadcrumbs'][] = $this->title;
+ +
+
📱
+
+
Telegram Bot (Prod)
+
+ + Сконфигурирован + + Не настроен + +
+
+
+ +
+
+
+
🤖
@@ -549,8 +570,9 @@ $this->params['breadcrumbs'][] = $this->title;