]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Токен для прода
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 20 Jan 2025 20:03:32 +0000 (23:03 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 20 Jan 2025 20:03:32 +0000 (23:03 +0300)
erp24/services/TelegramService.php

index 94592ef5a6e09651e68c71dda87f3483937a620f..457099cf394d7cb09cba67e3e3a8f1363b8042e3 100644 (file)
@@ -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();