This package makes it easy to send notifications using Octopush with Laravel 5.3.
Install the package via composer :
composer require laravel-notification-channels/octopush
Register the service provider in your config/app.php
configuration file :
// config/app.php
'providers' => [
...
NotificationChannels\Octopush\OctopushServiceProvider::class,
],
Set up the Octopush service as explained below.
Register a free trial account from Octopush website (offering 5 SMS for free) .
Get your credentials from your Octopush account, and add them to your config/services.php
configuration file :
// config/services.php
...
'octopush' => [
'user_login' => '**********@*******',
'api_key' => '****************',
],
...
The table below shows a complete list of all available configuration parameters :
Parameter name | Description |
---|---|
user_login |
User login (email address used for registration). This parameter is mandatory. |
api_key |
API key available on your Octopush manager. This parameter is mandatory. |
sms_text |
SMS message text (maximum 459 characters). |
sms_type |
SMS type : XXX for low cost SMS, FR for Premium SMS (France only), and WWW for global worldwide SMS (default value). In France, if STOP XXXXX is missing from your message text, the API will return an error. |
sms_sender |
Sender of the message (if supported by the recipient mobile phone operator), containing from 3 to 11 alphanumeric characters only. |
request_mode |
Allows to enable a simulation mode with the value simu . In the simulation mode, the API calls are done, but no SMS are sent. The default value is real (simulation mode is disabled by default). |
For a better convenience, parameter names match the ones used by Octopush SMS API, which are described at the following URL : http://www.octopush.com/en/api-sms-doc/parameters.
You can use the channel in the via()
method inside the notification class, and format the notification message within the toOctopush()
method :
use Illuminate\Notifications\Notification;
use NotificationChannels\Octopush\OctopushMessage;
use NotificationChannels\Octopush\OctopushChannel;
class InvoicePaid extends Notification
{
public function via($notifiable)
{
return [OctopushChannel::class];
}
public function toOctopush($notifiable)
{
return (new OctopushMessage)
->from('Online Store')
->content('Your invoice has been paid.');
}
}
The notification channel will automatically look for a phone_number
attribute on the notifiable entity. If you would like to customize the phone number the notification is delivered to, define a routeNotificationForOctopush
method on the entity:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* Route notifications for Octopush channel.
*
* @return string
*/
public function routeNotificationForOctopush()
{
return $this->phone;
}
}
The routeNotificationForOctopush()
method must return a valid phone number, in international format. It can also return an array of phone numbers :
// Notifiable entity
/**
* Route notifications for Octopush channel.
*
* @return string
*/
public function routeNotificationForOctopush()
{
return [$this->professional_phone_number, $this->personal_phone_number];
}
For further information about notification usage, you can read the official documentation about Laravel notification system.
The notification can be customized with the following methods (see OctopushMessage
class):
content(string $text)
: Set the notification message.from(string $sender)
: Set the sender name.
Please see CHANGELOG for more information what has changed recently.
$ composer test
Octopush provides a list of error codes returned by the service : http://www.octopush.com/en/errors_list.
For further information, you can also read the documentation of the Octopush SMS API Client, which is used by this notification system.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Please see CONTRIBUTING for details.
- Bruce Thomas
- Octopush organisation and umpirsky for developing the SMS API client
- All Contributors
The MIT License (MIT). Please see License File for more information.