• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/V2/Message.php
  • Класс: BitrixImV2Message
  • Вызов: Message::generateUrlPreview
public function generateUrlPreview(): void
{
	if ($this->getMessage())
	{
		$urls = UrlItem::getUrlsFromText($this->getMessage());
		foreach ($urls as $url)
		{
			$metadata = UrlPreview::getMetadataByUrl($url, true, false);
			if ($metadata !== false)
			{
				$urlItem = UrlItem::initByMetadata($metadata);
				if ($urlItem->getId())
				{
					$this->getParams()->get(Params::URL_ID)->addValue($urlItem->getId());
					$this->getParams()->get(Params::ATTACH)->addValue($urlItem->getUrlAttach());

					// check if message contains only link
					if ($urlItem->isStaticUrl())
					{
						$staticUrl = [$url];
						if (mb_substr($url, -1) == '/')
						{
							$staticUrl[] = mb_substr($url, 0, -1);
						}
						$checkMessage = trim(str_replace($staticUrl, '', $this->getMessage()));

						if (empty($checkMessage))
						{
							$this->getParams()->get(Params::URL_ONLY)->setValue(true);
						}
					}
				}
			}
		}
	}
}