• Модуль: imconnector
  • Путь к файлу: ~/bitrix/modules/imconnector/lib/connectors/telegrambot.php
  • Класс: BitrixImConnectorConnectorsTelegramBot
  • Вызов: TelegramBot::sendAutomaticMessage
public function sendAutomaticMessage(string $messageText, string $crmEntityType, int $crmEntityId): ?int
{
	if (!Loader::includeModule('imopenlines'))
	{
		return null;
	}
	$entityData = ImOpenLinesCrmCommon::get($crmEntityType, $crmEntityId, true);

	$lastTelegramImol = null;
	if (isset($entityData['FM']['IM']['TELEGRAM']) && is_array($entityData['FM']['IM']['TELEGRAM']))
	{
		$lastTelegramImol = end($entityData['FM']['IM']['TELEGRAM']);
	}

	if (!$lastTelegramImol)
	{
		return null;
	}

	$telegramUserCode = mb_substr($lastTelegramImol, 5); //cut "imol|"
	$chat = $this->getChat(['USER_CODE' => $telegramUserCode]);
	$chatId = $chat->getData('ID');
	if (!$chatId)
	{
		return null;
	}

	return $this->sendMessage($messageText, $chatId);
}