Skip to content

Commit

Permalink
Add method for setting typing indicator (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
crocodele authored and mpociot committed Apr 2, 2017
1 parent 16a5ffe commit 906d979
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/RealTimeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,36 @@ public function postMessage(Message $message)
return $deferred->promise();
}

/**
* Set as typing
*
* @param \Slack\ChannelInterface $channel The channel to set typing indicator in.
* @param bool $callDeferred Whether to call the API asynchronous or not.
*
* @return \React\Promise\PromiseInterface
*/
public function setAsTyping(ChannelInterface $channel, $callDeferred = true)
{
if (!$this->connected) {
return Promise\reject(new ConnectionException('Client not connected. Did you forget to call `connect()`?'));
}

$data = [
'id' => ++$this->lastMessageId,
'type' => 'typing',
'channel' => $channel->data['id'],
];
$this->websocket->send(json_encode($data));

// Perform an iteration of the event loop in order to send the
// web socket message synchronously
if (!$callDeferred) {
$this->loop->tick();
}

return Promise\resolve();
}

/**
* Returns whether the client is connected.
*
Expand Down

0 comments on commit 906d979

Please sign in to comment.