techinasia/laravel-stream-notification-channel

v1.0.0 2017-02-08 09:47 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:20:09 UTC


README

Dependency Status Build Status Coverage Status StyleCI Status

使用 Laravel 5.3 通知将活动发送到 Stream。

内容

安装

使用 Composer 安装此包

composer require techinasia/laravel-stream-notification-channel-notification-channel

在您的 config/app.php 中注册服务提供者

NotificationChannels\GetStream\StreamServiceProvider::class

设置 Stream

此通知通道使用 techinasia/laravel-stream 将通知发送到 Stream。

发布所有供应商资产

php artisan vendor:publish

这将创建一个名为 stream.php 的文件在 config 文件夹中。通过 Stream 的 管理界面创建一个应用程序,并将 API 密钥和密钥复制到配置文件中。

您可以通过在配置文件中添加更多的密钥/密钥对来添加更多应用程序

'applications' => [
    'main' => [
        'key' => 'key1',
        'secret' => 'secret1',
    ],
    'foo' => [
        'key' => 'foo',
        'secret' => 'bar',
    ],
],

使用方法

在通知中使用 Stream 发送通知

use NotificationChannels\GetStream\StreamChannel;
use NotificationChannels\GetStream\StreamMessage;
use Illuminate\Notifications\Notification;

class TestNotification extends Notification
{
    public function via($notifiable)
    {
        return [StreamChannel::class];
    }

    public function toStream($notifiable)
    {
        return (new StreamMessage())
            ->actor(1)
            ->verb('like')
            ->object(3)
            ->foreignId('post:42');
    }
}

您需要通过在实体上定义一个 routeNotificationForStream 方法来指定通知的可通知对象的 ID 和类型

/**
 * Notification routing information for Stream.
 *
 * @return array
 */
public function routeNotificationForStream()
{
    return [
        'type' => 'user',
        'id' => $this->id,
    ];
}

可用的消息方法

  • application(string $application): 设置用于发送通知的应用程序。

您可以通过调用名称为驼峰式的属性名称并将值作为参数来设置有效载荷的任何属性

return (new StreamMessage())
    ->actor(1)
    ->verb('like')
    ->object(3);

更新日志

请参阅 CHANGELOG 获取有关最近更改的更多信息。

测试

composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件 dev@techinasia.com 向我们报告,而不是使用问题跟踪器。

贡献

请参阅 CONTRIBUTING 以获取详细信息。

鸣谢

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 获取更多信息。