Skip to content

Commit 3ec342d

Browse files
Update recognize and media streaming (Azure#30888)
* remove inSeconds from interToneTimeout name * add abstract recognize options class and supporting logic * migrate changes to callautomation directory instead * add recognize cloud events * runned autorest to update * event updates based on new swagger * updated SDK based on the new swagger. However, we need content team to update methods in CallMedia * incorporate swagger updates and resolve comments * set repeatability request id to null * remove changes to callingserver * bug fixes * set target participant and update tests * switch to getSeconds * fix eventhandler case * fix mock payload in eventhandler tests * remove unused imports * add newline to end of files * fix recognize events * remove unused import * rename RecognitionType * replace StopTones with Tone * set default behaviour for timeout * add a test with a filled DtmfOptions object * remove unused imports again * update doc Co-authored-by: juntuchen <[email protected]>
1 parent 14e6ea5 commit 3ec342d

File tree

52 files changed

+1797
-1509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1797
-1509
lines changed

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallAutomationAsyncClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Mono<Response<CreateCallResult>> createCallWithResponseInternal(CreateCallOption
116116
context = context == null ? Context.NONE : context;
117117
CreateCallRequestInternal request = getCreateCallRequestInternal(createCallOptions);
118118

119-
return serverCallingInternal.createCallWithResponseAsync(request, context)
119+
return serverCallingInternal.createCallWithResponseAsync(request, null, null, context)
120120
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
121121
.map(response -> {
122122
try {
@@ -222,7 +222,7 @@ Mono<Response<AnswerCallResult>> answerCallWithResponseInternal(String incomingC
222222
}
223223

224224

225-
return serverCallingInternal.answerCallWithResponseAsync(request, context)
225+
return serverCallingInternal.answerCallWithResponseAsync(request, null, null, context)
226226
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
227227
.map(response -> {
228228
try {
@@ -276,7 +276,7 @@ Mono<Response<Void>> redirectCallWithResponseInternal(String incomingCallContext
276276
.setIncomingCallContext(incomingCallContext)
277277
.setTarget(CommunicationIdentifierConverter.convert(target));
278278

279-
return serverCallingInternal.redirectCallWithResponseAsync(request, context)
279+
return serverCallingInternal.redirectCallWithResponseAsync(request, null, null, context)
280280
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create);
281281
} catch (RuntimeException ex) {
282282
return monoError(logger, ex);
@@ -320,7 +320,7 @@ Mono<Response<Void>> rejectCallWithResponseInternal(String incomingCallContext,
320320
.setIncomingCallContext(incomingCallContext)
321321
.setCallRejectReason(CallRejectReasonInternal.fromString(callRejectReason.toString()));
322322

323-
return serverCallingInternal.rejectCallWithResponseAsync(request, context)
323+
return serverCallingInternal.rejectCallWithResponseAsync(request, null, null, context)
324324
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create);
325325
} catch (RuntimeException ex) {
326326
return monoError(logger, ex);

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallConnectionAsync.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Mono<Response<Void>> hangUpWithResponseInternal(boolean isForEveryone, Context c
136136
try {
137137
context = context == null ? Context.NONE : context;
138138

139-
return (isForEveryone ? callConnectionInternal.terminateCallWithResponseAsync(callConnectionId, context)
139+
return (isForEveryone ? callConnectionInternal.terminateCallWithResponseAsync(callConnectionId, null, null, context)
140140
: callConnectionInternal.hangupCallWithResponseAsync(callConnectionId, context))
141141
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create);
142142
} catch (RuntimeException ex) {
@@ -259,7 +259,7 @@ Mono<Response<TransferCallResult>> transferToParticipantCallWithResponseInternal
259259
.setUserToUserInformation(transferToParticipantCallOptions.getUserToUserInformation())
260260
.setOperationContext(transferToParticipantCallOptions.getOperationContext());
261261

262-
return callConnectionInternal.transferToParticipantWithResponseAsync(callConnectionId, request, context)
262+
return callConnectionInternal.transferToParticipantWithResponseAsync(callConnectionId, request, null, null, context)
263263
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
264264
.map(response ->
265265
new SimpleResponse<>(response, TransferCallResponseConstructorProxy.create(response.getValue())));
@@ -311,7 +311,7 @@ Mono<Response<AddParticipantsResult>> addParticipantsWithResponseInternal(AddPar
311311
request.setInvitationTimeoutInSeconds((int) addParticipantsOptions.getInvitationTimeout().getSeconds());
312312
}
313313

314-
return callConnectionInternal.addParticipantWithResponseAsync(callConnectionId, request, context)
314+
return callConnectionInternal.addParticipantWithResponseAsync(callConnectionId, request, null, null, context)
315315
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
316316
.map(response -> new SimpleResponse<>(response, AddParticipantsResponseConstructorProxy.create(response.getValue())));
317317
} catch (RuntimeException ex) {
@@ -360,7 +360,7 @@ Mono<Response<RemoveParticipantsResult>> removeParticipantsWithResponseInternal(
360360
.setParticipantsToRemove(participantModels)
361361
.setOperationContext(operationContext);
362362

363-
return callConnectionInternal.removeParticipantsWithResponseAsync(callConnectionId, request, context)
363+
return callConnectionInternal.removeParticipantsWithResponseAsync(callConnectionId, request, null, null, context)
364364
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
365365
.map(response -> new SimpleResponse<>(response, RemoveParticipantsResponseConstructorProxy.create(response.getValue())));
366366
} catch (RuntimeException ex) {

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallMedia.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.azure.communication.callautomation.models.CallingServerErrorException;
77
import com.azure.communication.callautomation.models.PlayOptions;
88
import com.azure.communication.callautomation.models.PlaySource;
9-
import com.azure.communication.callautomation.models.RecognizeOptions;
9+
import com.azure.communication.callautomation.models.CallMediaRecognizeOptions;
1010
import com.azure.communication.common.CommunicationIdentifier;
1111
import com.azure.core.annotation.ReturnType;
1212
import com.azure.core.annotation.ServiceMethod;
@@ -87,23 +87,23 @@ public Response<Void> playToAllWithResponse(PlaySource playSource, PlayOptions o
8787

8888
/**
8989
* Recognize tones.
90-
* @param recognizeOptions Optional elements for recognize.
90+
* @param callMediaRecognizeOptions Optional elements for recognize.
9191
*/
9292
@ServiceMethod(returns = ReturnType.SINGLE)
93-
public void recognize(RecognizeOptions recognizeOptions) {
94-
callMediaAsync.recognize(recognizeOptions).block();
93+
public void recognize(CallMediaRecognizeOptions callMediaRecognizeOptions) {
94+
callMediaAsync.recognize(callMediaRecognizeOptions).block();
9595
}
9696

9797
/**
9898
* Recognize tones.
99-
* @param recognizeOptions Optional elements for recognize.
99+
* @param callMediaRecognizeOptions Optional elements for recognize.
100100
* @param context A {@link Context} representing the request context.
101101
* @return Response for a successful recognize request.
102102
*/
103103
@ServiceMethod(returns = ReturnType.SINGLE)
104-
public Response<Void> recognizeWithResponse(RecognizeOptions recognizeOptions, Context context) {
104+
public Response<Void> recognizeWithResponse(CallMediaRecognizeOptions callMediaRecognizeOptions, Context context) {
105105
return callMediaAsync
106-
.recognizeWithResponseInternal(recognizeOptions, context)
106+
.recognizeWithResponseInternal(callMediaRecognizeOptions, context)
107107
.block();
108108
}
109109

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallMediaAsync.java

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@
66
import com.azure.communication.callautomation.implementation.ContentsImpl;
77
import com.azure.communication.callautomation.implementation.accesshelpers.ErrorConstructorProxy;
88
import com.azure.communication.callautomation.implementation.converters.CommunicationIdentifierConverter;
9-
import com.azure.communication.callautomation.implementation.models.DtmfConfigurationsInternal;
9+
import com.azure.communication.callautomation.implementation.models.DtmfOptionsInternal;
1010
import com.azure.communication.callautomation.implementation.models.FileSourceInternal;
1111
import com.azure.communication.callautomation.implementation.models.PlayOptionsInternal;
1212
import com.azure.communication.callautomation.implementation.models.PlayRequest;
1313
import com.azure.communication.callautomation.implementation.models.PlaySourceInternal;
1414
import com.azure.communication.callautomation.implementation.models.PlaySourceTypeInternal;
15-
import com.azure.communication.callautomation.implementation.models.RecognizeConfigurationsInternal;
1615
import com.azure.communication.callautomation.implementation.models.RecognizeInputTypeInternal;
16+
import com.azure.communication.callautomation.implementation.models.RecognizeOptionsInternal;
1717
import com.azure.communication.callautomation.implementation.models.RecognizeRequest;
18-
import com.azure.communication.callautomation.implementation.models.StopTonesInternal;
18+
import com.azure.communication.callautomation.models.CallMediaRecognizeDtmfOptions;
1919
import com.azure.communication.callautomation.models.CallingServerErrorException;
20-
import com.azure.communication.callautomation.models.DtmfConfigurations;
2120
import com.azure.communication.callautomation.models.FileSource;
2221
import com.azure.communication.callautomation.models.PlayOptions;
2322
import com.azure.communication.callautomation.models.PlaySource;
24-
import com.azure.communication.callautomation.models.RecognizeConfigurations;
25-
import com.azure.communication.callautomation.models.RecognizeOptions;
23+
import com.azure.communication.callautomation.models.CallMediaRecognizeOptions;
2624
import com.azure.communication.common.CommunicationIdentifier;
2725
import com.azure.core.annotation.ReturnType;
2826
import com.azure.core.annotation.ServiceMethod;
@@ -116,7 +114,7 @@ public Mono<Response<Void>> playToAllWithResponse(PlaySource playSource, PlayOpt
116114
* @param recognizeOptions Different attributes for recognize.
117115
* @return Response for successful recognize request.
118116
*/
119-
public Mono<Void> recognize(RecognizeOptions recognizeOptions) {
117+
public Mono<Void> recognize(CallMediaRecognizeOptions recognizeOptions) {
120118
return recognizeWithResponse(recognizeOptions).then();
121119
}
122120

@@ -125,55 +123,54 @@ public Mono<Void> recognize(RecognizeOptions recognizeOptions) {
125123
* @param recognizeOptions Different attributes for recognize.
126124
* @return Response for successful recognize request.
127125
*/
128-
public Mono<Response<Void>> recognizeWithResponse(RecognizeOptions recognizeOptions) {
126+
public Mono<Response<Void>> recognizeWithResponse(CallMediaRecognizeOptions recognizeOptions) {
129127
return withContext(context -> recognizeWithResponseInternal(recognizeOptions, context));
130128
}
131129

132-
Mono<Response<Void>> recognizeWithResponseInternal(RecognizeOptions recognizeOptions, Context context) {
130+
Mono<Response<Void>> recognizeWithResponseInternal(CallMediaRecognizeOptions recognizeOptions, Context context) {
133131
try {
134132
context = context == null ? Context.NONE : context;
135133

136-
RecognizeConfigurations recognizeConfigurations = recognizeOptions.getRecognizeConfiguration();
137-
DtmfConfigurationsInternal dtmfConfigurationsInternal = null;
138-
if (recognizeConfigurations.getDtmfConfigurations() != null) {
139-
DtmfConfigurations dtmfConfigurations = recognizeConfigurations.getDtmfConfigurations();
140-
dtmfConfigurationsInternal = new DtmfConfigurationsInternal()
141-
.setMaxTonesToCollect(dtmfConfigurations.getMaxTonesToCollect());
134+
if (recognizeOptions instanceof CallMediaRecognizeDtmfOptions) {
142135

143-
if (dtmfConfigurations.getInterToneTimeoutInSeconds() != null) {
144-
dtmfConfigurationsInternal.setInterToneTimeoutInSeconds((int) dtmfConfigurations.getInterToneTimeoutInSeconds().getSeconds());
145-
}
146-
if (dtmfConfigurations.getStopTones() != null) {
147-
dtmfConfigurationsInternal
148-
.setStopTones(dtmfConfigurations.getStopTones().stream()
149-
.map(stopTones -> StopTonesInternal.fromString(stopTones.toString()))
150-
.collect(Collectors.toList()));
136+
CallMediaRecognizeDtmfOptions dtmfRecognizeOptions = (CallMediaRecognizeDtmfOptions) recognizeOptions;
137+
DtmfOptionsInternal dtmfOptionsInternal = new DtmfOptionsInternal();
138+
139+
140+
dtmfOptionsInternal.setInterToneTimeoutInSeconds((int) dtmfRecognizeOptions.getInterToneTimeout().getSeconds());
151141

142+
143+
if (dtmfRecognizeOptions.getMaxTonesToCollect() != null) {
144+
dtmfOptionsInternal.setMaxTonesToCollect(dtmfRecognizeOptions.getMaxTonesToCollect());
152145
}
153-
}
154-
RecognizeConfigurationsInternal recognizeConfigurationsInternal = new RecognizeConfigurationsInternal()
155-
.setDtmfConfigurations(dtmfConfigurationsInternal)
156-
.setInterruptPromptAndStartRecognition(recognizeConfigurations.isInterruptPromptAndStartRecognition())
157-
.setTargetParticipant(CommunicationIdentifierConverter.convert(recognizeConfigurations.getTargetParticipant()));
158-
if (recognizeConfigurations.getInitialSilenceTimeoutInSeconds() != null) {
159-
recognizeConfigurationsInternal.setInitialSilenceTimeoutInSeconds((int) recognizeConfigurations.getInitialSilenceTimeoutInSeconds().getSeconds());
160-
}
161146

162-
PlaySourceInternal playSourceInternal = null;
163-
if (recognizeOptions.getPlayPrompt() != null) {
164-
PlaySource playSource = recognizeOptions.getPlayPrompt();
165-
if (playSource instanceof FileSource) {
166-
playSourceInternal = getPlaySourceInternal((FileSource) playSource);
147+
RecognizeOptionsInternal recognizeOptionsInternal = new RecognizeOptionsInternal()
148+
.setDtmfOptions(dtmfOptionsInternal)
149+
.setInterruptPrompt(recognizeOptions.isInterruptPrompt())
150+
.setTargetParticipant(CommunicationIdentifierConverter.convert(recognizeOptions.getTargetParticipant()));
151+
152+
recognizeOptionsInternal.setInitialSilenceTimeoutInSeconds((int) recognizeOptions.getInitialSilenceTimeout().getSeconds());
153+
154+
PlaySourceInternal playSourceInternal = null;
155+
if (recognizeOptions.getPlayPrompt() != null) {
156+
PlaySource playSource = recognizeOptions.getPlayPrompt();
157+
if (playSource instanceof FileSource) {
158+
playSourceInternal = getPlaySourceInternal((FileSource) playSource);
159+
}
167160
}
161+
162+
RecognizeRequest recognizeRequest = new RecognizeRequest()
163+
.setRecognizeInputType(RecognizeInputTypeInternal.fromString(recognizeOptions.getRecognizeInputType().toString()))
164+
.setInterruptCallMediaOperation(recognizeOptions.isInterruptCallMediaOperation())
165+
.setPlayPrompt(playSourceInternal)
166+
.setRecognizeOptions(recognizeOptionsInternal)
167+
.setOperationContext(recognizeOptions.getOperationContext());
168+
169+
return contentsInternal.recognizeWithResponseAsync(callConnectionId, recognizeRequest, context);
170+
171+
} else {
172+
return monoError(logger, new UnsupportedOperationException(recognizeOptions.getClass().getName()));
168173
}
169-
RecognizeRequest recognizeRequest = new RecognizeRequest()
170-
.setRecognizeInputType(RecognizeInputTypeInternal.fromString(recognizeOptions.getRecognizeInputType().toString()))
171-
.setRecognizeConfiguration(recognizeConfigurationsInternal)
172-
.setStopCurrentOperations(recognizeOptions.isStopCurrentOperations())
173-
.setPlayPrompt(playSourceInternal)
174-
.setOperationContext(recognizeOptions.getOperationContext());
175-
176-
return contentsInternal.recognizeWithResponseAsync(callConnectionId, recognizeRequest, context);
177174

178175
} catch (RuntimeException e) {
179176
return monoError(logger, e);

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallRecordingAsync.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Mono<Response<RecordingStateResult>> startRecordingWithResponseInternal(StartRec
123123
return withContext(contextValue -> {
124124
contextValue = context == null ? contextValue : context;
125125
return contentsInternal
126-
.recordingWithResponseAsync(request, contextValue)
126+
.recordingWithResponseAsync(request, null, null, contextValue)
127127
.onErrorMap(HttpResponseException.class, ErrorConstructorProxy::create)
128128
.map(response ->
129129
new SimpleResponse<>(response, RecordingStateResponseConstructorProxy.create(response.getValue()))

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/EventHandler.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import com.azure.communication.callautomation.models.events.CallTransferAcceptedEvent;
1212
import com.azure.communication.callautomation.models.events.CallTransferFailedEvent;
1313
import com.azure.communication.callautomation.models.events.ParticipantsUpdatedEvent;
14-
import com.azure.communication.callautomation.models.events.PlayCompleted;
15-
import com.azure.communication.callautomation.models.events.PlayFailed;
14+
import com.azure.communication.callautomation.models.events.RecognizeCompleted;
15+
import com.azure.communication.callautomation.models.events.RecognizeFailed;
16+
import com.azure.communication.callautomation.models.events.PlayCompletedEvent;
17+
import com.azure.communication.callautomation.models.events.PlayFailedEvent;
1618
import com.azure.communication.callautomation.models.events.RecordingStateChangedEvent;
1719
import com.azure.core.models.CloudEvent;
1820
import com.azure.core.util.logging.ClientLogger;
@@ -105,10 +107,14 @@ private static CallAutomationEventBase parseSingleCloudEvent(String data, String
105107
ret = mapper.convertValue(eventData, ParticipantsUpdatedEvent.class);
106108
} else if (Objects.equals(eventType, "Microsoft.Communication.CallRecordingStateChanged")) {
107109
ret = mapper.convertValue(eventData, RecordingStateChangedEvent.class);
108-
} else if (Objects.equals(eventType, "Microsoft.Communication.PlayCompleted")) {
109-
ret = mapper.convertValue(eventData, PlayCompleted.class);
110-
} else if (Objects.equals(eventType, "Microsoft.Communication.PlayFailed")) {
111-
ret = mapper.convertValue(eventData, PlayFailed.class);
110+
} else if (Objects.equals(eventType, "Microsoft.Communication.PlayCompletedEvent")) {
111+
ret = mapper.convertValue(eventData, PlayCompletedEvent.class);
112+
} else if (Objects.equals(eventType, "Microsoft.Communication.PlayFailedEvent")) {
113+
ret = mapper.convertValue(eventData, PlayFailedEvent.class);
114+
} else if (Objects.equals(eventType, "Microsoft.Communication.RecognizeCompleted")) {
115+
ret = mapper.convertValue(eventData, RecognizeCompleted.class);
116+
} else if (Objects.equals(eventType, "Microsoft.Communication.RecognizeFailed")) {
117+
ret = mapper.convertValue(eventData, RecognizeFailed.class);
112118
}
113119

114120
return ret;

0 commit comments

Comments
 (0)