-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws_pinpoint.php
90 lines (76 loc) · 2.03 KB
/
aws_pinpoint.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Class CRM_SMS_Provider_Dummysms
*/
class aws_pinpoint extends CRM_SMS_Provider
{
protected $config = array();
/**
* A processed params array
*
* @var array
*/
protected $params = array();
static private $_singleton;
function __construct($provider)
{
$this->config = civicrm_api3('SmsProvider', 'getsingle', ['id' => $provider['provider_id']]);
$params = explode("\n", $this->config['api_params']);
foreach ($params as $line) {
$parts = explode('=', trim($line));
$key = array_shift($parts);
$this->params[$key] = implode('=', $parts);
}
}
static function &singleton($providerParams = [], $force = false)
{
if (!isset(self::$_singleton)) {
self::$_singleton = new aws_pinpoint($providerParams);
}
return self::$_singleton;
}
function send($recipients, $header, $message, $jobID = NULL, $userID = NULL)
{
$client = new Aws\Pinpoint\PinpointClient([
'version' => 'latest',
'region' => $this->params['region'],
'credentials' => [
'key' => $this->config['username'],
'secret' => $this->config['password'],
]
]);
$result = $client->sendMessages([
'ApplicationId' => $this->params['application_id'],
'MessageRequest' => [
'Addresses' => [
$recipients => [
'ChannelType' => 'SMS',
],
],
'MessageConfiguration' => [
'SMSMessage' => [
'Body' => $message,
],
],
],
]);
return $result->get('MessageResponse')['RequestId'];
}
function inbound()
{
$input = json_decode(file_get_contents('php://input'));
if ($input->Type == 'SubscriptionConfirmation') {
file_get_contents($input->SubscribeURL);
return;
}
if ($input->Type == 'Notification') {
$message = json_decode($input->Message);
return parent::processInbound(
$message->originationNumber,
$message->messageBody,
null,
$message->inboundMessageId
);
}
}
}