File tree Expand file tree Collapse file tree 2 files changed +36
-23
lines changed Expand file tree Collapse file tree 2 files changed +36
-23
lines changed Original file line number Diff line number Diff line change 22
33namespace App \Actions ;
44
5+ use App \Jobs \SendTelegram ;
56use GuzzleHttp \Client ;
67use GuzzleHttp \Exception \GuzzleException ;
78
@@ -31,28 +32,6 @@ public static function error($log): void
3132 self ::handle ("error " , $ log );
3233 }
3334
34- /**
35- * @throws GuzzleException
36- */
37- private static function send ($ message ): void
38- {
39- $ token = config ("telegram.token " );
40- $ channelUsername = config ("telegram.id " );
41-
42- $ client = new Client ();
43- $ url = "https://api.telegram.org/bot {$ token }/sendMessage " ;
44-
45- $ client ->post ($ url , [
46- 'form_params ' => [
47- 'chat_id ' => $ channelUsername ,
48- 'text ' => $ message ,
49- ],
50- ]);
51- }
52-
53- /**
54- * @throws GuzzleException
55- */
5635 private static function handle ($ type , $ log ): void
5736 {
5837 $ template = "" ;
@@ -64,6 +43,6 @@ private static function handle($type, $log): void
6443
6544 $ template .= $ log ;
6645
67- self :: send ($ template );
46+ SendTelegram:: dispatch ($ template );
6847 }
6948}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Jobs ;
4+
5+ use GuzzleHttp \Client ;
6+ use Illuminate \Contracts \Queue \ShouldQueue ;
7+ use Illuminate \Foundation \Queue \Queueable ;
8+
9+ class SendTelegram implements ShouldQueue
10+ {
11+ use Queueable;
12+
13+ public $ message ;
14+
15+
16+ public function __construct ($ message )
17+ {
18+ $ this ->message = $ message ;
19+ }
20+
21+ /**
22+ * Execute the job.
23+ */
24+ public function handle (): void
25+ {
26+ $ token = config ("telegram.token " );
27+ $ channelUsername = config ("telegram.id " );
28+
29+ $ client = new Client ();
30+ $ url = "https://api.telegram.org/bot {$ token }/sendMessage " ;
31+
32+ $ client ->post ($ url , ['form_params ' => ['chat_id ' => $ channelUsername , 'text ' => $ this ->message ]]);
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments