浏览代码

added TELEGRAM_PROXY functionality

master
Evgeniy Ierusalimov 2 天前
父节点
当前提交
9d5af9a434
共有 3 个文件被更改,包括 19 次插入3 次删除
  1. 2
    0
      .env
  2. 6
    0
      config/services.yaml
  3. 11
    3
      src/Service/TelegramNotifier.php

+ 2
- 0
.env 查看文件

@@ -38,6 +38,8 @@ DATABASE_URL="postgresql://db_user:secret@127.0.0.1:5432/finfollow?serverVersion
38 38
 TELEGRAM_DSN=telegram://bot_token@default?channel=channel_id
39 39
 ###< symfony/telegram-notifier ###
40 40
 
41
+TELEGRAM_PROXY=
42
+
41 43
 TELEGRAM_BOT_TOKEN=
42 44
 TELEGRAM_CHAT_ID=
43 45
 

+ 6
- 0
config/services.yaml 查看文件

@@ -27,6 +27,12 @@ services:
27 27
         arguments:
28 28
             $telegramBotToken: '%env(TELEGRAM_BOT_TOKEN)%'
29 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 37
     App\Presentation\PortfolioPresenter:
32 38
         arguments:

+ 11
- 3
src/Service/TelegramNotifier.php 查看文件

@@ -6,16 +6,24 @@ use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransport;
6 6
 use Symfony\Component\Notifier\Chatter;
7 7
 use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
8 8
 use Symfony\Component\Notifier\Message\ChatMessage;
9
+use Symfony\Contracts\HttpClient\HttpClientInterface;
9 10
 
10 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 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 27
         $chatter = new Chatter($telegramTransport);
20 28
         $chatMessage = new ChatMessage($message);
21 29
 

正在加载...
取消
保存