diff --git a/src/SlackRTMDriver.php b/src/SlackRTMDriver.php index 680a2be..b10e07f 100644 --- a/src/SlackRTMDriver.php +++ b/src/SlackRTMDriver.php @@ -42,6 +42,8 @@ class SlackRTMDriver implements DriverInterface protected $file; + protected $messages = []; + /** * Driver constructor. * @param array $config @@ -54,6 +56,7 @@ public function __construct(array $config, RealTimeClient $client) $this->client = $client; $this->client->on('_internal_message', function ($type, $data) { + $this->messages = []; $this->event = Collection::make($data); if ($type !== 'message') { $this->slackEventData = [$type, $data]; @@ -174,6 +177,18 @@ private function convertQuestion(Question $question) * @return array */ public function getMessages() + { + if (empty($this->messages)) { + $this->loadMessages(); + } + + return $this->messages; + } + + /** + * Load Slack messages. + */ + protected function loadMessages() { $messageText = $this->event->get('text'); @@ -213,7 +228,7 @@ public function getMessages() $message = new IncomingMessage($messageText, $user_id, $channel_id, $this->event); $message->setIsFromBot($this->isBot()); - return [$message]; + $this->messages = [$message]; } /**