-
Notifications
You must be signed in to change notification settings - Fork 819
Closed
Labels
Description
The Slack RTM driver currently has an empty types()
method. I've tried to implement the typing indicator using the RTM API (documentation). It works in the sense that the typing indicator is shown, but for some reason the indicator appears only after the reply has been sent. The result is the same regardless of the sleep time (I tried with 10 seconds and 1 second). Do you have any ideas why showing the typing indicator is deferred like this? Is it related to websocket calls vs. HTTP API calls?
slack-client / RealTimeClient.php:
public function setAsTyping(ChannelInterface $channel)
{
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));
}
botman / SlackRTMDriver.php:
public function types(Message $matchingMessage)
{
$channel = null;
$this->getChannel($matchingMessage)->then(function ($_channel) use (&$channel) {
$channel = $_channel;
});
if (is_null($channel)) {
$this->client->getDMById($matchingMessage->getChannel())->then(function ($_channel) use (&$channel) {
$channel = $_channel;
});
}
if (! is_null($channel)) {
$this->client->setAsTyping($channel);
}
}
test:
$loop = Factory::create();
$config = ['slack_token' => 'SLACK_TOKEN_HERE'];
$botMan = BotManFactory::createForRTM($config, $loop);
$botMan->hears('ping', function(BotMan $bot) {
// Simulate typing
$bot->typesAndWaits(1);
// Respond
$bot->reply('Pong');
});
$loop->run();
Thanks for an awesome library! 😎