1 | <?php |
||
2 | |||
3 | namespace NotificationChannels\FacebookPoster; |
||
4 | |||
5 | use GuzzleHttp\Client; |
||
6 | use Illuminate\Contracts\Config\Repository; |
||
7 | use Illuminate\Notifications\Notification; |
||
8 | use Illuminate\Support\Arr; |
||
9 | |||
10 | class FacebookPosterChannel |
||
11 | { |
||
12 | /** |
||
13 | * The Guzzle client. |
||
14 | */ |
||
15 | protected Client $guzzle; |
||
16 | |||
17 | /** |
||
18 | * The application config. |
||
19 | */ |
||
20 | protected Repository $config; |
||
21 | |||
22 | 4 | /** |
|
23 | * Create a new channel instance. |
||
24 | 4 | */ |
|
25 | 4 | public function __construct(Client $guzzle, Repository $config) |
|
26 | { |
||
27 | $this->guzzle = $guzzle; |
||
28 | $this->config = $config; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Send the given notification. |
||
33 | 4 | * |
|
34 | * @param mixed $notifiable |
||
35 | 4 | * @param \Illuminate\Notifications\Notification $notification |
|
36 | */ |
||
37 | public function send($notifiable, Notification $notification) |
||
38 | { |
||
39 | 4 | $post = $notification->toFacebookPoster($notifiable); |
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
40 | |||
41 | 4 | $routing = $notifiable->routeNotificationFor('facebookPoster'); |
|
42 | |||
43 | 4 | $pageId = Arr::get($routing, 'page_id', function () { |
|
44 | 2 | return $this->config->get('services.facebook_poster.page_id'); |
|
45 | }); |
||
46 | |||
47 | 4 | $accessToken = Arr::get($routing, 'access_token', function () { |
|
48 | 4 | return $this->config->get('services.facebook_poster.access_token'); |
|
49 | }); |
||
50 | |||
51 | $this->guzzle->post("https://graph.facebook.com/v18.0/{$pageId}/feed?access_token={$accessToken}", [ |
||
52 | 'form_params' => $post->getBody(), |
||
53 | ]); |
||
54 | } |
||
55 | } |
||
56 |