/** * {@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 testHasAttachmentsIsTrueWhenAttachments() { $message = new Message($this->client, ['attachments' => [new Attachment($this->faker->title, $this->faker->sentence)]]); $this->assertTrue($message->hasAttachments()); }
/** * Posts a message. * * @param \Slack\Message\Message $message The message to post. * * @return \React\Promise\PromiseInterface */ public function postMessage(Message $message) { $options = ['text' => $message->getText(), 'channel' => $message->data['channel'], 'as_user' => true]; if ($message->hasAttachments()) { $options['attachments'] = json_encode($message->getAttachments()); } return $this->apiCall('chat.postMessage', $options); }