laraditz/realm-chat

Laravel wrapper for Realm Chat SDK

1.0.0 2022-10-19 09:43 UTC

This package is auto-updated.

Last update: 2024-04-19 15:27:00 UTC


README

Latest Version on Packagist Total Downloads GitHub Actions

Laravel wrapper for Realm Chat SDK. Includes event for receiving messages.

Installation

You can install the package via composer:

composer require laraditz/realm-chat

Before Start

Configure your variables in your .env (recommended) or you can publish the config file and change it there.

REALM_CHAT_API_KEY=<your_api_key>
REALM_CHAT_DEVICE_ID=<your_device_id>

(Optional) You can publish the config file via this command:

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

Run the migration command to create the necessary database table.

php artisan migrate

Add routeNotificationForRealmChat method to your Notifiable model.

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

Usage

Now you can use the channel in your via() method inside the notification:

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");
    }
}

Event

This package also provide an event to allow your application to listen for Realm Chat message receive. You can create your listener and register it under event below.

Event Description
Laraditz\RealmChat\Events\MessageReceived When a message comes in.

Webhook URL

You may setup the URLs below on Realm Chat dashboard so that Realm Chat will push new messages to it and it will then trigger the MessageReceived event above.

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

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email raditzfarhan@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Dependency