Laravel 5.3+ 通知 Pushbullet 驱动

1.5.0 2023-04-17 19:55 UTC

README

Laravel Pushbullet 通知通道

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

此包使得在 Laravel 5.5+、6.x、7.x 和 8.x 中使用 Pushbullet 发送通知变得容易。

内容

安装

要获取 Laravel 5.3 Pushbullet 通知通道的最新版本,只需使用 Composer 需求项目

$ composer require laravel-notification-channels/pushbullet

或者您可以手动更新您的 require 块并运行 composer update

{
    "require": {
        "laravel-notification-channels/pushbullet": "^1.0"
    }
}

设置 Pushbullet 服务

在您的 Pushbullet 账户中,转到 账户设置 页面。点击 创建访问令牌 按钮,您将获得 access_token。

您需要将其放入 config/services.php 配置文件中。您可以将下面的示例配置复制过来开始

'pushbullet' => [
    'access_token' => env('PUSHBULLET_ACCESS_TOKEN')
]

用法

路由 Pushbullet 通知

为了将通知发送到 Pushbullet,您需要为每个可通知实体指定接收者。目前有两种选择:pushbullet 电子邮件或接收者的设备 ID。要为库提供正确的通知接收者,您需要在可通知实体上定义 routeNotificationForPushbullet 方法。

通过电子邮件发送通知

public function routeNotificationForPushbullet()
{
    return new \NotificationChannels\Pushbullet\Targets\Email($this->email);
}

通过设备 ID 发送通知

public function routeNotificationForPushbullet()
{
    return new \NotificationChannels\Pushbullet\Targets\Device($this->pushbullet_device_id);
}

向具有标记的通道的所有订阅者发送通知

public function routeNotificationForPushbullet()
{
    return new \NotificationChannels\Pushbullet\Targets\Channel($this->channel_tag);
}

向用户的全部设备发送通知

public function routeNotificationForPushbullet()
{
    return new \NotificationChannels\Pushbullet\Targets\UserDevices();
}

via 方法

在通知实体上,只需将 \NotificationChannels\Pushbullet\PushbulletChannel::class 项目添加到从 via 方法返回的数组中。

toPushbullet 方法

在您的通知类中,您还应该定义 toPushbullet 方法,该方法将返回 \NotificationChannels\Pushbullet\PushbulletMessage 实例。

/**
 * Get the pushbullet representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \NotificationChannels\Pushbullet\PushbulletMessage
 */
public function toPushbullet($notifiable)
{
    $url = url('/invoice/' . $this->invoice->id);

    return PushbulletMessage::create('Thank you for using our application!')
        ->link()
        ->title('One of your invoices has been paid!')
        ->url($url);
}

可用的消息方法

  • note():将通知类型设置为笔记(通知可用标题和消息)
  • link():将通知类型设置为链接(通知可用标题、消息和 URL)
  • title($title):(字符串) 设置通知标题
  • message($message):(字符串) 设置通知消息
  • url($url):(字符串) 设置通知 URL(如果类型是 link,则将在通知中显示)

变更日志

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

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件 themsaid@gmail.com 反馈,而不是使用问题跟踪器。

贡献

有关详细信息,请参阅 CONTRIBUTING

致谢

许可证

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