toitzi / novu-notifications-laravel
Novu Notifications channel for Laravel.
Fund package maintenance!
toitzi
www.paypal.com/paypalme/toitzi
Requires
- php: ^8.3
- guzzlehttp/guzzle: ^7.0.1
- illuminate/notifications: ^10.0
- illuminate/support: ^10.0
Requires (Dev)
- laravel/pint: ^v1.13.7
- pestphp/pest: ^v2.28.1
This package is auto-updated.
Last update: 2024-04-25 07:12:41 UTC
README
Novu - Laravel Notification Channel
This package makes it easy to send notifications using Novu
class InvoicePaidNotification extends Notification { // Trigger a specific notification event public function toNovuEvent($notifiable) { return NovuMessage::create('workflow_1234') ->addVariable('invoice_id', $this->invoice->id) ->toSubscriberId('123456789'); } }
Contents
Installation
The Novu notification channel can be installed easily via Composer:
$ composer require toitzi/novu-notifications-laravel
Usage
In order to send a notification via the Novu channel, you'll need to specify the channel in the via()
method of your notification:
use NotificationChannels\Novu\NovuChannel; public function via($notifiable) { return [ NovuChannel::class ] }
API Overview
Novu Message
Namespace: NotificationChannels\Novu\NovuMessage
The NovuMessage
class encompasses an entire message that will be sent to the Novu API.
static create(?string $workflowId)
Instantiates and returns a newNovuMessage
instance, optionally pre-configuring it with the workflow idworkflowId(string $workflowId)
Set theworkflowId
of the message (Your novu workflow trigger id)to(array $to)
Array of recipient information likesubscriberId
,phone
, etc...toSubscriber(string $subscriberId)
Set thesubscriberId
of the recipientvariables(array $variables)
Set the variables (payload
) of the message. Those are your novu event variablesaddVariable(string $key, $value)
Add a single variable to the messagetoArray()
Returns the data that will be sent to the Novu API as an array
Testing
Run the tests with:
$ composer test
License
The MIT License (MIT). Please see License File for more information.