]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[BC-278] Отправка сообщения в Телеграм
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Fri, 4 Jul 2025 16:41:18 +0000 (19:41 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Fri, 4 Jul 2025 16:41:18 +0000 (19:41 +0300)
erp24/jobs/SendTelegramPromoMessageJob.php
erp24/services/TelegramService.php

index 67331bea4c830073bda60f81f56c2c123d76cf8d..7177eb53eb6914657f1bb98cee1617f3b81a5227 100644 (file)
@@ -39,12 +39,9 @@ class SendTelegramPromoMessageJob extends \yii\base\BaseObject implements JobInt
 
             if ($result == "OK") {
                 try {
-//                    $result = TelegramService::saveSentMessageToDB($this->messageData);
-                    //TODO - перенос сюда обновления статусов записей когорт
-                    if ($result) {
+
+                    if (1) {
                         Yii::warning("Сообщение успешно сохранено для пользователя с ID {$chatId} телефон {$phone}", 'telegram');
-                    } else {
-                        Yii::warning("Сообщение не удалось сохранить для пользователя с ID {$chatId} телефон {$phone}", 'telegram');
                     }
 
                 } catch (\Exception $e) {
index 9058136e04617db179c411c48f62b2fcad2331a1..1eb4afd43793dc2ad4df5c74f8fd6b0bf9c1cd52 100644 (file)
@@ -203,23 +203,11 @@ class TelegramService
         
 Только 7 дней: Скидка 20% на три стильных букета из нашей летней коллекции!';
 
-        $pic1Path = curl_file_create(
-        __DIR__ . '/../web/images/pic_1.jpg',
-        'image/jpg',
-        'pic_1.jpg'
-        );
+        $pic1Path =__DIR__ . '/../web/images/pic_1.jpg';
 
-        $pic2Path = curl_file_create(
-        __DIR__ . '/../web/images/pic_2.jpg',
-        'image/jpg',
-        'pic_2.jpg'
-        );
+        $pic2Path = __DIR__ . '/../web/images/pic_2.jpg';
 
-        $pic3Path = curl_file_create(
-        __DIR__ . '/../web/images/pic_3.jpg',
-        'image/jpg',
-        'pic_3.jpg'
-        );
+        $pic3Path = __DIR__ . '/../web/images/pic_3.jpg';
 
         $result = 'false';
 
@@ -228,19 +216,47 @@ class TelegramService
                 $buttons = self::getTgShortButtons($chatId);
 
                 $client = new Client();
+
+                $media = [
+                    [
+                        'type' => 'photo',
+                        'media' => 'attach://pic_1.jpg',
+                        'caption' => $text,
+                    ],
+                    [
+                        'type' => 'photo',
+                        'media' => 'attach://pic_2.jpg',
+                    ],
+                    [
+                        'type' => 'photo',
+                        'media' => 'attach://pic_3.jpg',
+                    ]
+                ];
+
                 try {
-                    $response1 = $client->post($apiURL1, [
-                        'json' => [
-                            'chat_id' => $chatId,
-                            'media' => json_encode([
-                                ['type' => 'photo', 'media' => 'attach://pic_1.jpg', "caption" => $text],
-                                ['type' => 'photo', 'media' => 'attach://pic_2.jpg' ],
-                                ['type' => 'photo', 'media' => 'attach://pic_3.jpg' ],
-                            ]),
-                            'pic_1.jpg' => $pic1Path,
-                            'pic_2.jpg' => $pic2Path,
-                            'pic_3.jpg' => $pic3Path,
-                        ],
+                    $response1 = $client->post($apiURL1,[
+                        'multipart' => [
+                            [
+                                'name' => 'chat_id',
+                                'contents' => $chatId
+                            ],
+                            [
+                                'name' => 'media',
+                                'contents' => json_encode($media)
+                            ],
+                            [
+                                'name' => 'pic_1.jpg',
+                                'contents' => fopen($pic1Path, 'r')
+                            ],
+                            [
+                                'name' => 'pic_2.jpg',
+                                'contents' => fopen($pic2Path, 'r')
+                            ],
+                            [
+                                'name' => 'pic_3.jpg',
+                                'contents' => fopen($pic3Path, 'r')
+                            ],
+                        ]
                     ]);
 
                     if ($response1->getStatusCode() !== 200) {