๐จ๐จ๐จ Very much a work in progress so expect very rough edges! ๐จ๐จ๐จ
Find out more about Chatkit here.
You can get the Chatkit PHP SDK via a composer package called pusher-chatkit-server
. See https://packagist.org/packages/pusher/pusher-chatkit-server
$ composer require pusher/pusher-chatkit-server
Or add to composer.json
:
"require": {
"pusher/pusher-chatkit-server": "^0.1.1"
}
and then run composer update
.
Or you can clone or download the library files.
We recommend you use composer.
This library depends on PHP modules for cURL and JSON. See cURL module installation instructions and JSON module installation instructions.
Head to your dashbord to find your instance_locator
and key
and use them to create a new Chatkit\Chatkit
instance.
$instance_locator = 'YOUR_INSTANCE_LOCATOR';
$key = 'YOUR_KEY';
$chatkit = new Chatkit\Chatkit($instance_locator, $key, array());
To generate token pair (access token and refresh token) for usage by a Chatkit client use the generate_token_pair
function.
$chatkit->generate_token_pair(array(
"user_id" => "ham"
))
To create a user you must provide an id
and a name
. You can optionally provide an avatar_url (string)
and custom_data (array)
.
$chatkit->create_user("ham", "Hamilton Chapman")
Or with an avatar_url
and custom_data
:
$chatkit->create_user(
"ham",
"Hamilton Chapman"
"http://cat.com/cat.jpg",
array(
"my_custom_key" => "some data"
)
)
To update a user you must provide an id
. You can optionally provide a name (string)
, an avatar_url (string)
and custom_data (array)
. One of the three optional fields must be provided.
$chatkit->update_user("ham", "Hamilton Chapman")
Or with an avatar_url
and custom_data
:
$chatkit->update_user(
"ham",
"Hamilton Chapman"
"http://cat.com/cat.jpg",
array(
"my_custom_key" => "some data"
)
)
To send a message you must provide a user id
, a room_id
and the text
.
$chatkit->send_message(1001, "This is a wonderful message.")