Via Composer
$ composer require shapintv/talkjs
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);
// 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');
// 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');
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...
The MIT License (MIT). Please see License File for more information.