/** * {@inheritDoc} */ public function postMessage(Message $message) { if (!$this->connected) { return Promise\reject(new ConnectionException('Client not connected. Did you forget to call `connect()`?')); } // We can't send attachments using the RTM API, so revert to the web API // to send the message if ($message->hasAttachments()) { return parent::postMessage($message); } $data = ['id' => ++$this->lastMessageId, 'type' => 'message', 'channel' => $message->data['channel'], 'text' => $message->getText()]; $this->websocket->send(json_encode($data)); // Create a deferred object and add message to pending list so when a // success message arrives, we can de-queue it and resolve the promise. $deferred = new Promise\Deferred(); $this->pendingMessages[$this->lastMessageId] = $deferred; return $deferred->promise(); }
public function __construct(LoopInterface $loop, $token, ClientInterface $httpClient = null) { parent::__construct($loop, $httpClient); $this->setToken($token); }