Browse Source

added TELEGRAM_PROXY functionality

master
Evgeniy Ierusalimov 2 days ago
parent
commit
9d5af9a434
3 changed files with 19 additions and 3 deletions
  1. 2
    0
      .env
  2. 6
    0
      config/services.yaml
  3. 11
    3
      src/Service/TelegramNotifier.php

+ 2
- 0
.env View File

38
 TELEGRAM_DSN=telegram://bot_token@default?channel=channel_id
38
 TELEGRAM_DSN=telegram://bot_token@default?channel=channel_id
39
 ###< symfony/telegram-notifier ###
39
 ###< symfony/telegram-notifier ###
40
 
40
 
41
+TELEGRAM_PROXY=
42
+
41
 TELEGRAM_BOT_TOKEN=
43
 TELEGRAM_BOT_TOKEN=
42
 TELEGRAM_CHAT_ID=
44
 TELEGRAM_CHAT_ID=
43
 
45
 

+ 6
- 0
config/services.yaml View File

27
         arguments:
27
         arguments:
28
             $telegramBotToken: '%env(TELEGRAM_BOT_TOKEN)%'
28
             $telegramBotToken: '%env(TELEGRAM_BOT_TOKEN)%'
29
             $telegramChatId: '%env(TELEGRAM_CHAT_ID)%'
29
             $telegramChatId: '%env(TELEGRAM_CHAT_ID)%'
30
+            $httpClient: '@App\Service\TelegramHttpClient'
31
+
32
+    App\Service\TelegramHttpClient:
33
+        factory: ['Symfony\Component\HttpClient\HttpClient', 'create']
34
+        arguments:
35
+            - proxy: '%env(TELEGRAM_PROXY)%'
30
 
36
 
31
     App\Presentation\PortfolioPresenter:
37
     App\Presentation\PortfolioPresenter:
32
         arguments:
38
         arguments:

+ 11
- 3
src/Service/TelegramNotifier.php View File

6
 use Symfony\Component\Notifier\Chatter;
6
 use Symfony\Component\Notifier\Chatter;
7
 use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
7
 use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
8
 use Symfony\Component\Notifier\Message\ChatMessage;
8
 use Symfony\Component\Notifier\Message\ChatMessage;
9
+use Symfony\Contracts\HttpClient\HttpClientInterface;
9
 
10
 
10
 readonly class TelegramNotifier
11
 readonly class TelegramNotifier
11
 {
12
 {
12
-    public function __construct(private string $telegramBotToken, private string $telegramChatId)
13
-    {
13
+    public function __construct(
14
+        private string $telegramBotToken,
15
+        private string $telegramChatId,
16
+        private HttpClientInterface $httpClient,
17
+    ) {
14
     }
18
     }
15
 
19
 
16
     public function notify(string $message, ?string $filename = null): void
20
     public function notify(string $message, ?string $filename = null): void
17
     {
21
     {
18
-        $telegramTransport = new TelegramTransport($this->telegramBotToken, $this->telegramChatId);
22
+        $telegramTransport = new TelegramTransport(
23
+            $this->telegramBotToken,
24
+            $this->telegramChatId,
25
+            $this->httpClient,
26
+        );
19
         $chatter = new Chatter($telegramTransport);
27
         $chatter = new Chatter($telegramTransport);
20
         $chatMessage = new ChatMessage($message);
28
         $chatMessage = new ChatMessage($message);
21
 
29
 

Loading…
Cancel
Save