/talkjs

A TalkJS PHP SDK

Primary LanguagePHPMIT LicenseMIT

TalkJS PHP SDK

Latest version Build status Total downloads

Install

Via Composer

$ composer require shapintv/talkjs

Usage

Create a TalkJSClient

use Shapin\TalkJS\TalkJSClient;
use Symfony\Component\HttpClient\HttpClient;

$httpClient = HttpClient::create([
    'base_uri' => 'https://api.talkjs.com/v1/'.self::APP_ID.'/',
    'auth_bearer' => self::SECRET_KEY,
    'headers' => [
        'Content-Type' => 'application/json',
    ],
]);

$talkJSClient = new TalkJSClient($httpClient);

Deal with users

// Create or update a user
$client->users()->createOrUpdate('my_custom_id', [
    'email' => 'georges@abitbol.com',
]);

// Retrieve a user
$user = $client->users()->get('my_custom_id');

Deal with conversations

// Create or update a user
$client->conversations()->createOrUpdate('my_custom_id', [
    'subject' => 'My new conversation',
]);

// Retrive a conversation
$conversation = $client->conversations()->get('my_custom_id');

// Find conversations
$conversations = $client->conversations()->find();

// Join a conversation
$client->conversation()->join('my_conversation_id', 'my_user_id');

// Leave a conversation
$client->conversation()->leave('my_conversation_id', 'my_user_id');

Integration with symfony

Create a new HttpClient:

framework:
    http_client:
        scoped_clients:
            talkjs.client:
                auth_bearer: '%env(TALKJS_SECRET_KEY)%'
                base_uri: 'https://api.talkjs.com/v1/%env(TALKJS_APP_ID)%/'
                headers:
                    'Content-Type': 'application/json'

Then create your service:

services:
    Shapin\TalkJS\TalkJSClient: ~

You're done!

One day, I may consider creating a bundle in order to bootstrap this SDK...

License

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