laraditz/realm-chat

Realm Chat SDK 的 Laravel 封装

1.0.0 2022-10-19 09:43 UTC

This package is auto-updated.

Last update: 2024-09-19 16:23:30 UTC


README

Latest Version on Packagist Total Downloads GitHub Actions

Laravel 封装 Realm Chat SDK。包括接收消息的事件。

安装

您可以通过 composer 安装此包

composer require laraditz/realm-chat

开始前

在您的 .env 中配置变量(推荐),或者您可以将配置文件发布并更改它。

REALM_CHAT_API_KEY=<your_api_key>
REALM_CHAT_DEVICE_ID=<your_device_id>

(可选)您可以通过以下命令发布配置文件

php artisan vendor:publish --provider="Laraditz\RealmChat\RealmChatServiceProvider" --tag="config"

运行迁移命令以创建必要的数据库表。

php artisan migrate

routeNotificationForRealmChat 方法添加到您的 Notifiable 模型中。

public function routeNotificationForRealmChat($notification)
{
    return $this->mobile_no;
}

用法

现在您可以在通知内部的 via() 方法中使用此通道

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Laraditz\RealmChat\RealmChatChannel;
use Laraditz\RealmChat\RealmChatMessage;

class TestNotification extends Notification
{
    use Queueable;  
  
    public function via($notifiable)
    {
        return [RealmChatChannel::class];
    }
    
    public function toRealmChat($notifiable)
    {
        return (new RealmChatMessage())
            ->content("Test send message!")
            ->media("https://news.tokunation.com/wp-content/uploads/sites/5/2022/07/Kamen-Rider-Geats-Teaser.jpeg", "Kamen-Rider-Geats-Teaser.jpeg");
    }
}

事件

此包还提供了一个事件,允许您的应用程序监听 Realm Chat 消息接收。您可以在以下事件下创建您的监听器并注册它。

Webhook URL

您可以在 Realm Chat 控制台中设置以下 URL,以便 Realm Chat 将新消息推送到它,然后触发上述 MessageReceived 事件。

https://your-app-url/realm-chat/webhooks/receive //for message receive

测试

composer test

变更日志

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

贡献

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

安全

如果您发现任何安全问题,请通过电子邮件 raditzfarhan@gmail.com 而不是使用问题跟踪器来报告。

致谢

许可证

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

依赖