/** * @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())); } }