Skip to content

Commit

Permalink
Call Transcription Data changes (#37869)
Browse files Browse the repository at this point in the history
* Transcription chages first commit

* Add events, methods & options configuration for transcription data apis

* Add events, methods & options configuration for transcription data apis

* Add junit for events and fix bug in event parsing

* Add junit tests for transcription api methods

* Optimize imports in junit tests

* Regenerate model & delete unused event models

* Rebase on latest main (which has GA2 changes)

* Fix junit test

* Support TranscriptionUpdated event for call transcription data.

* Fix entries in readme.md

* Add dataSubscriptionId in CallConnectionProperties and added in tests
  • Loading branch information
abhishesingh-msft authored Dec 5, 2023
1 parent ba85b25 commit 3c906c6
Show file tree
Hide file tree
Showing 156 changed files with 6,568 additions and 3,937 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@

import com.azure.communication.callautomation.implementation.AzureCommunicationCallAutomationServiceImpl;
import com.azure.communication.callautomation.implementation.CallConnectionsImpl;
import com.azure.communication.callautomation.implementation.CallDialogsImpl;
import com.azure.communication.callautomation.implementation.CallMediasImpl;
import com.azure.communication.callautomation.implementation.CallRecordingsImpl;
import com.azure.communication.callautomation.implementation.CallDialogsImpl;
import com.azure.communication.callautomation.implementation.accesshelpers.CallConnectionPropertiesConstructorProxy;
import com.azure.communication.callautomation.implementation.converters.CommunicationIdentifierConverter;
import com.azure.communication.callautomation.implementation.converters.CommunicationUserIdentifierConverter;
import com.azure.communication.callautomation.implementation.converters.PhoneNumberIdentifierConverter;
import com.azure.communication.callautomation.implementation.models.AnswerCallRequestInternal;
import com.azure.communication.callautomation.implementation.models.CallIntelligenceOptionsInternal;
import com.azure.communication.callautomation.implementation.models.CallRejectReasonInternal;
import com.azure.communication.callautomation.implementation.models.MediaStreamingAudioChannelTypeInternal;
import com.azure.communication.callautomation.implementation.models.MediaStreamingConfigurationInternal;
import com.azure.communication.callautomation.implementation.models.MediaStreamingContentTypeInternal;
import com.azure.communication.callautomation.implementation.models.MediaStreamingTransportTypeInternal;
import com.azure.communication.callautomation.implementation.models.CommunicationIdentifierModel;
import com.azure.communication.callautomation.implementation.models.CommunicationUserIdentifierModel;
import com.azure.communication.callautomation.implementation.models.CreateCallRequestInternal;
import com.azure.communication.callautomation.implementation.models.CustomCallingContext;
import com.azure.communication.callautomation.implementation.models.MediaStreamingAudioChannelTypeInternal;
import com.azure.communication.callautomation.implementation.models.MediaStreamingConfigurationInternal;
import com.azure.communication.callautomation.implementation.models.MediaStreamingContentTypeInternal;
import com.azure.communication.callautomation.implementation.models.MediaStreamingTransportTypeInternal;
import com.azure.communication.callautomation.implementation.models.RedirectCallRequestInternal;
import com.azure.communication.callautomation.implementation.models.RejectCallRequestInternal;
import com.azure.communication.callautomation.implementation.models.TranscriptionConfigurationInternal;
import com.azure.communication.callautomation.implementation.models.TranscriptionTransportTypeInternal;
import com.azure.communication.callautomation.models.AnswerCallOptions;
import com.azure.communication.callautomation.models.AnswerCallResult;
import com.azure.communication.callautomation.models.CallInvite;
Expand All @@ -34,6 +36,7 @@
import com.azure.communication.callautomation.models.MediaStreamingOptions;
import com.azure.communication.callautomation.models.RedirectCallOptions;
import com.azure.communication.callautomation.models.RejectCallOptions;
import com.azure.communication.callautomation.models.TranscriptionOptions;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.communication.common.CommunicationUserIdentifier;
import com.azure.core.annotation.ReturnType;
Expand All @@ -49,8 +52,10 @@
import reactor.core.publisher.Mono;

import java.net.URISyntaxException;
import java.time.OffsetDateTime;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import static com.azure.core.util.FluxUtil.monoError;
Expand Down Expand Up @@ -181,6 +186,8 @@ private Mono<Response<CreateCallResult>> getCreateCallResponseMono(Context conte
context = context == null ? Context.NONE : context;
return azureCommunicationCallAutomationServiceInternal.createCallWithResponseAsync(
createCallRequestInternal,
UUID.randomUUID(),
OffsetDateTime.now(),
context)
.map(response -> {
try {
Expand Down Expand Up @@ -231,6 +238,12 @@ private CreateCallRequestInternal getCreateCallRequestInternal(CreateCallOptions
request.setMediaStreamingConfiguration(streamingConfigurationInternal);
}

if (createCallOptions.getTranscriptionConfiguration() != null) {
TranscriptionConfigurationInternal transcriptionConfigurationInternal =
getTranscriptionConfigurationInternal(createCallOptions.getTranscriptionConfiguration());
request.setTranscriptionConfiguration(transcriptionConfigurationInternal);
}

return request;
}

Expand Down Expand Up @@ -266,6 +279,12 @@ private CreateCallRequestInternal getCreateCallRequestInternal(CreateGroupCallOp
request.setMediaStreamingConfiguration(streamingConfigurationInternal);
}

if (createCallGroupOptions.getTranscriptionConfiguration() != null) {
TranscriptionConfigurationInternal transcriptionConfigurationInternal =
getTranscriptionConfigurationInternal(createCallGroupOptions.getTranscriptionConfiguration());
request.setTranscriptionConfiguration(transcriptionConfigurationInternal);
}

return request;
}

Expand All @@ -284,6 +303,17 @@ private MediaStreamingConfigurationInternal getMediaStreamingConfigurationIntern
mediaStreamingOptions.getTransportType().toString()));
}

private TranscriptionConfigurationInternal getTranscriptionConfigurationInternal(
TranscriptionOptions transcriptionOptions) {
return new TranscriptionConfigurationInternal()
.setTransportUrl(transcriptionOptions.getTransportUrl())
.setTransportType(
TranscriptionTransportTypeInternal.fromString(
transcriptionOptions.getTransportType().toString()))
.setLocale(transcriptionOptions.getLocale())
.setStartTranscription(transcriptionOptions.getStartTranscription());
}

/**
* Answer an incoming call
*
Expand Down Expand Up @@ -332,11 +362,19 @@ Mono<Response<AnswerCallResult>> answerCallWithResponseInternal(AnswerCallOption
if (answerCallOptions.getMediaStreamingConfiguration() != null) {
MediaStreamingConfigurationInternal mediaStreamingConfigurationInternal =
getMediaStreamingConfigurationInternal(answerCallOptions.getMediaStreamingConfiguration());

request.setMediaStreamingConfiguration(mediaStreamingConfigurationInternal);
}

if (answerCallOptions.getTranscriptionConfiguration() != null) {
TranscriptionConfigurationInternal transcriptionConfigurationInternal =
getTranscriptionConfigurationInternal(answerCallOptions.getTranscriptionConfiguration());
request.setTranscriptionConfiguration(transcriptionConfigurationInternal);
}

return azureCommunicationCallAutomationServiceInternal.answerCallWithResponseAsync(
request,
UUID.randomUUID(),
OffsetDateTime.now(),
context)
.map(response -> {
try {
Expand Down Expand Up @@ -401,6 +439,8 @@ Mono<Response<Void>> redirectCallWithResponseInternal(RedirectCallOptions redire

return azureCommunicationCallAutomationServiceInternal.redirectCallWithResponseAsync(
request,
UUID.randomUUID(),
OffsetDateTime.now(),
context);
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand Down Expand Up @@ -446,6 +486,8 @@ Mono<Response<Void>> rejectCallWithResponseInternal(RejectCallOptions rejectCall

return azureCommunicationCallAutomationServiceInternal.rejectCallWithResponseAsync(
request,
UUID.randomUUID(),
OffsetDateTime.now(),
context);
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@
import com.azure.communication.callautomation.models.events.RecordingStateChanged;
import com.azure.communication.callautomation.models.events.RemoveParticipantFailed;
import com.azure.communication.callautomation.models.events.RemoveParticipantSucceeded;
import com.azure.communication.callautomation.models.events.TranscriptionFailed;
import com.azure.communication.callautomation.models.events.TranscriptionResumed;
import com.azure.communication.callautomation.models.events.TranscriptionStarted;
import com.azure.communication.callautomation.models.events.TranscriptionStopped;
import com.azure.communication.callautomation.models.events.SendDtmfTonesCompleted;
import com.azure.communication.callautomation.models.events.SendDtmfTonesFailed;
import com.azure.communication.callautomation.models.events.TranscriptionUpdated;
import com.azure.core.models.CloudEvent;
import com.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -160,6 +165,16 @@ private static CallAutomationEventBase parseSingleCloudEvent(String data, String
ret = mapper.convertValue(eventData, DialogTransfer.class);
} else if (Objects.equals(eventType, "Microsoft.Communication.DialogSensitivityUpdate")) {
ret = mapper.convertValue(eventData, DialogSensitivityUpdate.class);
} else if (Objects.equals(eventType, "Microsoft.Communication.TranscriptionStarted")) {
ret = mapper.convertValue(eventData, TranscriptionStarted.class);
} else if (Objects.equals(eventType, "Microsoft.Communication.TranscriptionFailed")) {
ret = mapper.convertValue(eventData, TranscriptionFailed.class);
} else if (Objects.equals(eventType, "Microsoft.Communication.TranscriptionResumed")) {
ret = mapper.convertValue(eventData, TranscriptionResumed.class);
} else if (Objects.equals(eventType, "Microsoft.Communication.TranscriptionStopped")) {
ret = mapper.convertValue(eventData, TranscriptionStopped.class);
} else if (Objects.equals(eventType, "Microsoft.Communication.TranscriptionUpdated")) {
ret = mapper.convertValue(eventData, TranscriptionUpdated.class);
}
return ret;
} catch (RuntimeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import com.azure.communication.callautomation.implementation.models.RemoveParticipantRequestInternal;
import com.azure.communication.callautomation.implementation.models.TransferToParticipantRequestInternal;
import com.azure.communication.callautomation.implementation.models.UnmuteParticipantsRequestInternal;
import com.azure.communication.callautomation.models.AddParticipantOptions;
import com.azure.communication.callautomation.models.AddParticipantResult;
import com.azure.communication.callautomation.models.CallConnectionProperties;
import com.azure.communication.callautomation.models.CallInvite;
import com.azure.communication.callautomation.models.CallParticipant;
import com.azure.communication.callautomation.models.CancelAddParticipantOperationOptions;
import com.azure.communication.callautomation.models.CancelAddParticipantOperationResult;
import com.azure.communication.callautomation.models.AddParticipantOptions;
import com.azure.communication.callautomation.models.CallConnectionProperties;
import com.azure.communication.callautomation.models.CallInvite;
import com.azure.communication.callautomation.models.MuteParticipantOptions;
import com.azure.communication.callautomation.models.MuteParticipantResult;
import com.azure.communication.callautomation.models.RemoveParticipantOptions;
Expand All @@ -44,17 +44,19 @@
import com.azure.communication.common.PhoneNumberIdentifier;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.logging.ClientLogger;
import reactor.core.publisher.Mono;
import com.azure.core.exception.HttpResponseException;

import java.net.URISyntaxException;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.UUID;

import static com.azure.core.util.FluxUtil.monoError;
import static com.azure.core.util.FluxUtil.withContext;
Expand Down Expand Up @@ -156,6 +158,8 @@ Mono<Response<Void>> hangUpWithResponseInternal(boolean isForEveryone, Context c

return (isForEveryone ? callConnectionInternal.terminateCallWithResponseAsync(
callConnectionId,
UUID.randomUUID(),
OffsetDateTime.now(),
context)
: callConnectionInternal.hangupCallWithResponseAsync(callConnectionId, context));
} catch (RuntimeException ex) {
Expand Down Expand Up @@ -292,6 +296,8 @@ Mono<Response<TransferCallResult>> transferCallToParticipantWithResponseInternal
return callConnectionInternal.transferToParticipantWithResponseAsync(
callConnectionId,
request,
UUID.randomUUID(),
OffsetDateTime.now(),
context)
.map(response -> {
TransferCallResult result = TransferCallResponseConstructorProxy.create(response.getValue());
Expand Down Expand Up @@ -355,6 +361,8 @@ Mono<Response<AddParticipantResult>> addParticipantWithResponseInternal(AddParti
return callConnectionInternal.addParticipantWithResponseAsync(
callConnectionId,
request,
UUID.randomUUID(),
OffsetDateTime.now(),
context
).map(response -> {
AddParticipantResult result = AddParticipantResponseConstructorProxy.create(response.getValue());
Expand Down Expand Up @@ -404,6 +412,8 @@ Mono<Response<RemoveParticipantResult>> removeParticipantWithResponseInternal(Re
return callConnectionInternal.removeParticipantWithResponseAsync(
callConnectionId,
request,
UUID.randomUUID(),
OffsetDateTime.now(),
context).map(response -> {
RemoveParticipantResult result = RemoveParticipantResponseConstructorProxy.create(response.getValue());
result.setEventProcessor(eventProcessor, callConnectionId, result.getOperationContext());
Expand Down Expand Up @@ -449,6 +459,8 @@ Mono<Response<MuteParticipantResult>> muteParticipantWithResponseInternal(MutePa
return callConnectionInternal.muteWithResponseAsync(
callConnectionId,
request,
UUID.randomUUID(),
OffsetDateTime.now(),
context).map(internalResponse -> new SimpleResponse<>(internalResponse, MuteParticipantsResponseConstructorProxy.create(internalResponse.getValue())));
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand Down Expand Up @@ -488,6 +500,8 @@ Mono<Response<UnmuteParticipantResult>> unmuteParticipantWithResponseInternal(Un
return callConnectionInternal.unmuteWithResponseAsync(
callConnectionId,
request,
UUID.randomUUID(),
OffsetDateTime.now(),
context).map(internalResponse -> new SimpleResponse<>(internalResponse, UnmuteParticipantsResponseConstructorProxy.create(internalResponse.getValue())));
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand Down Expand Up @@ -532,6 +546,8 @@ Mono<Response<CancelAddParticipantOperationResult>> cancelAddParticipantOperatio
return callConnectionInternal.cancelAddParticipantWithResponseAsync(
callConnectionId,
request,
UUID.randomUUID(),
OffsetDateTime.now(),
context).map(response -> {
CancelAddParticipantOperationResult result = CancelAddParticipantResponseConstructorProxy.create(response.getValue());
result.setEventProcessor(eventProcessor, callConnectionId, result.getOperationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.azure.communication.callautomation.models.SendDtmfTonesOptions;
import com.azure.communication.callautomation.models.SendDtmfTonesResult;
import com.azure.communication.callautomation.models.StartHoldMusicOptions;
import com.azure.communication.callautomation.models.StartTranscriptionOptions;
import com.azure.communication.callautomation.models.StopTranscriptionOptions;
import com.azure.communication.callautomation.models.PlaySource;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.core.annotation.ReturnType;
Expand Down Expand Up @@ -263,4 +265,65 @@ public Response<Void> stopHoldMusicWithResponse(CommunicationIdentifier targetPa
Context context) {
return callMediaAsync.stopHoldMusicWithResponseInternal(targetParticipant, operationContext, context).block();
}

/**
* Starts transcription in the call.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void startTranscription() {
callMediaAsync.startTranscription().block();
}

/**
* Starts transcription in the call.
*
* @param options Options for the Start Transcription operation.
* @param context Context
* @return Response for successful start transcription request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> startTranscriptionWithResponse(StartTranscriptionOptions options, Context context) {
return callMediaAsync.startTranscriptionWithResponseInternal(options, context).block();
}

/**
* Stops transcription in the call.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void stopTranscription() {
callMediaAsync.stopTranscription().block();
}

/**
* Stops transcription in the call.
*
* @param options Options for the Stop Transcription operation.
* @param context Context
* @return Response for successful stop transcription request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> stopTranscriptionWithResponse(StopTranscriptionOptions options, Context context) {
return callMediaAsync.stopTranscriptionWithResponseInternal(options, context).block();
}

/**
* Updates transcription language in the call.
* @param locale Defines new locale for transcription.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void updateTranscription(String locale) {
callMediaAsync.updateTranscription(locale).block();
}

/**
* Updates transcription language in the call.
*
* @param locale Defines new locale for transcription.
* @param context Context
* @return Response for successful update transcription request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> updateTranscriptionWithResponse(String locale, Context context) {
return callMediaAsync.updateTranscriptionWithResponseInternal(locale, context).block();
}
}
Loading

0 comments on commit 3c906c6

Please sign in to comment.