shalvah / pusher-chatkit-laravel
Laravel wrapper for the Chatkit PHP SDK
Installs: 12 153
Dependents: 0
Suggesters: 0
Security: 0
Stars: 22
Watchers: 2
Forks: 7
Open Issues: 0
Requires
- php: ^7.0
- graham-campbell/manager: ^3.0 || ^4.0
- illuminate/contracts: ^5.5 || ^6.0 || ^7.0
- illuminate/support: ^5.5 || ^6.0 || ^7.0
- pusher/pusher-chatkit-server: ^1.0.0
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/testbench: ^3.5 || ^4.0 || ^5.0
- phpunit/phpunit: ^6.3
README
ChatKit is shutting down - https://blog.pusher.com/narrowing-our-product-focus
Laravel wrapper for Pusher Chatkit. Find out more about Chatkit here.
Note: This package requires Laravel 5.5 or above
Installation
composer require shalvah/pusher-chatkit-laravel
The package will automatically make use of the latest stable version of the Chatkit PHP library (currently 1.1.0).
Quick start
Publish the config file by running:
php artisan vendor:publish --provider="Chatkit\Laravel\ChatkitServiceProvider"
This will create a config/chatkit.php
file in your app that you can modify to match your configuration.
Retrieve your Chatkit app details from your Chatkit app dashboard and add them in your .env
file like so:
CHATKIT_INSTANCE_LOCATOR=your-instance-locator CHATKIT_KEY=your-key
That's it. You can use Chatkit via the facade in your app:
<?php use Chatkit\Laravel\Facades\Chatkit; public function startChatting() { Chatkit::createUser(['id' => 'hc', 'name' => 'Hamilton Chapman']); Chatkit::createRoom(['creator_id' => 'hc', 'name' => 'Cat Lovers']); Chatkit::sendMessage(['sender_id' => 'hc', 'room_id' => 'r001', 'text' => 'Hi, everyone!' ]); }
Alternatively, you may inject the ChatkitManager
into your methods:
<?php use Chatkit\Laravel\ChatkitManager; public function startChatting(ChatkitManager $chatkitManager) { $chatkitManager->createUser(['id' => 'hc', 'name' => 'Hamilton Chapman']); $chatkitManager->createRoom(['creator_id' => 'hc', 'name' => 'Cat Lovers']); $chatkitManager->sendMessage([ 'sender_id' => 'hc', 'room_id' => 'r001', 'text' => 'Hi, everyone!' ]); }
Configuration
The config/chatkit.php
file allows you to configure your Chatkit usage (for instance, to use multiple connections).
Working with Multiple Connections
Supposing you have to work with multiple chat apps from the same server. You can do this easily by publishing the config file as explained above, then configuring your various connections in it as needed. You can then switch connections as needed using either the facade or Manager class:
<?php // use whatever connection is default -- by default, this is 'main' Chatkit::createRoom(['creator_id' =>'admin', 'name' => 'Just Chat']); // use the 'main' connection Chatkit::connection('main')->createRoom(['creator_id' =>'admin', 'name' => 'Just Chat']); // use the 'test' connection Chatkit::connection('test')->createRoom('admin', ['name' => 'Just Chat']); // use the 'secondary' connection Chatkit::setDefaultConnection('secondary'); Chatkit::createRoom(['creator_id' =>'admin', 'name' => 'Just Chat']);
Documentation
A complete listing of available methods is available at the Chatkit PHP SDK docs.
License
MIT