]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Merge branch 'refs/heads/feature_fomichev_erp-255_send_tg_message_to_customer' into...
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 10 Jan 2025 09:49:40 +0000 (12:49 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 10 Jan 2025 09:49:40 +0000 (12:49 +0300)
# Conflicts:
# erp24/services/TelegramService.php

1  2 
erp24/config/console.php
erp24/config/web.php
erp24/services/TelegramService.php

Simple merge
Simple merge
index de682c97ffaf9cbbae89c1d68c7b429352a214b0,95ac43da67e4a3ef5ef723220d3f5c32ce980285..321b688747bbab92f62b515be67b4cff1b554c03
@@@ -4,9 -4,9 +4,10 @@@ namespace yii_app\services
  
  use GuzzleHttp\Client;
  use Yii;
 +use yii_app\records\UsersTelegramMessage;
  
- class TelegramService {
+ class TelegramService
+ {
  
  
      const TELEGRAM_API_URL = "8063257458:AAGnMf4cxwJWlYLF1wS_arn4PrOaLs9ERQQ";
          return $client->request('GET', $url);
      }
  
 -    public static function isDevelopmentEnvironment($urlString = null): bool
 -    {
 -        $currentUrl = empty($urlString) ? Yii::$app->request->getHostInfo() : $urlString;
 -        return !str_contains($currentUrl, self::TARGET_PROD_URL);
 -    }
 +     public static function isDevelopmentEnvironment($urlString = null) : bool
 +     {
 +         try {
 +             $ip = Yii::$app->request->getHostInfo();
 +         } 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;
-     $chatIdDefault = self::CHAT_CHANNEL_ID;
-     $chatIdErp = self::CHAT_CHANNEL_ERP_ID;
-     $apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage";
    public static function sendErrorToTelegramMessage($message, $disableNotification, $isDev)
    {
+         $botToken = self::TELEGRAM_API_URL;
+         $chatIdDefault = self::CHAT_CHANNEL_ID;
+         $chatIdErp = self::CHAT_CHANNEL_ERP_ID;
+         $apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage";
  
  
-     if ($isDev) {
-         $chatId = $chatIdDefault;
-     } else  {
-         $chatId = $chatIdErp;
+         if ($isDev) {
+             $chatId = $chatIdDefault;
+         } else {
+             $chatId = $chatIdErp;
+         }
+         $client = new Client();
+         try {
+             $client->post($apiURL, [
+                 'json' => [
+                     'chat_id' => $chatId,
+                     'text' => $message,
+                     'parse_mode' => 'MarkdownV2',
+                     'disable_notification' => $disableNotification,
+                 ],
+             ]);
+         } catch (\Exception $e) {
+             Yii::error("Ошибка отправки сообщения в Telegram: " . $e->getMessage(), 'telegram');
+         }
      }
  
-     $client = new Client();
-     try {
-         $client->post($apiURL, [
-             'json' => [
-                 'chat_id' => $chatId,
-                 'text' => $message,
-                 'parse_mode' => 'MarkdownV2',
-                 'disable_notification' => $disableNotification,
-             ],
-         ]);
-     } catch (\Exception $e) {
-         Yii::error("Ошибка отправки сообщения в Telegram: " . $e->getMessage(), 'telegram');
+     public static function sendMessageToTelegramClient($chatId, $message)
+     {
+         $botToken = self::TELEGRAM_API_URL; // Токен вашего Telegram-бота
+         $apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage";
+         $client = new Client();
+         try {
+             $response = $client->post($apiURL, [
+                 'json' => [
+                     'chat_id' => $chatId,
+                     'text' => $message,
+                     'parse_mode' => 'MarkdownV2',
+                 ],
+             ]);
+             if ($response->getStatusCode() !== 200) {
+                 Yii::error("Ошибка при отправке сообщения в Telegram. Код ответа: "
+                     . $response->getStatusCode(), 'telegram');
+                 return $response->getStatusCode();
+             }
+             return $response->getReasonPhrase();
+         } catch (\Exception $e) {
+             Yii::error("Ошибка отправки сообщения в Telegram: " . $e->getMessage(), 'telegram');
+             return $e->getMessage();
+         }
      }
- }
  
  
      // Метод для экранирования символов MarkdownV2 для файла