This package adds a Laravel Notification Channel to sent messages via ntfy. It's build on top of the verifiedjoseph/ntfy-php-library package.
Install the package via composer:
composer require wijourdil/ntfy-notification-channel
Publish the config file with:
php artisan vendor:publish --tag="ntfy-notification-channel-config"
If you are using the online version https://ntfy.sh, you don't need to configure the server base url.
But if you are using a self-hosted version of ntfy, you can configure it in your .env
file:
NTFY_SERVER=https://ntfy.example.com
By default, authentication is disabled. If you want to connect using credentials, you can also configure it within you .env
file:
NTFY_AUTH_ENABLED=true
NTFY_AUTH_USERNAME=michel
NTFY_AUTH_PASSWORD=m0tDeP4ss3
To see default values and other settings, see the config/ntfy-notification-channel.php
config file.
In your Notification class, tell Laravel to send your notification via ntfy
by returning the NtfyChannel::class
in the via()
method:
use Wijourdil\NtfyNotificationChannel\Channels\NtfyChannel;
public function via($notifiable)
{
return [NtfyChannel::class];
}
Then, define a toNtfy()
method in your Notification:
use Ntfy\Message;
public function toNtfy(mixed $notifiable): Message
{
$message = new Message();
$message->topic('test');
$message->title('It works!');
$message->body("And voila, I sent my notification using ntfy.sh!");
$message->tags(['white_check_mark', 'ok_hand']);
return $message;
}
Here is what the notification looks like using the ntfy mobile app:
composer test
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.