Skip to content

Commit

Permalink
Added OPS outgoing call (#46816)
Browse files Browse the repository at this point in the history
* Added OPS outgoing call

* updated API

* updated callInvite
  • Loading branch information
juntuchen-msft authored Oct 30, 2024
1 parent 4f733df commit d056e18
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public CallAutomationClient(string connectionString, Azure.Communication.CallAut
public CallAutomationClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.Communication.CallAutomation.CallAutomationClientOptions options = null) { }
public CallAutomationClient(System.Uri pmaEndpoint, string connectionString, Azure.Communication.CallAutomation.CallAutomationClientOptions options = null) { }
public CallAutomationClient(System.Uri pmaEndpoint, System.Uri acsEndpoint, Azure.Core.TokenCredential credential, Azure.Communication.CallAutomation.CallAutomationClientOptions options = null) { }
public Azure.Communication.MicrosoftTeamsAppIdentifier OPSSource { get { throw null; } }
public Azure.Communication.CommunicationUserIdentifier Source { get { throw null; } }
public virtual Azure.Response<Azure.Communication.CallAutomation.AnswerCallResult> AnswerCall(Azure.Communication.CallAutomation.AnswerCallOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.AnswerCallResult> AnswerCall(string incomingCallContext, System.Uri callbackUri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand All @@ -138,6 +139,7 @@ public CallAutomationClient(System.Uri pmaEndpoint, System.Uri acsEndpoint, Azur
public partial class CallAutomationClientOptions : Azure.Core.ClientOptions
{
public CallAutomationClientOptions(Azure.Communication.CallAutomation.CallAutomationClientOptions.ServiceVersion version = Azure.Communication.CallAutomation.CallAutomationClientOptions.ServiceVersion.V2023_10_03_Preview) { }
public Azure.Communication.MicrosoftTeamsAppIdentifier OPSSource { get { throw null; } set { } }
public Azure.Communication.CommunicationUserIdentifier Source { get { throw null; } set { } }
public enum ServiceVersion
{
Expand Down Expand Up @@ -341,6 +343,7 @@ public CallIntelligenceOptions() { }
public partial class CallInvite
{
public CallInvite(Azure.Communication.CommunicationUserIdentifier targetIdentity) { }
public CallInvite(Azure.Communication.MicrosoftTeamsAppIdentifier targetIdentity) { }
public CallInvite(Azure.Communication.MicrosoftTeamsUserIdentifier targetIdentity) { }
public CallInvite(Azure.Communication.PhoneNumberIdentifier targetPhoneNumberIdentity, Azure.Communication.PhoneNumberIdentifier callerIdNumber) { }
public Azure.Communication.CallAutomation.CustomCallingContext CustomCallingContext { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public class CallAutomationClient
/// </summary>
public CommunicationUserIdentifier Source { get; }

/// <summary>
/// MicrosoftTeamsAppIdentifier that makes the outbound call.
/// This can be provided by providing CallAutomationClientOption during construction of CallAutomationClient.
/// If left blank, Source is the default outbound call identity.
/// This should be mutual exclusive with Source.
/// </summary>
public MicrosoftTeamsAppIdentifier OPSSource { get; }

#region public constructors
/// <summary> Initializes a new instance of <see cref="CallAutomationClient"/>.</summary>
/// <param name="connectionString">Connection string acquired from the Azure Communication Services resource.</param>
Expand Down Expand Up @@ -119,6 +127,7 @@ private CallAutomationClient(Uri endpoint, HttpPipeline httpPipeline, CallAutoma
CallDialogRestClient = new CallDialogRestClient(_clientDiagnostics, httpPipeline, endpoint, options.ApiVersion);
EventProcessor = new CallAutomationEventProcessor();
Source = options.Source;
OPSSource = options.OPSSource;
}

private CallAutomationClient(
Expand Down Expand Up @@ -620,6 +629,7 @@ private CreateCallRequestInternal CreateCallRequest(CreateCallOptions options)
: new PhoneNumberIdentifierModel(options?.CallInvite?.SourceCallerIdNumber?.PhoneNumber),
SourceDisplayName = options?.CallInvite?.SourceDisplayName,
Source = Source == null ? null : new CommunicationUserIdentifierModel(Source.Id),
OpsSource = OPSSource == null ? null : new MicrosoftTeamsAppIdentifierModel(OPSSource.AppId),
};

request.CustomCallingContext = new CustomCallingContextInternal(
Expand Down Expand Up @@ -654,6 +664,7 @@ private CreateCallRequestInternal CreateCallRequest(CreateGroupCallOptions optio
: new PhoneNumberIdentifierModel(options?.SourceCallerIdNumber?.PhoneNumber),
SourceDisplayName = options?.SourceDisplayName,
Source = Source == null ? null : new CommunicationUserIdentifierModel(Source.Id),
OpsSource = OPSSource == null ? null : new MicrosoftTeamsAppIdentifierModel(OPSSource.AppId)
};

request.CustomCallingContext = new CustomCallingContextInternal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ public class CallAutomationClientOptions : ClientOptions

/// <summary>
/// The caller source of the call automation client.
/// Mutual exclusive with <see cref="OPSSource"/>.
/// </summary>
public CommunicationUserIdentifier Source { get; set; }

/// <summary>
/// The One Phone System caller source of the call automation client.
/// Mutual exclusive with <see cref="Source"/>.
/// </summary>
public MicrosoftTeamsAppIdentifier OPSSource { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="CallAutomationClientOptions"/>.
/// </summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public CallInvite(MicrosoftTeamsUserIdentifier targetIdentity)
CustomCallingContext = new CustomCallingContext(sipHeaders: null, voipHeaders: new Dictionary<string, string>());
}

/// <summary>
/// Creates a new CallInvite object.
/// </summary>
/// <param name="targetIdentity"></param>
public CallInvite(MicrosoftTeamsAppIdentifier targetIdentity)
{
Target = targetIdentity;
CustomCallingContext = new CustomCallingContext(sipHeaders: null, voipHeaders: new Dictionary<string, string>());
}

/// <summary>
/// The target callee.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ model-namespace: false
tag: package-2023-10-03-preview

require:
- https://github.com/Azure/azure-rest-api-specs/blob/73e737262249936932d2f7a3e3c400ce2b14a92c/specification/communication/data-plane/CallAutomation/readme.md
- https://github.com/Azure/azure-rest-api-specs/blob/be2a0fa68829fcb15c4e6b47aa6bc4bdd566c1cf/specification/communication/data-plane/CallAutomation/readme.md


title: Azure Communication Services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,38 @@ public void CreateCall_201Created(CallInvite target, Uri callbackUri)
Assert.AreEqual(CallConnectionId, result.CallConnection.CallConnectionId);
}

[TestCaseSource(nameof(TestData_CreateCall))]
public async Task CreateCallWithOPSSourceAsync_201Created(CallInvite target, Uri callbackUri)
{
CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(201, CreateOrAnswerCallOrGetCallConnectionPayloadForOPSCall, isOPSCall:true);

var options = new CreateCallOptions(target, callbackUri);
var response = await callAutomationClient.CreateCallAsync(options).ConfigureAwait(false);
CreateCallResult result = (CreateCallResult)response;
Assert.NotNull(result);
Assert.AreEqual((int)HttpStatusCode.Created, response.GetRawResponse().Status);
verifyOPSCallConnectionProperties(result.CallConnectionProperties);
Assert.Null(result.CallConnectionProperties.MediaSubscriptionId);
Assert.Null(result.CallConnectionProperties.DataSubscriptionId);
Assert.AreEqual(CallConnectionId, result.CallConnection.CallConnectionId);
}

[TestCaseSource(nameof(TestData_CreateCall))]
public void CreateCallWithOPSSource_201Created(CallInvite target, Uri callbackUri)
{
CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(201, CreateOrAnswerCallOrGetCallConnectionPayloadForOPSCall, isOPSCall: true);

var options = new CreateCallOptions(target, callbackUri);
var response = callAutomationClient.CreateCall(options);
CreateCallResult result = (CreateCallResult)response;
Assert.NotNull(result);
Assert.AreEqual((int)HttpStatusCode.Created, response.GetRawResponse().Status);
verifyOPSCallConnectionProperties(result.CallConnectionProperties);
Assert.Null(result.CallConnectionProperties.MediaSubscriptionId);
Assert.Null(result.CallConnectionProperties.DataSubscriptionId);
Assert.AreEqual(CallConnectionId, result.CallConnection.CallConnectionId);
}

[TestCaseSource(nameof(TestData_CreateCall))]
public async Task CreateCallWithOptionsAsync_201Created(CallInvite target, Uri callbackUri)
{
Expand Down Expand Up @@ -415,7 +447,19 @@ private static void ValidateCallConnectionProperties(CallConnectionProperties pr
{
new object?[]
{
new CallInvite(new CommunicationUserIdentifier("12345")),
new CallInvite(new CommunicationUserIdentifier("8:acs:12345")),
new Uri("https://bot.contoso.com/callback")
},
};
}

private static IEnumerable<object?[]> TestData_CreateOPSCall()
{
return new[]
{
new object?[]
{
new CallInvite(new MicrosoftTeamsAppIdentifier("28:acs:12345")),
new Uri("https://bot.contoso.com/callback")
},
};
Expand Down
Loading

0 comments on commit d056e18

Please sign in to comment.