• Модуль: voximplant
  • Путь к файлу: ~/bitrix/modules/voximplant/classes/general/vi_rest.php
  • Класс: CVoxImplantRestService
  • Вызов: CVoxImplantRestService::answerCall
static function answerCall($params, $n, $server)
{
	if ($server->getAuthType() !== BitrixRestSessionAuthAuth::AUTH_TYPE)
	{
		throw new BitrixRestRestException("This method is only available for internal usage.", "WRONG_AUTH_TYPE", CRestServer::STATUS_FORBIDDEN);
	}

	$callId = $params['CALL_ID'];
	$userId = static::getCurrentUserId();
	$call = BitrixVoximplantModelCallTable::getByCallId($callId);
	if (!$call)
	{
		throw new BitrixRestRestException("Call is not found, or already finished", BitrixRestRestException::ERROR_NOT_FOUND, CRestServer::STATUS_NOT_FOUND);
	}

	if ($call['STATUS'] !== BitrixVoximplantModelCallTable::STATUS_WAITING)
	{
		throw new BitrixRestRestException("Call is already answered", "ERROR_WRONG_STATE");
	}

	$result = CVoxImplantIncoming::SendCommand(
		[
			'CALL_ID' => $callId,
			'COMMAND' => CVoxImplantIncoming::RULE_WAIT
		],
		true
	);

	if (!$result->isSuccess())
	{
		$errors = $result->getErrors();
		throw new BitrixRestRestException($errors[0]->getMessage(), $errors[0]->getCode());
	}

	CVoxImplantIncoming::SendPullEvent([
		'COMMAND' => 'answer_self',
		'USER_ID' => $userId,
		'CALL_ID' => $callId,
	]);

	return [
		"SUCCESS" => true
	];
}