Skip to content

thecodearcher/chatkit-server-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚨🚨🚨 Very much a work in progress so expect very rough edges! 🚨🚨🚨

Chatkit PHP Server SDK

Find out more about Chatkit here.

Installation

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.

Chatkit constructor

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());

Generating a token pair

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

Creating a user

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

Updating a user

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

Send a message

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.")

About

PHP SDK for Pusher Chatkit

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%