Skip to content

Commit

Permalink
updated ops outgoing call (Azure#42578)
Browse files Browse the repository at this point in the history
* updated ops outgoing call

* fixed format

* Updated to fix bug
  • Loading branch information
juntuchen-msft authored Nov 8, 2024
1 parent d36754b commit 0f17a67
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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.MicrosoftTeamsAppIdentifierConverter;
import com.azure.communication.callautomation.implementation.converters.PhoneNumberIdentifierConverter;
import com.azure.communication.callautomation.implementation.models.AnswerCallRequestInternal;
import com.azure.communication.callautomation.implementation.models.CallIntelligenceOptionsInternal;
Expand All @@ -23,6 +24,7 @@
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.MicrosoftTeamsAppIdentifierModel;
import com.azure.communication.callautomation.implementation.models.RedirectCallRequestInternal;
import com.azure.communication.callautomation.implementation.models.RejectCallRequestInternal;
import com.azure.communication.callautomation.implementation.models.TranscriptionConfigurationInternal;
Expand All @@ -39,6 +41,7 @@
import com.azure.communication.callautomation.models.TranscriptionOptions;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.communication.common.CommunicationUserIdentifier;
import com.azure.communication.common.MicrosoftTeamsAppIdentifier;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
Expand Down Expand Up @@ -80,10 +83,12 @@ public final class CallAutomationAsyncClient {
private final HttpPipeline httpPipelineInternal;
private final String resourceUrl;
private final CommunicationUserIdentifierModel sourceIdentity;
private final MicrosoftTeamsAppIdentifierModel opsSourceIdentity;
private final CallAutomationEventProcessor eventProcessor;

CallAutomationAsyncClient(AzureCommunicationCallAutomationServiceImpl callServiceClient,
CommunicationUserIdentifier sourceIdentity, CallAutomationEventProcessor eventProcessor) {
CommunicationUserIdentifier sourceIdentity, MicrosoftTeamsAppIdentifier opsSourceIdentity,
CallAutomationEventProcessor eventProcessor) {
this.callConnectionsInternal = callServiceClient.getCallConnections();
this.azureCommunicationCallAutomationServiceInternal = callServiceClient;
this.callRecordingsInternal = callServiceClient.getCallRecordings();
Expand All @@ -97,6 +102,8 @@ public final class CallAutomationAsyncClient {
this.resourceUrl = callServiceClient.getEndpoint();
this.sourceIdentity
= sourceIdentity == null ? null : CommunicationUserIdentifierConverter.convert(sourceIdentity);
this.opsSourceIdentity
= opsSourceIdentity == null ? null : MicrosoftTeamsAppIdentifierConverter.convert(opsSourceIdentity);
}

/**
Expand All @@ -115,6 +122,14 @@ public CommunicationUserIdentifier getSourceIdentity() {
return sourceIdentity == null ? null : CommunicationUserIdentifierConverter.convert(sourceIdentity);
}

/**
* Get OPS Source Identity that is used for create OPS call
* @return {@link CommunicationUserIdentifier} represent source
*/
public MicrosoftTeamsAppIdentifier getOPSSourceIdentity() {
return opsSourceIdentity == null ? null : MicrosoftTeamsAppIdentifierConverter.convert(opsSourceIdentity);
}

//region Pre-call Actions
/**
* Create a call connection request from a source identity to a target identity.
Expand Down Expand Up @@ -224,6 +239,7 @@ private CreateCallRequestInternal getCreateCallRequestInternal(CreateCallOptions
PhoneNumberIdentifierConverter.convert(createCallOptions.getCallInvite().getSourceCallerIdNumber()))
.setSourceDisplayName(createCallOptions.getCallInvite().getSourceDisplayName())
.setSource(sourceIdentity)
.setOpsSource(opsSourceIdentity)
.setTargets(targetsModel)
.setCallbackUri(createCallOptions.getCallbackUrl())
.setCallIntelligenceOptions(callIntelligenceOptionsInternal)
Expand Down Expand Up @@ -272,6 +288,7 @@ private CreateCallRequestInternal getCreateCallRequestInternal(CreateGroupCallOp
PhoneNumberIdentifierConverter.convert(createCallGroupOptions.getSourceCallIdNumber()))
.setSourceDisplayName(createCallGroupOptions.getSourceDisplayName())
.setSource(sourceIdentity)
.setOpsSource(opsSourceIdentity)
.setTargets(targetsModel)
.setCallbackUri(createCallGroupOptions.getCallbackUrl())
.setCallIntelligenceOptions(callIntelligenceOptionsInternal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.communication.callautomation.implementation.CustomBearerTokenAuthenticationPolicy;
import com.azure.communication.callautomation.implementation.CustomHmacAuthenticationPolicy;
import com.azure.communication.common.CommunicationUserIdentifier;
import com.azure.communication.common.MicrosoftTeamsAppIdentifier;
import com.azure.communication.common.implementation.CommunicationConnectionString;
import com.azure.communication.common.implementation.HmacAuthenticationPolicy;
import com.azure.core.annotation.ServiceClientBuilder;
Expand Down Expand Up @@ -81,6 +82,7 @@ public final class CallAutomationClientBuilder
private RetryPolicy retryPolicy;
private RetryOptions retryOptions;
private CommunicationUserIdentifier sourceIdentity;
private MicrosoftTeamsAppIdentifier opsSourceIdentity;

/**
* Public default constructor
Expand Down Expand Up @@ -185,6 +187,16 @@ public CallAutomationClientBuilder sourceIdentity(CommunicationUserIdentifier so
return this;
}

/**
* Set One Phone System Source Identity used to create call
* @param opsSourceIdentity {@link MicrosoftTeamsAppIdentifier} to used to create call.
* @return {@link CallAutomationClientBuilder} object.
*/
public CallAutomationClientBuilder opsSourceIdentity(MicrosoftTeamsAppIdentifier opsSourceIdentity) {
this.opsSourceIdentity = opsSourceIdentity;
return this;
}

/**
* Sets the retry policy to use (using the RetryPolicy type).
* <p>
Expand Down Expand Up @@ -319,7 +331,8 @@ public CallAutomationClientBuilder addPolicy(HttpPipelinePolicy customPolicy) {
* and {@link #retryPolicy(RetryPolicy)} have been set.
*/
public CallAutomationAsyncClient buildAsyncClient() {
return new CallAutomationAsyncClient(createServiceImpl(), sourceIdentity, new CallAutomationEventProcessor());
return new CallAutomationAsyncClient(createServiceImpl(), sourceIdentity, opsSourceIdentity,
new CallAutomationEventProcessor());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ public DialogStateResponse startDialog(String callConnectionId, String dialogId,
}

/**
* Stop a dialog.
* The stopDialog operation.
*
* @param callConnectionId The call connection id.
* @param dialogId The dialog id.
* @param operationCallbackUri Operation callback URI.
* @param callConnectionId The callConnectionId parameter.
* @param dialogId The dialogId parameter.
* @param operationCallbackUri The operationCallbackUri parameter.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws CommunicationErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
Expand All @@ -230,11 +230,11 @@ public Mono<Response<Void>> stopDialogWithResponseAsync(String callConnectionId,
}

/**
* Stop a dialog.
* The stopDialog operation.
*
* @param callConnectionId The call connection id.
* @param dialogId The dialog id.
* @param operationCallbackUri Operation callback URI.
* @param callConnectionId The callConnectionId parameter.
* @param dialogId The dialogId parameter.
* @param operationCallbackUri The operationCallbackUri parameter.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws CommunicationErrorResponseException thrown if the request is rejected by server.
Expand All @@ -250,11 +250,11 @@ public Mono<Response<Void>> stopDialogWithResponseAsync(String callConnectionId,
}

/**
* Stop a dialog.
* The stopDialog operation.
*
* @param callConnectionId The call connection id.
* @param dialogId The dialog id.
* @param operationCallbackUri Operation callback URI.
* @param callConnectionId The callConnectionId parameter.
* @param dialogId The dialogId parameter.
* @param operationCallbackUri The operationCallbackUri parameter.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws CommunicationErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
Expand All @@ -267,11 +267,11 @@ public Mono<Void> stopDialogAsync(String callConnectionId, String dialogId, Stri
}

/**
* Stop a dialog.
* The stopDialog operation.
*
* @param callConnectionId The call connection id.
* @param dialogId The dialog id.
* @param operationCallbackUri Operation callback URI.
* @param callConnectionId The callConnectionId parameter.
* @param dialogId The dialogId parameter.
* @param operationCallbackUri The operationCallbackUri parameter.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws CommunicationErrorResponseException thrown if the request is rejected by server.
Expand All @@ -286,11 +286,11 @@ public Mono<Void> stopDialogAsync(String callConnectionId, String dialogId, Stri
}

/**
* Stop a dialog.
* The stopDialog operation.
*
* @param callConnectionId The call connection id.
* @param dialogId The dialog id.
* @param operationCallbackUri Operation callback URI.
* @param callConnectionId The callConnectionId parameter.
* @param dialogId The dialogId parameter.
* @param operationCallbackUri The operationCallbackUri parameter.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws CommunicationErrorResponseException thrown if the request is rejected by server.
Expand All @@ -304,11 +304,11 @@ public Response<Void> stopDialogWithResponse(String callConnectionId, String dia
}

/**
* Stop a dialog.
* The stopDialog operation.
*
* @param callConnectionId The call connection id.
* @param dialogId The dialog id.
* @param operationCallbackUri Operation callback URI.
* @param callConnectionId The callConnectionId parameter.
* @param dialogId The dialogId parameter.
* @param operationCallbackUri The operationCallbackUri parameter.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws CommunicationErrorResponseException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.communication.callautomation.implementation.converters;

import com.azure.communication.callautomation.implementation.models.MicrosoftTeamsAppIdentifierModel;
import com.azure.communication.common.MicrosoftTeamsAppIdentifier;

/**
* A converter for {@link MicrosoftTeamsAppIdentifier} and {@link MicrosoftTeamsAppIdentifierModel}
*/
public final class MicrosoftTeamsAppIdentifierConverter {

/**
* Converts to {@link MicrosoftTeamsAppIdentifierModel}.
*/
public static MicrosoftTeamsAppIdentifierModel convert(MicrosoftTeamsAppIdentifier microsoftTeamsAppIdentifier) {

MicrosoftTeamsAppIdentifierModel microsoftTeamsAppIdentifierModel
= (microsoftTeamsAppIdentifier == null || microsoftTeamsAppIdentifier.getAppId().isEmpty())
? null
: CommunicationIdentifierConverter
.convert(new MicrosoftTeamsAppIdentifier(microsoftTeamsAppIdentifier.getAppId()))
.getMicrosoftTeamsApp();
return microsoftTeamsAppIdentifierModel;
}

/**
* Converts to {@link MicrosoftTeamsAppIdentifier}.
*/
public static MicrosoftTeamsAppIdentifier
convert(MicrosoftTeamsAppIdentifierModel microsoftTeamsAppIdentifierModel) {

MicrosoftTeamsAppIdentifier microsoftTeamsAppIdentifier
= (microsoftTeamsAppIdentifierModel == null || microsoftTeamsAppIdentifierModel.getAppId().isEmpty())
? null
: new MicrosoftTeamsAppIdentifier(microsoftTeamsAppIdentifierModel.getAppId());

return microsoftTeamsAppIdentifier;
}

private MicrosoftTeamsAppIdentifierConverter() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public final class AnswerCallRequestInternal implements JsonSerializable<AnswerC
*/
private String callbackUri;

/*
* Used by customer to send custom calling context to targets when answering On-Behalf-Of call
*/
private CustomCallingContext customCallingContext;

/*
* A customer set value used to track the answering of a call.
*/
Expand Down Expand Up @@ -97,6 +102,28 @@ public AnswerCallRequestInternal setCallbackUri(String callbackUri) {
return this;
}

/**
* Get the customCallingContext property: Used by customer to send custom calling context to targets when answering
* On-Behalf-Of call.
*
* @return the customCallingContext value.
*/
public CustomCallingContext getCustomCallingContext() {
return this.customCallingContext;
}

/**
* Set the customCallingContext property: Used by customer to send custom calling context to targets when answering
* On-Behalf-Of call.
*
* @param customCallingContext the customCallingContext value to set.
* @return the AnswerCallRequestInternal object itself.
*/
public AnswerCallRequestInternal setCustomCallingContext(CustomCallingContext customCallingContext) {
this.customCallingContext = customCallingContext;
return this;
}

/**
* Get the operationContext property: A customer set value used to track the answering of a call.
*
Expand Down Expand Up @@ -208,6 +235,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("incomingCallContext", this.incomingCallContext);
jsonWriter.writeStringField("callbackUri", this.callbackUri);
jsonWriter.writeJsonField("customCallingContext", this.customCallingContext);
jsonWriter.writeStringField("operationContext", this.operationContext);
jsonWriter.writeJsonField("mediaStreamingConfiguration", this.mediaStreamingConfiguration);
jsonWriter.writeJsonField("transcriptionConfiguration", this.transcriptionConfiguration);
Expand Down Expand Up @@ -236,6 +264,8 @@ public static AnswerCallRequestInternal fromJson(JsonReader jsonReader) throws I
deserializedAnswerCallRequestInternal.incomingCallContext = reader.getString();
} else if ("callbackUri".equals(fieldName)) {
deserializedAnswerCallRequestInternal.callbackUri = reader.getString();
} else if ("customCallingContext".equals(fieldName)) {
deserializedAnswerCallRequestInternal.customCallingContext = CustomCallingContext.fromJson(reader);
} else if ("operationContext".equals(fieldName)) {
deserializedAnswerCallRequestInternal.operationContext = reader.getString();
} else if ("mediaStreamingConfiguration".equals(fieldName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public final class CreateCallRequestInternal implements JsonSerializable<CreateC
*/
private CommunicationUserIdentifierModel source;

/*
* The identifier of the source in an OPS call
*/
private MicrosoftTeamsAppIdentifierModel opsSource;

/*
* A customer set value used to track the answering of a call.
*/
Expand Down Expand Up @@ -158,6 +163,26 @@ public CreateCallRequestInternal setSource(CommunicationUserIdentifierModel sour
return this;
}

/**
* Get the opsSource property: The identifier of the source in an OPS call.
*
* @return the opsSource value.
*/
public MicrosoftTeamsAppIdentifierModel getOpsSource() {
return this.opsSource;
}

/**
* Set the opsSource property: The identifier of the source in an OPS call.
*
* @param opsSource the opsSource value to set.
* @return the CreateCallRequestInternal object itself.
*/
public CreateCallRequestInternal setOpsSource(MicrosoftTeamsAppIdentifierModel opsSource) {
this.opsSource = opsSource;
return this;
}

/**
* Get the operationContext property: A customer set value used to track the answering of a call.
*
Expand Down Expand Up @@ -292,6 +317,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeJsonField("sourceCallerIdNumber", this.sourceCallerIdNumber);
jsonWriter.writeStringField("sourceDisplayName", this.sourceDisplayName);
jsonWriter.writeJsonField("source", this.source);
jsonWriter.writeJsonField("opsSource", this.opsSource);
jsonWriter.writeStringField("operationContext", this.operationContext);
jsonWriter.writeJsonField("mediaStreamingConfiguration", this.mediaStreamingConfiguration);
jsonWriter.writeJsonField("transcriptionConfiguration", this.transcriptionConfiguration);
Expand Down Expand Up @@ -329,6 +355,8 @@ public static CreateCallRequestInternal fromJson(JsonReader jsonReader) throws I
deserializedCreateCallRequestInternal.sourceDisplayName = reader.getString();
} else if ("source".equals(fieldName)) {
deserializedCreateCallRequestInternal.source = CommunicationUserIdentifierModel.fromJson(reader);
} else if ("opsSource".equals(fieldName)) {
deserializedCreateCallRequestInternal.opsSource = MicrosoftTeamsAppIdentifierModel.fromJson(reader);
} else if ("operationContext".equals(fieldName)) {
deserializedCreateCallRequestInternal.operationContext = reader.getString();
} else if ("mediaStreamingConfiguration".equals(fieldName)) {
Expand Down
Loading

0 comments on commit 0f17a67

Please sign in to comment.