wijourdil / ntfy-notification-channel
ntfy.sh 通知通道用于 Laravel
3.0.0
2024-04-17 12:37 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^11.0
- spatie/laravel-package-tools: ^1.13.0
- thecodingmachine/safe: ^2.4
- verifiedjoseph/ntfy-php-library: ^4.0
- webmozart/assert: ^1.11
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.1
- orchestra/testbench: ^9.0
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpstan/phpstan-webmozart-assert: ^1.2
- phpunit/phpunit: ^10.1
- thecodingmachine/phpstan-safe-rule: ^1.2
README
此包为 Laravel 添加了一个通知通道,用于通过 ntfy 发送消息。它基于 verifiedjoseph/ntfy-php-library 包构建。
安装
通过 composer 安装此包
composer require wijourdil/ntfy-notification-channel
使用以下命令发布配置文件
php artisan vendor:publish --tag="ntfy-notification-channel-config"
配置
如果您使用的是在线版本 https://ntfy.sh,则不需要配置服务器基本 URL。但如果您使用的是自托管版本的 ntfy,您可以在您的 .env
文件中配置它
NTFY_SERVER=https://ntfy.example.com
默认情况下,认证已禁用。如果您想使用凭据进行连接,您也可以在您的 .env
文件中配置它
NTFY_AUTH_ENABLED=true NTFY_AUTH_USERNAME=michel NTFY_AUTH_PASSWORD=m0tDeP4ss3
要查看默认值和其他设置,请参阅 config/ntfy-notification-channel.php
配置文件。
使用方法
在您的通知类中,通过在 via()
方法中返回 NtfyChannel::class
来告诉 Laravel 通过 ntfy 发送通知
use Wijourdil\NtfyNotificationChannel\Channels\NtfyChannel; public function via($notifiable) { return [NtfyChannel::class]; }
然后在您的通知中定义一个 toNtfy()
方法
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; }
以下是使用 ntfy 移动应用 的通知外观
测试
composer test
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件