rene-roscher/pushover

Laravel 的 Pushover 通知

3.0.0 2023-03-06 10:03 UTC

This package is not auto-updated.

Last update: 2024-09-17 15:11:11 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('') 来设置。

变更日志

有关最近更改的更多信息,请参阅变更日志

测试

$ composer test

安全

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

贡献

有关详细信息,请参阅贡献指南

致谢

许可证

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