@@ -56,6 +56,8 @@ class TelegramBotHandler extends AbstractProcessingHandler
56
56
*/
57
57
protected $ topicId ;
58
58
59
+ protected $ queue = null ;
60
+
59
61
protected $ topicsLevel ;
60
62
61
63
/**
@@ -68,6 +70,7 @@ public function __construct(
68
70
string $ token ,
69
71
string $ chat_id ,
70
72
?string $ topic_id = null ,
73
+ ?string $ queue = null ,
71
74
$ topics_level = [],
72
75
$ level = Logger::DEBUG ,
73
76
bool $ bubble = true ,
@@ -81,6 +84,7 @@ public function __construct(
81
84
$ this ->botApi = $ bot_api ;
82
85
$ this ->chatId = $ chat_id ;
83
86
$ this ->topicId = $ topic_id ;
87
+ $ this ->queue = $ queue ;
84
88
$ this ->topicsLevel = $ topics_level ;
85
89
$ this ->level = $ level ;
86
90
$ this ->bubble = $ bubble ;
@@ -116,47 +120,24 @@ private function truncateTextToTelegramLimit(string $textMessage): string
116
120
* @param null $token
117
121
* @param null $chatId
118
122
* @param null $topicId
119
- * @param array $option
120
123
* @throws GuzzleException
121
124
*/
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
123
126
{
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 ;
145
130
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 ' ;
152
134
153
- $ options = [
154
- 'form_params ' => $ topicId !== null ? $ params + ['message_thread_id ' => $ topicId ] : $ params
155
- ];
135
+ $ message = $ this ->truncateTextToTelegramLimit ($ message );
156
136
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 );
160
141
}
161
142
}
162
143
0 commit comments