|
| 1 | +# Pushbullet notification channel for Laravel 5.3 |
| 2 | + |
| 3 | +This package makes it easy to send notifications using [Pushbullet](http://pushbullet.com) with Laravel 5.3. |
| 4 | + |
| 5 | +## Contents |
| 6 | + |
| 7 | +- [Installation](#installation) |
| 8 | + - [Setting up the Pushbullet service](#setting-up-the-pushbullet-service) |
| 9 | +- [Usage](#usage) |
| 10 | + - [Available Message methods](#available-message-methods) |
| 11 | +- [Changelog](#changelog) |
| 12 | +- [Testing](#testing) |
| 13 | +- [Security](#security) |
| 14 | +- [Contributing](#contributing) |
| 15 | +- [Credits](#credits) |
| 16 | +- [License](#license) |
| 17 | + |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +[PHP](https://php.net) 5.6.4+ is required. |
| 22 | + |
| 23 | +To get the latest version of Pushbullet Notification channel for Laravel 5.3, simply require the project using [Composer](https://getcomposer.org): |
| 24 | + |
| 25 | +```bash |
| 26 | +$ composer require laravel-notification-channels/pushbullet |
| 27 | +``` |
| 28 | + |
| 29 | +Or you can manually update your require block and run `composer update` if you choose so: |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "require": { |
| 34 | + "laravel-notification-channels/pushbullet": "^0.1" |
| 35 | + } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +You will also need to install `guzzlehttp/guzzle` http client to send request to Pushbullet API. |
| 40 | + |
| 41 | +Once package is installed, you need to register the service provider. Open up `config/app.php` and add the following to the `providers` key. |
| 42 | + |
| 43 | +* `NotificationChannels\Pushbullet\PushbulletServiceProvider::class` |
| 44 | + |
| 45 | +### Setting up the Pushbullet service |
| 46 | + |
| 47 | +In your pushbullet account go to [Account settings](https://www.pushbullet.com/#settings/account) page. Click `Create Access Token` button and you will get access_token. |
| 48 | + |
| 49 | +You need to put it to `config/services.php` configuration file. You may copy the example configuration below to get started: |
| 50 | +```php |
| 51 | +'pushbullet' => [ |
| 52 | + 'access_token' => env('PUSHBULLET_ACCESS_TOKEN') |
| 53 | +] |
| 54 | +``` |
| 55 | + |
| 56 | +## Usage |
| 57 | + |
| 58 | +### Routing Pushbullet notifications |
| 59 | +In order to send notifications to Pushbullet you need to specify recipient for each notifiable entity. There are currently 2 options: pushbullet email or device id of recipient. |
| 60 | +To provide library with correct notification recipient you need to define `routeNotificationForTelegram` method on notifiable entity. |
| 61 | + |
| 62 | +#### Sending notification to email: |
| 63 | +```php |
| 64 | +public function routeNotificationForTelegram() |
| 65 | +{ |
| 66 | + return new \NotificationChannels\Pushbullet\Targets\Email($this->email); |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +#### Sending notification to device id: |
| 71 | +```php |
| 72 | +public function routeNotificationForTelegram() |
| 73 | +{ |
| 74 | + return new \NotificationChannels\Pushbullet\Targets\Device($this->pushbullet_device_id); |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +#### Third option: |
| 79 | +Although, this option is not recommended, you might just return a string (email or device id) and library will do its best to determine if it email or device id. |
| 80 | +```php |
| 81 | +public function routeNotificationForTelegram() |
| 82 | +{ |
| 83 | + return $this->email; |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +### `via` Method |
| 88 | +On notification entity just add `\NotificationChannels\Pushbullet\PushbulletChannel::class` item to array that is returned from `via` method. |
| 89 | + |
| 90 | +### `toPushbullet` Method |
| 91 | +In your notification class you also should define `toPushbullet` method which will return instance of `\NotificationChannels\Pushbullet\PushbulletMessage`. |
| 92 | +```php |
| 93 | +/** |
| 94 | + * Get the telegram representation of the notification. |
| 95 | + * |
| 96 | + * @param mixed $notifiable |
| 97 | + * @return \NotificationChannels\Pushbullet\PushbulletMessage |
| 98 | + */ |
| 99 | +public function toPushbullet($notifiable) |
| 100 | +{ |
| 101 | + $url = url('/invoice/' . $this->invoice->id); |
| 102 | + |
| 103 | + return (new PushbulletMessage) |
| 104 | + ->note() // or link() |
| 105 | + ->title('One of your invoices has been paid!') |
| 106 | + ->message('Thank you for using our application!'); |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +#### Available Message methods |
| 111 | +- `note()`: set notification type to note (title and message for notification are available) |
| 112 | +- `link()`: set notification type to link (title, message and url are available) |
| 113 | +- `title($title)`: (string) set notification title |
| 114 | +- `message($message)`: (string) set notification message |
| 115 | +- `url($url)`: (string) set notification url (will be in notification if type is `link`) |
| 116 | + |
| 117 | +## Contributing |
| 118 | + |
| 119 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 120 | + |
| 121 | +## Credits |
| 122 | + |
| 123 | +- [Alex Plekhanov](https://github.com/alexsoft) |
| 124 | +- [All Contributors](../../contributors) |
| 125 | + |
| 126 | +## License |
| 127 | + |
| 128 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments