Skip to content

Commit

Permalink
Conform to the new format for sending.
Browse files Browse the repository at this point in the history
  • Loading branch information
peec committed Dec 26, 2016
1 parent fbde15e commit 3cb8a89
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Add to your `config/services.php`:
'secret' => env('AWSSMS_SECRET'),
'region' => env('AWSSMS_REGION'),
'from' => env('AWSSMS_FROM'), // optional
'max_price_usd' => '0.50' // Max price, sms wont send if price of the sms is more then this.
],
...
```
Expand Down
38 changes: 31 additions & 7 deletions src/AWSSMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@ class AWSSMS
*/
protected $from;

public function __construct(\Aws\Sns\SnsClient $snsClient, $from)
/**
* The maximum amount in USD that you are willing to spend to send the SMS message. Amazon SNS will not send the message if it determines that doing so would incur a cost that exceeds the maximum price.
* This attribute has no effect if your month-to-date SMS costs have already exceeded the limit set for the MonthlySpendLimit attribute, which you set by using the SetSMSAttributes request.
* If you are sending the message to an Amazon SNS topic, the maximum price applies to each message delivery to each phone number that is subscribed to the topic.
* @var
*/
protected $maxPrice;

public function __construct(\Aws\Sns\SnsClient $snsClient, $from, $maxPrice)
{
$this->snsClient = $snsClient;
$this->from = $from;
$this->maxPrice = $maxPrice;
}
/**
* Send a TwilioMessage to the a phone number.
Expand All @@ -43,12 +52,27 @@ public function sendMessage(AWSSMSMessage $message, $to)
}
protected function sendSmsMessage(AWSSMSMessage $message, $to)
{
$args = array(
"SenderID" => $this->getFrom($message),
"SMSType" => $message->type,
"Message" => $message->content,
"PhoneNumber" => $to
);

$args = [
'Message' => $message->content,
'PhoneNumber' => $to,
'MessageAttributes' => [
'AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => $this->getFrom($message)
],

'AWS.SNS.SMS.SMSType' => [
'DataType' => 'String',
'StringValue' => $message->type
],
'AWS.SNS.SMS.MaxPrice' => [
'DataType' => 'String',
'StringValue' => $this->maxPrice
]
]
];



return $this->snsClient->publish($args);
Expand Down
3 changes: 2 additions & 1 deletion src/AWSSMSServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function boot()

return new AWSSMS(
$client,
$config['from']
$config['from'],
isset($config['max_price_usd']) ? $config['max_price_usd'] : '0.50'
);
});

Expand Down

0 comments on commit 3cb8a89

Please sign in to comment.