@@ -56,6 +56,8 @@ class TelegramBotHandler extends AbstractProcessingHandler
5656 */
5757 protected $ topicId ;
5858
59+ protected $ queue = null ;
60+
5961 protected $ topicsLevel ;
6062
6163 /**
@@ -68,6 +70,7 @@ public function __construct(
6870 string $ token ,
6971 string $ chat_id ,
7072 ?string $ topic_id = null ,
73+ ?string $ queue = null ,
7174 $ topics_level = [],
7275 $ level = Logger::DEBUG ,
7376 bool $ bubble = true ,
@@ -81,6 +84,7 @@ public function __construct(
8184 $ this ->botApi = $ bot_api ;
8285 $ this ->chatId = $ chat_id ;
8386 $ this ->topicId = $ topic_id ;
87+ $ this ->queue = $ queue ;
8488 $ this ->topicsLevel = $ topics_level ;
8589 $ this ->level = $ level ;
8690 $ this ->bubble = $ bubble ;
@@ -116,47 +120,24 @@ private function truncateTextToTelegramLimit(string $textMessage): string
116120 * @param null $token
117121 * @param null $chatId
118122 * @param null $topicId
119- * @param array $option
120123 * @throws GuzzleException
121124 */
122- protected function send (string $ message , $ token = null , $ chatId = null , $ topicId = null , array $ option = [] ): void
125+ protected function send (string $ message , $ token = null , $ chatId = null , $ topicId = null ): void
123126 {
124- try {
125-
126- $ token = $ token ?? $ this ->token ;
127- $ chatId = $ chatId ?? $ this ->chatId ;
128- $ topicId = $ topicId ?? $ this ->topicId ;
129-
130- if (!isset ($ option ['verify ' ])) {
131- $ option ['verify ' ] = false ;
132- }
133-
134- if (!is_null ($ this ->proxy )) {
135- $ option ['proxy ' ] = $ this ->proxy ;
136- }
137-
138- $ httpClient = new Client ($ option );
139-
140- $ url = !str_contains ($ this ->botApi , 'https://api.telegram.org ' )
141- ? $ this ->botApi
142- : $ this ->botApi . $ token . '/SendMessage ' ;
143-
144- $ message = $ this ->truncateTextToTelegramLimit ($ message );
127+ $ token = $ token ?? $ this ->token ;
128+ $ chatId = $ chatId ?? $ this ->chatId ;
129+ $ topicId = $ topicId ?? $ this ->topicId ;
145130
146- $ params = [
147- 'text ' => $ message ,
148- 'chat_id ' => $ chatId ,
149- 'parse_mode ' => 'html ' ,
150- 'disable_web_page_preview ' => true ,
151- ];
131+ $ url = !str_contains ($ this ->botApi , 'https://api.telegram.org ' )
132+ ? $ this ->botApi
133+ : $ this ->botApi . $ token . '/SendMessage ' ;
152134
153- $ options = [
154- 'form_params ' => $ topicId !== null ? $ params + ['message_thread_id ' => $ topicId ] : $ params
155- ];
135+ $ message = $ this ->truncateTextToTelegramLimit ($ message );
156136
157- $ response = $ httpClient ->post ($ url , $ options );
158- } catch (\Exception $ e ) {
159- $ a = 1 ;
137+ if ($ this ->queue === null ) {
138+ dispatch_sync (new SendJob ($ url , $ message , $ chatId , $ topicId , $ this ->proxy ));
139+ } else {
140+ dispatch (new SendJob ($ url , $ message , $ chatId , $ topicId , $ this ->proxy ))->onQueue ($ this ->queue );
160141 }
161142 }
162143
0 commit comments