nero/laravel-expo-notifier

使用 Laravel 轻松发送 Expo 通知。

安装: 10

依赖: 0

建议: 0

安全: 0

星标: 0

关注者: 0

分支: 11

类型:插件

0.0.20 2024-07-20 16:14 UTC

This package is auto-updated.

Last update: 2024-09-20 16:40:43 UTC


README

使用 Laravel 轻松管理 Expo 通知。支持批量通知。

Latest Version GitHub Workflow Status Total Downloads

主要版本零(0.y.z)用于初始开发。任何内容在任何时候都可能发生变化。公共 API 不应被视为稳定。

安装

composer require nero/laravel-expo-notifier

配置

您必须使用以下命令发布配置文件

php artisan vendor:publish --provider="YieldStudio\LaravelExpoNotifier\ExpoNotificationsServiceProvider" --tag="expo-notifications-config" --tag="expo-notifications-migration"

可用的环境变量

  • EXPO_PUSH_NOTIFICATIONS_PER_REQUEST_LIMIT : 设置批量请求中发送的最大通知数量。 官方文档表示限制应为 100 但实际上失败了。您可以通过设置小于 100 的值来调整。

使用

发送通知

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use YieldStudio\LaravelExpoNotifier\ExpoNotificationsChannel;
use YieldStudio\LaravelExpoNotifier\Dto\ExpoMessage;

class NewSampleNotification extends Notification
{
    public function via($notifiable): array
    {
        return [ExpoNotificationsChannel::class];
    }

    public function toExpoNotification($notifiable): ExpoMessage
    {
        return (new ExpoMessage())
            ->expoTokenId($notifiable->expoTokens->id)
            ->to([$notifiable->expoTokens->value])
            ->title('A beautiful title')
            ->body('This is a content')
            ->channelId('default');
    }
}

命令使用

发送数据库挂起的通知

php artisan expo:notifications:send

从过时的令牌中清理票据

php artisan expo:tickets:check

您可以为这些命令创建计划。

批量支持

您可以在下一个批次中发送通知

(new ExpoMessage())
    ->expoTokenId($notifiable->expoTokens->id)
    ->to([$notifiable->expoTokens->value])
    ->title('A beautiful title')
    ->body('This is a content')
    ->channelId('default')
    ->shouldBatch();

别忘了安排 expo:notifications:send 命令。

单元测试

要运行测试,只需运行 composer installcomposer test

变更日志

请参阅 CHANGELOG 了解最近更改的更多信息。

贡献

请参阅 CONTRIBUTING 了解详细信息。

安全

如果您发现有关安全的错误,请通过邮件发送 contact@yieldstudio.fr 而不是使用问题跟踪器。

致谢

许可证

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