Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Hooks Notification Channel for Laravel 5.3

License

Notifications You must be signed in to change notification settings

lukonet/laravel-hooks-notification-channel

Repository files navigation

Hooks Notifications Channel for Laravel 5.3

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

UPDATE: It seems like the Hooks service is no longer active, hence, this project has been archived.

This package makes it easy to send notifications using Hooks with Laravel 5.3.

Hooks API lets you send a notification to all users subscribed to your custom alert.

Contents

Installation

You can install the package via composer:

composer require lukonet/laravel-hooks-notification-channel

You must install the service provider:

// config/app.php
'providers' => [
    ...
    NotificationChannels\Hooks\HooksServiceProvider::class,
],

Setting up the Hooks service

  1. Sign up for a developer account on Hooks site.
  2. Get the API Key, located in the account page.
  3. Create a custom alert on alerts page.
  4. Obtain the alert id associated with your notification, located in your alerts page. It'll be used when sending a notification.

Then, configure your Hooks API Key by adding it to the config/services.php file:

// config/services.php
...
'hooks' => [
    'key' => env('HOOKS_API_KEY', 'YOUR HOOKS API KEY HERE')
],
...

Usage

You can now use the channel in your via() method inside the Notification class.

use NotificationChannels\Hooks\HooksChannel;
use NotificationChannels\Hooks\HooksMessage;
use Illuminate\Notifications\Notification;

class NewsUpdate extends Notification
{
    public function via($notifiable)
    {
        return [HooksChannel::class];
    }

    public function toHooks($notifiable)
    {
        $url = url('/news/' . $notifiable->id);

        return HooksMessage::create()
            ->alertId('<Hooks Alert ID>') // Optional.
            ->message('Laravel 5.3 launches with the all new notifications feature!')
            ->url($url);
    }
}

Here's a screenshot preview of the above notification on Hooks App:

Laravel Hooks Notification Example

Routing a message

You can either send the notification by providing with the alert id to the alertId($alertId) method like shown in the above example or add a routeNotificationForHooks() method in your notifiable model:

...
/**
 * Route notifications for the Hooks channel.
 *
 * @return int
 */
public function routeNotificationForHooks()
{
    return 'YOUR ALERT ID HERE';
}
...

Available Message methods

  • alertId($alertId): (integer) The alert id associated with your notification, located in your alerts page.
  • message(''): (string) The message of the notification.
  • url($url): (string) The related url of this notification.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.