• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/controller/integration/messengercall.php
  • Класс: BitrixDiskControllerIntegrationMessengerCall
  • Вызов: MessengerCall::attachFileToCall
protected function attachFileToCall(Call $call, File $newFile): ?AttachedObject
{
	$userId = $this->getCurrentUser()->getId();
	$chatId = $call->getAssociatedEntity()->getChatId();

	$text = Loc::getMessage("DISK_INTEGRATION_IM_CALL_CALL_DOCUMENT_CREATED");
	if ($newFile->getCode() === DocumentOnlyOfficeTemplatesCreateDocumentByCallTemplateScenario::CODE_RESUME)
	{
		$text = Loc::getMessage("DISK_INTEGRATION_IM_CALL_CALL_RESUME_CREATED");
	}

	$result = Sender::sendFileToChat(
		$newFile,
		$chatId,
		$text,
		['CALL_ID' => $call->getId()],
		$userId
	);
	if (!$result->isSuccess())
	{
		return null;
	}

	/** @var FileLink $fileInChat */
	$fileInChat = $result->getData()['IM_FILE'];
	$errorCollection = new ErrorCollection();
	$sharing = Sharing::add(
		[
			'FROM_ENTITY' => Sharing::CODE_USER . $userId,
			'REAL_OBJECT' => $newFile,
			'CREATED_BY' => $userId,
			'CAN_FORWARD' => false,
			'LINK_OBJECT_ID' => $fileInChat->getId(),
			'LINK_STORAGE_ID' => $fileInChat->getStorageId(),
			'TO_ENTITY' => Sharing::CODE_CHAT . $chatId,
			'TASK_NAME' => RightsManager::TASK_EDIT,
		],
		$errorCollection
	);
	// (new ChatAuthProvider())->updateChatCodesByRelations($chatId);

	if ($newFile->getCode() === DocumentOnlyOfficeTemplatesCreateDocumentByCallTemplateScenario::CODE_RESUME)
	{
		$fileInChat->changeCode($newFile->getCode());
	}

	return $newFile->attachToEntity(
		[
			'id' => $call->getId(),
			'type' => 'im_call',
		],
		[
			'allowEdit' => true,
			'isEditable' => true,
			'createdBy' => $newFile->getCreatedBy(),
		]
	);
}