• Модуль: imconnector
  • Путь к файлу: ~/bitrix/modules/imconnector/lib/connectors/base.php
  • Класс: BitrixImConnectorConnectorsBase
  • Вызов: Base::processMessageForRich
protected function processMessageForRich(array $message): array
{
	$richData = [];
	if (
		!empty($message['message']['attachments'])
		&& is_array($message['message']['attachments'])
	)
	{
		foreach ($message['message']['attachments'] as $attachment)
		{
			try
			{
				$attachment = WebJson::decode($attachment);

				if (
					isset($attachment['BLOCKS'])
					&& is_array($attachment['BLOCKS'])
				)
				{
					foreach ($attachment['BLOCKS'] as $block)
					{
						if (
							isset($block['RICH_LINK'])
							&& is_array($block['RICH_LINK'])
						)
						{
							foreach ($block['RICH_LINK'] as $richData)
							{
								if (!empty($richData))
								{
									if ($richData['LINK'])
									{
										$richData['richData']['url'] = $richData['LINK'];
									}

									if ($richData['NAME'])
									{
										$richData['richData']['title'] = $richData['NAME'];
									}

									if ($richData['DESC'])
									{
										$richData['richData']['description'] = $richData['DESC'];
									}

									if ($richData['PREVIEW'])
									{
										$uri = new Uri($richData['PREVIEW']);
										if ($uri->getHost())
										{
											$richData['richData']['image'] = $richData['PREVIEW'];
										}
										else
										{
											$richData['richData']['image'] = Connector::getDomainDefault() .'/'. $richData['PREVIEW'];
										}
									}
									elseif($richData['EXTRA_IMAGE'])
									{
										$richData['richData']['image'] = $richData['EXTRA_IMAGE'];
									}
								}
							}
						}
					}
				}
			}
			catch (BitrixMainSystemException $e)
			{
			}
		}
	}

	$message['message']['attachments'] = $richData;

	return $message;
}