|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Messagebird; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
|
6
|
|
|
use Illuminate\Notifications\Events\NotificationFailed; |
|
7
|
|
|
use Illuminate\Notifications\Notification; |
|
8
|
|
|
use NotificationChannels\Messagebird\Exceptions\CouldNotSendNotification; |
|
9
|
|
|
|
|
10
|
|
|
class MessagebirdChannel |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var \NotificationChannels\Messagebird\MessagebirdClient */ |
|
13
|
|
|
protected $client; |
|
14
|
|
|
private $dispatcher; |
|
15
|
|
|
|
|
16
|
3 |
|
public function __construct(MessagebirdClient $client, Dispatcher $dispatcher = null) |
|
17
|
|
|
{ |
|
18
|
3 |
|
$this->client = $client; |
|
19
|
3 |
|
$this->dispatcher = $dispatcher; |
|
20
|
3 |
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Send the given notification. |
|
24
|
|
|
* |
|
25
|
|
|
* @param mixed $notifiable |
|
26
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
|
27
|
|
|
* |
|
28
|
|
|
* @return object with response body data if succesful response from API | empty array if not |
|
29
|
|
|
* @throws \NotificationChannels\MessageBird\Exceptions\CouldNotSendNotification |
|
30
|
|
|
*/ |
|
31
|
2 |
|
public function send($notifiable, Notification $notification) |
|
32
|
|
|
{ |
|
33
|
2 |
|
$message = $notification->toMessagebird($notifiable); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
2 |
|
$data = []; |
|
36
|
|
|
|
|
37
|
2 |
|
if (is_string($message)) { |
|
38
|
1 |
|
$message = MessagebirdMessage::create($message); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
2 |
|
if ($to = $notifiable->routeNotificationFor('messagebird')) { |
|
42
|
2 |
|
$message->setRecipients($to); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
try { |
|
46
|
2 |
|
$data = $this->client->send($message); |
|
47
|
|
|
|
|
48
|
2 |
|
if ($this->dispatcher !== null) { |
|
49
|
2 |
|
$this->dispatcher->dispatch('messagebird-sms', [$notifiable, $notification, $data]); |
|
50
|
|
|
} |
|
51
|
|
|
} catch (CouldNotSendNotification $e) { |
|
52
|
|
|
if ($this->dispatcher !== null) { |
|
53
|
|
|
$this->dispatcher->dispatch( |
|
54
|
|
|
new NotificationFailed( |
|
55
|
|
|
$notifiable, |
|
56
|
|
|
$notification, |
|
57
|
|
|
'messagebird-sms', |
|
58
|
|
|
$e->getMessage() |
|
|
|
|
|
|
59
|
|
|
) |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
2 |
|
return $data; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.