@@ -52,6 +52,13 @@ class TelegramBotHandler extends AbstractProcessingHandler
5252
5353 protected TopicDetector $ topicDetector ;
5454
55+ /**
56+ * Timeout for Telegram API requests in seconds.
57+ *
58+ * @var int
59+ */
60+ protected int $ timeout ;
61+
5562 /**
5663 * @param string $token Telegram bot access token provided by BotFather
5764 * @param string $channel Telegram channel name
@@ -66,7 +73,9 @@ public function __construct(
6673 $ level = Logger::DEBUG ,
6774 bool $ bubble = true ,
6875 string $ bot_api = 'https://api.telegram.org/bot ' ,
69- string |null $ proxy = null )
76+ string |null $ proxy = null ,
77+ int $ timeout = 5
78+ )
7079 {
7180 parent ::__construct ($ level , $ bubble );
7281
@@ -78,6 +87,7 @@ public function __construct(
7887 $ this ->level = $ level ;
7988 $ this ->bubble = $ bubble ;
8089 $ this ->proxy = $ proxy ;
90+ $ this ->timeout = $ timeout ;
8191
8292 $ this ->topicDetector = new TopicDetector ($ topics_level );
8393 }
@@ -127,9 +137,9 @@ protected function send(string $message, $token = null, $chatId = null, $topicId
127137 $ message = $ this ->truncateTextToTelegramLimit ($ message );
128138
129139 if (empty ($ this ->queue )) {
130- dispatch_sync (new SendJob ($ url , $ message , $ chatId , $ topicId , $ this ->proxy ));
140+ dispatch_sync (new SendJob ($ url , $ message , $ chatId , $ topicId , $ this ->proxy , $ this -> timeout ));
131141 } else {
132- dispatch (new SendJob ($ url , $ message , $ chatId , $ topicId , $ this ->proxy ))->onQueue ($ this ->queue );
142+ dispatch (new SendJob ($ url , $ message , $ chatId , $ topicId , $ this ->proxy , $ this -> timeout ))->onQueue ($ this ->queue );
133143 }
134144 }
135145
0 commit comments