This package makes it easy to send notifications using Amazon SNS with Laravel 5.3.
Can to install with commands:
composer require lab123/aws-sns
Or editing the composer.json
file:
"require": {
"lab123/aws-sns": "dev-master"
}
You must install the service provider in config/app.php
:
'providers' => [
...
Lab123\AwsSns\AwsSnsServiceProvider::class,
],
Follow the Amazon Console generate the APIKEY and API SECRET, which is connecting both.
Create a new sns section inside config/services.php
:
...
'sns' => [
'key' => env('SNS_KEY'),
'secret' => env('SNS_SECRET'),
'region' => env('SNS_REGION', 'us-east-1')
],
...
Next we need to add this keys to our Laravel environment. Edit file .env
to config the keys:
SNS_KEY=YOUR_KEY
SNS_SECRET=YOUR_SECRET
SNS_REGION=YOUR_REGION
To send sms without the need to create a topic, leave the function via
as follows:
// Notifications/Welcome.php
/**
* Get the notification channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return [
AwsSnsSmsChannel::class
];
}
Add function toAwsSns()
expected by class AwsSnsChannel
to send notification:
// Notifications/Welcome.php
/**
* Get the AWS SNS SMS Message representation of the notification.
*
* @param mixed $notifiable
* @return \Lab123\AwsSns\Messages\AwsSnsMessage
*/
public function toAwsSns($notifiable)
{
return (new AwsSnsMessage())->message('Message Here')->phoneNumber('+5511999999999');
}
You also can ignore the ->phoneNumber()
in your notification and use function routeNotificationForAwsSnsSms
in your Model Notifiable:
// Models/User.php
/**
* Route notifications for the Aws SNS SMS channel.
*
* @return string
*/
public function routeNotificationForAwsSnsSms()
{
return $this->phone_number;
}
**Obs.: ** The expected number use the standards-based international E.123
eg.: +5511999999999
To send notification to a topic, leave the function via
as follows:
// Notifications/Welcome.php
/**
* Get the notification channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return [
AwsSnsTopicChannel::class
];
}
Add function toAwsSnsTopic()
expected by class AwsSnsTopicChannel
to send notification:
// Notifications/Welcome.php
/**
* Get the AWS SNS Topic Message representation of the notification.
*
* @param mixed $notifiable
* @return \Lab123\AwsSns\Messages\AwsSnsMessage
*/
public function toAwsSnsTopic($notifiable)
{
return (new AwsSnsMessage())->message('Message Here')->topicArn('arn:aws:sns:us-east-1:000000000000:name-topic');
}
You also can ignore the ->topicArn()
in your notification and use function routeNotificationForAwsSnsTopic
in your Model Notifiable:
// Models/User.php
/**
* Route notifications for the Aws SNS Topic channel.
*
* @return string
*/
public function routeNotificationForAwsSnsTopic()
{
return $this->topicArn;
}
topicArn($topicArn)
: Your Topic Arn from Amazon SNS;phoneNumber($phoneNumber)
: Phone number to send notification;message($message)
: Message to be sent;
Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email jean.pierre@lab123.com.br instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.