Coder Social home page Coder Social logo

chatkit-server-php's Introduction

๐Ÿšจ๐Ÿšจ๐Ÿšจ 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.")

chatkit-server-php's People

Contributors

hamchapman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.