Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

Messages

Pascal Boucher edited this page Jun 11, 2018 · 1 revision

Shortcuts

Sending Messages - Fetch Messages From a Room - Typing Indicators

Sending Messages

@param  int $roomId
@param  array $message
@return \Chess\Chatkit\Models\Message

$room->messages()->send($message);

text (string|required): Message text.

attachment (array|optional): Attachment to send with message

  • resource_link (string|required): A valid URL to the resource being attached to the message.

  • type (string|required): The type of attachment. This can be one of image,video, audio or file.

Example

$room = new \Chess\Chatkit\Models\Room($roomId);

$message = $room->messages()->send([
    'text' => 'Test Message',
    'attachment' => [
        'resource_link' => 'https://images.com/mycoolimage.jpg',
        'type' => 'image'
    ]
]);

Api reference

Fetch Messages From a Room

@param  int $roomId
@param  int|optional $messageId
@return \Illuminate\Support\Collection

The maximum number of messages that can be fetched is 100.

initial_id (integer|optional): Starting id of the range of messages (non-inclusive).

limit (integer|optional): Number of messages to return. If left empty, the limit is set to 20 by default.

direction (string|optional): Order of messages - one of newer or older.

Example

$room = new \Chess\Chatkit\Models\Room($roomId);

$messages = $room->messages()->get();

OR with optional parameters. Note that you can chain the filters methods the way you like.

$room = new \Chess\Chatkit\Models\Room($roomId);

$messages = $room->messages()->fromId($messageId)->newer()->limit(5)->get();

// Is the same has this :

$messages = $room->messages()->get(['initial_id' => $messageId, 'direction' => 'newer', 'limit' => 5]);

Api reference

Typing Indicators

@param  int $roomId
@return bool

Examples

Start Typing

$room = new \Chess\Chatkit\Models\Room($roomId);

$typing = $room->typing()->start();

Stop Typing

$room = new \Chess\Chatkit\Models\Room($roomId);

$typing = $room->typing()->stop();

Api reference

Clone this wiki locally