Skip to content
This repository was archived by the owner on Oct 8, 2019. It is now read-only.
Pascal Boucher edited this page Sep 3, 2018 · 6 revisions

Shortcuts

Creating a User - Batch Creating Users - Get User - Get Users - Get Users by IDs - Updating a User - Deleting a User - Get User Rooms - Join a Room - Leave a Room

Creating a User (sudo)

This method requires a sudo token.

@param  array $user
@return \Chess\Chatkit\Models\User

Chatkit::users()->store($user);

id (string|required): User id assigned to the user in your app.

name (string|required): Name of the new user.

avatar_url (string|optional): A link to the user's photo/image.

custom_data (array|optional): Custom data that may be associated with a user.

Example

$user = Chatkit::users()->store([
    'id' => $userId,
    'name' => 'John Doe',
    'avatar_url' => 'https://placekitten.com/200/300',
    'custom_data' => [
        'my_custom_key' => 'some data'
    ]
]);

Api reference

Batch Creating Users (sudo)

This method requires a sudo token.

@param  array $users
@return \Illuminate\Support\Collection

Chatkit::users()->storeMultiple($users);

See Creating a User for $users required values

Example

$users = Chatkit::users()->storeMultiple([
    [
        'id' => $rockyId,
        'name' => 'Rocky Balboa',
        'avatar_url' => 'https://placekitten.com/200/300',
        'custom_data' => [
            'my_custom_key' => 'some data'
        ]
    ],
    [
        'id' => $harryId,
        'name' => 'Harry Potter',
        'avatar_url' => 'https://placekitten.com/200/300',
        'custom_data' => [
            'my_custom_key' => 'some data'
        ]
    ],
    [
        'id' => $arthurId,
        'name' => 'Arthur Dent',
        'avatar_url' => 'https://placekitten.com/200/300',
        'custom_data' => [
            'my_custom_key' => 'some data'
        ]
    ]
]);

Api reference

Get User

@param  string $userId
@return \Chess\Chatkit\Models\User

Example

$user = Chatkit::users()->show($userId);

Api reference

Get Users

@param  string $fromTs
@return \Illuminate\Support\Collection

The number of users returned is 20.

$fromTs (string|optional): Timestamp (inclusive) from which users with a more recent created_at should be returned. The timestamp should use the ISO 8601 notation; specifically the B8601DZw.d format. An example of a timestamp in this format is 2018-04-17T14:02:00Z.

Examples

$users = Chatkit::users()->index();

OR with $fromTs

$users = Chatkit::users()->index('2018-04-17T14:02:00Z');

Api reference

Get Users by IDs

@param  array $usersIds
@return \Illuminate\Support\Collection

Examples

$users = Chatkit::users()->showMultiple([$userIdOne, $userIdTwo, $userIdThree]);

Api reference

Updating a User

@param  string $userId
@param  array  $userData
@return bool

Chatkit::users()->update($userId, $userData);

name (string|optional): Updated name for the user.

avatar_url (string|optional): Updated user image link.

custom_data (array|optional): Updated custom data.

Example

// User ID in request must match User ID in access token

Chatkit::withUser($userId);

$updated = Chatkit::users()->update($userId, [
    'name' => 'Jake',
    'avatar_url' => 'https://imgur.com/img/6987',
    'custom_data' => ['email' => 'jake@example.com']
]);

The user must also have the right set of permission to perform this action. See Roles & Permissions for details.

If you want to use only your own policies, you can always use :

Chatkit::withSudoUser($userId);

to bypass Chatkit restrictions.

Api reference

Deleting a User (sudo)

This method requires a sudo token.

@param  string $userId
@return bool

Example

$deleted = Chatkit::users()->destroy($userId);

Api reference

Get User Rooms

@param  string $userId
@return \Illuminate\Support\Collection

joinable (boolean): Indicates if only rooms that the user can join should be returned.

Examples

$user = new \Chess\Chatkit\Models\User($userId);

$rooms = $user->rooms()->get();

Or with Joinable

$user = new \Chess\Chatkit\Models\User($userId);

$rooms = $user->rooms()->joinable()->get();

Api reference

Join a Room

@param  string $userId
@param  int    $roomId
@return \Chess\Chatkit\Models\Room

Example

// User ID in request must match User ID in access token

Chatkit::withUser($userId);

$user = new \Chess\Chatkit\Models\User($userId);

$room = $user->room($roomId)->join();

Api reference

Leave a Room

@param  string $userId
@param  int    $roomId
@return bool

Example

// User ID in request must match User ID in access token

Chatkit::withUser($userId);

$user = new \Chess\Chatkit\Models\User($userId);

$leaved = $user->room($roomId)->leave();

Api reference