1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CoreProc\NotificationChannels\Telerivet; |
4
|
|
|
|
5
|
|
|
use CoreProc\NotificationChannels\Telerivet\Exceptions\CouldNotSendNotification; |
6
|
|
|
use GuzzleHttp\Client; |
7
|
|
|
use GuzzleHttp\Exception\RequestException; |
8
|
|
|
use Illuminate\Notifications\Notification; |
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
10
|
|
|
|
11
|
|
|
class TelerivetChannel |
12
|
|
|
{ |
13
|
|
|
public const DEFAULT_API_URL = 'https://api.telerivet.com'; |
14
|
|
|
|
15
|
|
|
protected $client; |
16
|
|
|
|
17
|
|
|
public function __construct(Client $client) |
18
|
|
|
{ |
19
|
|
|
$this->client = $client; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Send the given notification. |
24
|
|
|
* |
25
|
|
|
* @param mixed $notifiable |
26
|
|
|
* @param Notification $notification |
27
|
|
|
* |
28
|
|
|
* @return ResponseInterface |
29
|
|
|
* @throws CouldNotSendNotification |
30
|
|
|
*/ |
31
|
|
|
public function send($notifiable, Notification $notification) |
32
|
|
|
{ |
33
|
|
|
$telerivetMessage = $notification->toTelerivet($notifiable); |
|
|
|
|
34
|
|
|
|
35
|
|
|
// If the message does not have a to_number of contact_id |
36
|
|
|
if (empty($telerivetMessage->getToNumber()) && empty($telerivetMessage->getContactId())) { |
37
|
|
|
// Check first if the notifiable object has a telerivetContactId |
38
|
|
|
if (! empty($notifiable->routeNotificationFor('telerivetContactId'))) { |
39
|
|
|
$telerivetMessage->setContactId($notifiable->routeNotificationFor('telerivetContactId')); |
40
|
|
|
} else { |
41
|
|
|
// If not, default to the "telerivet" route which should be a phone number |
42
|
|
|
$telerivetMessage->setToNumber($notifiable->routeNotificationFor('telerivet')); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
try { |
47
|
|
|
$response = $this->client->post( |
48
|
|
|
'v1/projects/' . config('broadcasting.connections.telerivet.project_id') . '/messages/send', |
49
|
|
|
[ |
50
|
|
|
'auth' => [config('broadcasting.connections.telerivet.api_key'), ''], |
51
|
|
|
'json' => $telerivetMessage->toArray(), |
52
|
|
|
] |
53
|
|
|
); |
54
|
|
|
} catch (RequestException $requestException) { |
55
|
|
|
throw CouldNotSendNotification::serviceRespondedWithAnError($requestException); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $response; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
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.