mmockelyn / pushover
Laravel 的 Pushover 通知。
dev-master
2022-10-03 17:03 UTC
Requires
- php: >=7.3
- guzzlehttp/guzzle: ^7.0.1
- illuminate/notifications: ^9.0
- illuminate/support: ^9.0
Requires (Dev)
- dms/phpunit-arraysubset-asserts: >=0.1.0
- mockery/mockery: ^1.3.1
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
This package is not auto-updated.
Last update: 2024-10-02 01:05:55 UTC
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'); } }
确保在您的可通知模型上有 routeNotificationForPushover
方法,例如
... 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'); }
可用的消息方法
请注意,只有消息内容是必需的,所有其他方法都是可选的。消息内容可以通过 content('')
、通过创建方法的 PushoverMessage::create('')
或通过构造函数 new PushoverMessage('')
来设置。
变更日志
有关最近更改的更多信息,请参阅 变更日志。
测试
$ composer test
安全性
如果您发现任何与安全相关的问题,请通过电子邮件 mail@casperboone.nl 而不是使用问题跟踪器来报告。
贡献
有关详细信息,请参阅 贡献。
致谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。