From ad87a8805f1a24421120fb87b20e53035dc7c1eb Mon Sep 17 00:00:00 2001 From: fomichev Date: Mon, 20 Jan 2025 23:03:32 +0300 Subject: [PATCH] =?utf8?q?=D0=A2=D0=BE=D0=BA=D0=B5=D0=BD=20=D0=B4=D0=BB?= =?utf8?q?=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/TelegramService.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/erp24/services/TelegramService.php b/erp24/services/TelegramService.php index 94592ef5..457099cf 100644 --- a/erp24/services/TelegramService.php +++ b/erp24/services/TelegramService.php @@ -10,8 +10,8 @@ class TelegramService { - const TELEGRAM_API_URL = "8063257458:AAGnMf4cxwJWlYLF1wS_arn4PrOaLs9ERQQ"; - + const TELEGRAM_BOT_DEV = "8063257458:AAGnMf4cxwJWlYLF1wS_arn4PrOaLs9ERQQ"; + const TELEGRAM_BOT_PROD = "5456741805:AAG7xOSiYDwUdV5NMb2v9vh8CWzEczDP4yU"; const TARGET_PROD_URL = "erp.erp-flowers.ru"; const CHAT_CHANNEL_ID = "-1001861631125"; const CHAT_CHANNEL_ERP_ID = "-1002338329426"; @@ -26,21 +26,21 @@ class TelegramService return $client->request('GET', $url); } - public static function isDevelopmentEnvironment($urlString = null) : bool - { - try { + public static function isDevelopmentEnvironment($urlString = null): bool + { + try { $ip = Yii::$app->request->getHostInfo(); - } catch (\Exception $exception) { + } catch (\Exception $exception) { $ip = 'console'; - } + } $currentUrl = empty($urlString) ? $ip : $urlString; return !str_contains($currentUrl, self::TARGET_PROD_URL); - } + } public static function sendErrorToTelegramMessage($message, $disableNotification, $isDev) { - $botToken = self::TELEGRAM_API_URL; + $botToken = self::TELEGRAM_BOT_DEV; $chatIdDefault = self::CHAT_CHANNEL_ID; $chatIdErp = self::CHAT_CHANNEL_ERP_ID; $apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage"; @@ -69,7 +69,12 @@ class TelegramService public static function sendMessageToTelegramClient($chatId, $message) { - $botToken = self::TELEGRAM_API_URL; // Токен вашего Telegram-бота + if (self::isDevelopmentEnvironment()) { + $botToken = self::TELEGRAM_BOT_DEV; + } else { + $botToken = self::TELEGRAM_BOT_PROD; + } + $apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage"; $client = new Client(); -- 2.39.5