4
4
5
5
use Illuminate \Http \Client \PendingRequest ;
6
6
use Illuminate \Http \Client \RequestException ;
7
+ use Illuminate \Http \Client \Response ;
7
8
use Illuminate \Notifications \Notification ;
8
9
use Illuminate \Support \Facades \Http ;
9
10
@@ -12,15 +13,15 @@ class DiscordChannel
12
13
/**
13
14
* @throws RequestException
14
15
*/
15
- public function send (mixed $ notifiable , Notification $ notification ): void
16
+ public function send (mixed $ notifiable , Notification $ notification ): ? Response
16
17
{
17
18
/**
18
19
* @var DiscordMessage $message
19
20
*/
20
21
$ message = $ notification ->toDiscordWebhook ($ notifiable );
21
22
22
23
if (! $ message ->isValid ()) {
23
- return ;
24
+ return null ;
24
25
}
25
26
26
27
/**
@@ -29,22 +30,22 @@ public function send(mixed $notifiable, Notification $notification): void
29
30
$ webhook_url = $ notifiable ->routeNotificationFor ('discord-webhook ' );
30
31
31
32
if (empty ($ webhook_url )) {
32
- return ;
33
+ return null ;
33
34
}
34
35
35
- Http::attach (
36
+ return Http::attach (
36
37
name: 'payload_json ' ,
37
38
contents: $ message ->toJson (),
38
- headers: ['Content-Type ' => 'application/json ' ]
39
+ headers: ['Content-Type ' => 'application/json ' ],
39
40
)->when (filled ($ message ->getAttachments ()), function (PendingRequest $ client ) use ($ message ) {
40
41
foreach ($ message ->getAttachments () as $ id => $ attach ) {
41
42
$ client ->attach (
42
43
name: "files[ $ id] " ,
43
44
contents: $ attach ->content ,
44
45
filename: $ attach ->filename ,
45
- headers: ['Content-Type ' => $ attach ->filetype ]
46
+ headers: ['Content-Type ' => $ attach ->filetype ],
46
47
);
47
48
}
48
- })->post ($ webhook_url )-> throw () ;
49
+ })->post ($ webhook_url );
49
50
}
50
51
}
0 commit comments