laravel-notification-channels / pushover
Laravel 的 Pushover 通知。
4.0.0
2024-03-20 08:14 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0.1
- illuminate/notifications: ^8.0 || ^9.0 || ^10.0 || ^11.0
- illuminate/support: ^8.0 || ^9.0 || ^10.0 || ^11.0
Requires (Dev)
- dms/phpunit-arraysubset-asserts: >=0.1.0
- mockery/mockery: ^1.3.1
- orchestra/testbench: ^8.0 || ^9.0
- phpunit/phpunit: ^9.3 || ^10.5
Suggests
- ext-exif: Required for image attachment support
README
此包使得使用 Laravel 通知发送 Pushover 通知变得简单。
内容
安装
您可以通过 composer 安装此包
composer require laravel-notification-channels/pushover
设置你的 Pushover 账户
要开始通过 Pushover 发送消息,您必须 注册一个应用程序。将生成的 Pushover 应用程序令牌添加到服务配置文件中
// config/services.php 'pushover' => [ 'token' => 'YOUR_APPLICATION_TOKEN', ],
使用方法
现在您可以在通知中的 via()
方法内使用该通道,以及发送推送通知
use NotificationChannels\Pushover\PushoverChannel; use NotificationChannels\Pushover\PushoverMessage; use Illuminate\Notifications\Notification; class AccountApproved extends Notification { public function via($notifiable) { return [PushoverChannel::class]; } public function toPushover($notifiable) { return PushoverMessage::create('The invoice has been paid.') ->title('Invoice paid') ->sound('incoming') ->lowPriority() ->url('http://example.com/invoices', 'Go to your invoices'); } }
要向通知的可通知实体发送 Pushover 通知,请将 routeNotificationForPushover
方法添加到该模型中。通常,这是用户模型。pushover_key
可以是数据库字段,并由用户自行编辑。
public function routeNotificationForPushover() { return $this->pushover_key; }
高级使用和配置
如果您想指定特定的设备,可以返回一个 PushoverReceiver
对象。
public function routeNotificationForPushover() { return PushoverReceiver::withUserKey('pushover-key') ->toDevice('iphone') ->toDevice('desktop') // or, if you prefer: ->toDevice(['iphone', 'desktop']); }
如果您想(动态地)覆盖服务配置中的应用程序令牌,例如,因为每个用户都有自己的应用程序令牌,可以返回一个如下的 PushoverReceiver
对象
public function routeNotificationForPushover() { return PushoverReceiver::withUserKey('pushover-key') ->withApplicationToken('app-token'); }
您还可以向 Pushover 群组发送消息
public function routeNotificationForPushover() { return PushoverReceiver::withGroupKey('pushover-group-key'); }
可用的消息方法
变更日志
请参阅 变更日志 了解最近发生了什么变化。
测试
$ composer test
安全性
如果您发现任何与安全相关的问题,请通过电子邮件 mail@casperboone.nl 而不是使用问题跟踪器。
贡献
请参阅 CONTRIBUTING 以获取详细信息。
鸣谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。