ccoeder/laravel-notification-webhook

Webhook Notifications driver

1.4.0 2019-08-19 19:39 UTC

This package is auto-updated.

Last update: 2024-04-20 05:49:03 UTC


README

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

This package makes it easy to send webhooks using the Laravel notification system.

This is an another fork from miladnouri/laravel-notification-webhook because I need to use with on-demand notifications so I added support for that.

Contents

Installation

You can install the package via composer:

composer require ccoeder/laravel-notification-webhook

Usage

Now you can use the channel in your via() method inside the notification:

use NotificationChannels\Webhook\WebhookMessage;
use Illuminate\Notifications\Notification;

class ProjectCreated extends Notification
{
    public function via($notifiable)
    {
        return ['webhook'];
    }

    public function toWebhook($notifiable)
    {
        return WebhookMessage::create()
            ->data([
               'payload' => [
                   'webhook' => 'data'
               ]
            ])
            ->userAgent("Custom-User-Agent")
            ->header('X-Custom', 'Custom-Header');
    }
}

In order to let your Notification know which URL should receive the Webhook data, add the routeNotificationForWebhook method to your Notifiable model.

This method needs to return the URL where the notification Webhook will receive a POST request.

public function routeNotificationForWebhook()
{
    return 'http://myrequest.com/abcd';
}

Available methods

  • data(''): Accepts a JSON-encodable value for the Webhook body.
  • userAgent(''): Accepts a string value for the Webhook user agent.
  • header($name, $value): Sets additional headers to send with the POST Webhook.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

License

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