laravel-notification-channels / pushwoosh
Pushwoosh notification channel for Laravel
Installs: 28 777
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 4
Open Issues: 0
Requires
- php: ^7.1|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.2 || ^7.0
- guzzlehttp/psr7: ^1.0 || ^2.0
- laravel/framework: ^5.5 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
Requires (Dev)
- mockery/mockery: ^1.3.1
- orchestra/testbench: ^3.5 || ^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^7.5 || ^8.0 || ^9.0 || ^10.0
README
This package makes sending notifications using Pushwoosh a breeze.
Contents
Requirements
This make use of this package you need:
- Laravel 5.5 or higher
- PHP 7.1 or higher
- An active Pushwoosh subscription (and use at least one Pushwoosh SDK)
Installation
To install this package run the following command:
composer require laravel-notification-channels/pushwoosh
Next, add the following lines to your config/services.php
:
'pushwoosh' => [ 'application' => env('PUSHWOOSH_APP_CODE'), 'token' => env('PUSHWOOSH_TOKEN'), ],
You can now add the PUSHWOOSH_APP_CODE
(found here) and the
PUSHWOOSH_TOKEN
(found here) to your environment file.
Usage
Using this package, you can use Pushwoosh just like any other notification channel within Laravel. For more information about Laravel's notification system, see the official documentation.
Note that before you can start sending pushes you must first register users to your application using one of Pushwoosh's SDKs.
Routing notifications
In order for Pushwoosh to know to what devices it needs to send to, you will need to add the
routeNotificationForPushwoosh
to your notifiable model(s), for example:
class Customer extends Model { use Notifiable; public function routeNotificationForPushwoosh() { // In this example 'device_id' is a token previously // retrieved from Pushwoosh using one of their SDKs return (new PushwooshRecipient)->device($this->device_id); } }
The routeNotificationForPushwoosh
method may return a string, an array of strings or a PushwooshRecipient
instance.
For more information about the PushwooshRecipient
class refer to the available methods section.
Sending notifications
Sending a pushwoosh message is easy, add pushwoosh
to your notification's via method and implement the toPushwoosh
method, for example:
class WishlistItemOnSale extends Notification { public function via($notifiable) { return ['pushwoosh']; } public function toPushwoosh($notifiable) { return (new PushwooshMessage) ->content('Your wishlist item ' . $this->product->name . ' is on sale, get it now!') ->url(route('products.show', $this->product)) ->deliverAt(Carbon::now()->addMinutes(10)); } }
The
toPushwoosh
method may return a string or an instance of thePushwooshMessage
class, for more information on thePushwooshMessage
class refer to the available methods section.
You can then send a push to one user:
$customer->notify(new WishlistItemOnSale($product));
Or to multiple users:
Notification::send($customers, new WishlistItemOnSale($product));
Unknown devices
When you reference devices that do not exist (anymore), a NotificationChannels\Pushwoosh\Events\UnknownDevices
event
will be dispatched.
You can easily hook into this event like so:
Event::listen( NotificationChannels\Pushwoosh\Events\UnknownDevices::class, function ($event) { // Handle the event } );
Available methods
This section details the public API of this package.
PushwooshMessage
Below is a list of available methods on the PushwooshMessage
class.
PushwooshRecipient
Below is a list of available methods on the PushwooshRecipient
class.
Platforms
Below is a list of supported platforms, for the PushwooshRecipient::platform
method.
- Amazon
- Android
- Blackberry
- Chrome
- Firefox
- iOS
- Mac
- Safari
- Windows
- Windows Phone
Changelog
Please see the changelog for more information on what has changed recently.
Testing
composer test
Contributing
If you want to contribute to this package, take a look at the contribution guide.
Credits
License
This product is licensed under the MIT License (MIT). Please see the License File for more information.