• Модуль: voximplant
  • Путь к файлу: ~/bitrix/modules/voximplant/classes/general/vi_rest.php
  • Класс: CVoxImplantRestService
  • Вызов: CVoxImplantRestService::attachTranscription
static function attachTranscription($params, $n, $server)
{
	$params['CALL_ID'] ??= null;
	$params['COST'] ??= null;
	$params['COST_CURRENCY'] ??= null;
	$params['MESSAGES'] ??= null;

	if (!isset($params['CALL_ID']))
	{
		throw new BitrixRestRestException('CALL_ID should be set');
	}
	if (!is_array($params['MESSAGES']))
	{
		throw new BitrixRestRestException('MESSAGES should be an array');
	}
	foreach ($params['MESSAGES'] as $k => $messageFields)
	{
		if ($messageFields['SIDE'] !== BitrixVoximplantTranscript::SIDE_CLIENT && $messageFields['SIDE'] !== BitrixVoximplantTranscript::SIDE_USER)
		{
			throw new BitrixRestRestException('MESSAGES[' . $k . '][SIDE] should be either Client or User');
		}
		if ((int)$messageFields['START_TIME'] < 0)
		{
			throw new BitrixRestRestException('MESSAGES[' . $k . '][START_TIME] should be greater or equal to zero');
		}
		if ((int)$messageFields['STOP_TIME'] <= 0)
		{
			throw new BitrixRestRestException('MESSAGES[' . $k . '][STOP_TIME] should be greater than zero');
		}
		if ($messageFields['MESSAGE'] == '')
		{
			throw new BitrixRestRestException('MESSAGES[' . $k . '][MESSAGE] is empty');
		}
	}

	$callId = $params['CALL_ID'];
	$callFields = BitrixVoximplantStatisticTable::getRow([
		'filter' => [
			'=CALL_ID' => $callId
		]
	]);

	if (!$callFields)
	{
		throw new BitrixRestRestException('Call ' . $callId . ' is not found. Is it finished?');
	}

	$transcript = BitrixVoximplantTranscript::createWithLines($params['MESSAGES']);
	$transcript->setCallId($callId);
	if ($params['COST'])
	{
		$transcript->setCost((double)$params['COST']);
		$transcript->setCostCurrency((string)$params['COST_CURRENCY']);
	}
	$transcript->save();

	BitrixVoximplantStatisticTable::update($callFields['ID'], [
		'TRANSCRIPT_ID' => $transcript->getId(),
		'TRANSCRIPT_PENDING' => 'N'
	]);

	return [
		'TRANSCRIPT_ID' => $transcript->getId()
	];
}