1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\AwsPinpoint; |
4
|
|
|
|
5
|
|
|
use Aws\AwsClient; |
6
|
|
|
use NotificationChannels\AwsPinpoint\Events\DeliveryFailed; |
7
|
|
|
use NotificationChannels\AwsPinpoint\Events\DeliverySuccess; |
8
|
|
|
use NotificationChannels\AwsPinpoint\Exceptions\CouldNotSendNotification; |
9
|
|
|
|
10
|
|
|
class AwsPinpointClient |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var AwsClient |
14
|
|
|
*/ |
15
|
|
|
protected $client; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Create a AwsPinpointClient instance. |
19
|
|
|
* |
20
|
|
|
* @param AwsClient $client |
21
|
|
|
*/ |
22
|
|
|
public function __construct(AwsClient $client = null) |
23
|
|
|
{ |
24
|
|
|
$this->client = $client; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Send the Message. |
29
|
|
|
* |
30
|
|
|
* @param AwsPinpointSmsMessage $message |
31
|
|
|
* @throws CouldNotSendNotification |
32
|
|
|
*/ |
33
|
|
|
public function send(AwsPinpointSmsMessage $message) |
34
|
|
|
{ |
35
|
|
|
try { |
36
|
|
|
$result = $this->client->sendMessages([ |
37
|
|
|
'ApplicationId' => config('aws.Pinpoint.application_id'), |
38
|
|
|
'MessageRequest' => [ |
39
|
|
|
'Addresses' => $message->recipients, |
40
|
|
|
'MessageConfiguration' => [ |
41
|
|
|
'SMSMessage' => [ |
42
|
|
|
'Body' => $message->body, |
43
|
|
|
'MessageType' => $message->messageType, |
44
|
|
|
'SenderId' => config('aws.Pinpoint.sender_id'), |
45
|
|
|
], |
46
|
|
|
], |
47
|
|
|
], |
48
|
|
|
]); |
49
|
|
|
|
50
|
|
|
$output = $result->get('MessageResponse'); |
51
|
|
|
|
52
|
|
|
foreach ($output['Result'] as $number => $res) { |
53
|
|
|
if ($res['DeliveryStatus'] === 'SUCCESSFUL') { |
54
|
|
|
// Trigger event for successful deliveries |
55
|
|
|
event(new DeliverySuccess($number, $message->body, $res['StatusMessage'])); |
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// Trigger event for failed deliveries |
60
|
|
|
event(new DeliveryFailed($number, $message->body, $res['StatusMessage'])); |
61
|
|
|
} |
62
|
|
|
} catch (Exception $exception) { |
|
|
|
|
63
|
|
|
throw CouldNotSendNotification::serviceRespondedWithAnError($exception); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.