jamie4224/pushover

Laravel 的 Pushover 通知。

3.0.2 2022-04-09 11:10 UTC

This package is auto-updated.

Last update: 2024-09-09 16:22:15 UTC


README

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads

此包简化了使用 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('') 设置。

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件 mail@casperboone.nl 而不是使用问题跟踪器来报告。

贡献

有关详细信息,请参阅 CONTRIBUTING

致谢

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件