/**
  * @param Message $message
  */
 public function process(Message $message)
 {
     // Only process messages where ShareMonkey is mentioned
     if ($this->shareMonkeyIsMentioned($message->getText()) === false) {
         return;
     }
     $text = $message->getText();
     $urls = $text->getUrls();
     $tags = $text->getTags();
     if (count($urls) === 0) {
         $this->logger->debug('No urls found in message');
         return;
     }
     $user = $this->userRepository->findOneBySlackId($message->getUserId());
     if (!$user instanceof User) {
         $this->logger->error(sprintf('User "%s" not found', $message->getUserId()->getValue()));
         return;
     }
     foreach ($urls as $url) {
         $this->logger->debug(sprintf('processing url %s', $url));
         $info = Embed::create($url);
         $link = Link::fromSlack($message->getId(), $user, $message->getCreatedAt(), $info->getTitle() ?: $message->getText(), $url, $tags);
         $this->objectManager->persist($link);
         $this->objectManager->flush();
         $this->objectManager->clear();
         $this->logger->debug(sprintf('Saved link %s', $link->getUrl()));
     }
 }
 /**
  * @param Payload $payload
  * @param OutputInterface $output
  */
 private function onMessage(Payload $payload, OutputInterface $output)
 {
     try {
         // Always ignore messages without a user
         if ($payload->offsetExists('user') == false) {
             return;
         }
         $message = Message::fromSlack($payload->offsetGet('text'), $payload->offsetGet('ts'), $payload->offsetGet('user'));
         $this->incomingLinkProcessor->process($message);
     } catch (\Exception $e) {
         $output->writeln(sprintf('<error>Error: %s, %s</error>', get_class($e), $e->getMessage()));
     }
 }