Skip to content

Commit

Permalink
Remove SourceCallerIdNumber from Transfer API (Azure#35927)
Browse files Browse the repository at this point in the history
* remove SourceCallerId from Transfer API

* add simple method and fix unit test

* update public api

* add description
  • Loading branch information
fangchen0601 authored May 2, 2023
1 parent 1c71335 commit 0936533
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ protected CallConnection() { }
public virtual Azure.Response<Azure.Communication.CallAutomation.RemoveParticipantResult> RemoveParticipant(Azure.Communication.CommunicationIdentifier participantToRemove, string operationContext = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.RemoveParticipantResult>> RemoveParticipantAsync(Azure.Communication.CallAutomation.RemoveParticipantOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.RemoveParticipantResult>> RemoveParticipantAsync(Azure.Communication.CommunicationIdentifier participantToRemove, string operationContext = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.TransferCallToParticipantResult> TransferCallToParticipant(Azure.Communication.CallAutomation.CallInvite callInvite, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.TransferCallToParticipantResult> TransferCallToParticipant(Azure.Communication.CallAutomation.TransferToParticipantOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.TransferCallToParticipantResult>> TransferCallToParticipantAsync(Azure.Communication.CallAutomation.CallInvite callInvite, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.TransferCallToParticipantResult> TransferCallToParticipant(Azure.Communication.CommunicationIdentifier targetParticipant, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.TransferCallToParticipantResult>> TransferCallToParticipantAsync(Azure.Communication.CallAutomation.TransferToParticipantOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.TransferCallToParticipantResult>> TransferCallToParticipantAsync(Azure.Communication.CommunicationIdentifier targetParticipant, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.UnmuteParticipantsResponse> UnmuteParticipants(Azure.Communication.CallAutomation.UnmuteParticipantsOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.UnmuteParticipantsResponse> UnmuteParticipants(Azure.Communication.CommunicationIdentifier targetParticipant, string operationContext = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.UnmuteParticipantsResponse>> UnmuteParticipantsAsync(Azure.Communication.CallAutomation.UnmuteParticipantsOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -1098,9 +1098,13 @@ internal TransferCallToParticipantResult() { }
}
public partial class TransferToParticipantOptions
{
public TransferToParticipantOptions(Azure.Communication.CallAutomation.CallInvite callInvite) { }
public Azure.Communication.CallAutomation.CallInvite CallInvite { get { throw null; } }
public TransferToParticipantOptions(Azure.Communication.CommunicationUserIdentifier targetIdentity, System.Collections.Generic.IDictionary<string, string> voipHeaders = null) { }
public TransferToParticipantOptions(Azure.Communication.MicrosoftTeamsUserIdentifier targetIdentity, System.Collections.Generic.IDictionary<string, string> voipHeaders = null) { }
public TransferToParticipantOptions(Azure.Communication.PhoneNumberIdentifier targetPhoneNumberIdentity, System.Collections.Generic.IDictionary<string, string> sipHeaders = null) { }
public string OperationContext { get { throw null; } set { } }
public System.Collections.Generic.IDictionary<string, string> SipHeaders { get { throw null; } }
public Azure.Communication.CommunicationIdentifier Target { get { throw null; } }
public System.Collections.Generic.IDictionary<string, string> VoipHeaders { get { throw null; } }
}
public partial class UnmuteParticipantsOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,33 @@ public virtual Response HangUp(HangUpOptions options, CancellationToken cancella
}

/// <summary> Transfer this call to a participant. </summary>
/// <param name="callInvite"> The target to transfer the call to.</param>
/// <param name="targetParticipant"> The target to transfer the call to. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
/// <exception cref="ArgumentNullException"><paramref name="callInvite"/> is null.</exception>
public virtual async Task<Response<TransferCallToParticipantResult>> TransferCallToParticipantAsync(CallInvite callInvite, CancellationToken cancellationToken = default)
/// <exception cref="ArgumentNullException"><paramref name="targetParticipant"/> is null.</exception>
public virtual async Task<Response<TransferCallToParticipantResult>> TransferCallToParticipantAsync(CommunicationIdentifier targetParticipant, CancellationToken cancellationToken = default)
{
TransferToParticipantOptions options = new TransferToParticipantOptions(callInvite);
if (targetParticipant == null)
throw new ArgumentNullException(nameof(targetParticipant));

TransferToParticipantOptions options;

if (targetParticipant is CommunicationUserIdentifier)
{
options = new TransferToParticipantOptions(targetParticipant as CommunicationUserIdentifier);
}
else if (targetParticipant is PhoneNumberIdentifier)
{
options = new TransferToParticipantOptions(targetParticipant as PhoneNumberIdentifier);
}
else if (targetParticipant is MicrosoftTeamsUserIdentifier)
{
options = new TransferToParticipantOptions(targetParticipant as MicrosoftTeamsUserIdentifier);
}
else
{
throw new ArgumentException("targetParticipant type is invalid.", nameof(targetParticipant));
}

return await TransferCallToParticipantAsync(options, cancellationToken).ConfigureAwait(false);
}
Expand Down Expand Up @@ -239,13 +259,33 @@ public virtual async Task<Response<TransferCallToParticipantResult>> TransferCal
}

/// <summary> Transfer this call to a participant. </summary>
/// <param name="callInvite"> The target to transfer the call to.</param>
/// <param name="targetParticipant"> The target to transfer the call to. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
/// <exception cref="ArgumentNullException"><paramref name="callInvite"/> is null.</exception>
public virtual Response<TransferCallToParticipantResult> TransferCallToParticipant(CallInvite callInvite, CancellationToken cancellationToken = default)
/// <exception cref="ArgumentNullException"><paramref name="targetParticipant"/> is null.</exception>
public virtual Response<TransferCallToParticipantResult> TransferCallToParticipant(CommunicationIdentifier targetParticipant, CancellationToken cancellationToken = default)
{
TransferToParticipantOptions options = new TransferToParticipantOptions(callInvite);
if (targetParticipant == null)
throw new ArgumentNullException(nameof(targetParticipant));

TransferToParticipantOptions options;

if (targetParticipant is CommunicationUserIdentifier)
{
options = new TransferToParticipantOptions(targetParticipant as CommunicationUserIdentifier);
}
else if (targetParticipant is PhoneNumberIdentifier)
{
options = new TransferToParticipantOptions(targetParticipant as PhoneNumberIdentifier);
}
else if (targetParticipant is MicrosoftTeamsUserIdentifier)
{
options = new TransferToParticipantOptions(targetParticipant as MicrosoftTeamsUserIdentifier);
}
else
{
throw new ArgumentException("targetParticipant type is invalid.", nameof(targetParticipant));
}

return TransferCallToParticipant(options, cancellationToken);
}
Expand Down Expand Up @@ -290,11 +330,11 @@ public virtual Response<TransferCallToParticipantResult> TransferCallToParticipa

private static TransferToParticipantRequestInternal CreateTransferToParticipantRequest(TransferToParticipantOptions options)
{
TransferToParticipantRequestInternal request = new TransferToParticipantRequestInternal(CommunicationIdentifierSerializer.Serialize(options.CallInvite.Target));
TransferToParticipantRequestInternal request = new TransferToParticipantRequestInternal(CommunicationIdentifierSerializer.Serialize(options.Target));

request.CustomContext = new CustomContextInternal(
options.CallInvite.SipHeaders == null ? new ChangeTrackingDictionary<string, string>() : options.CallInvite.SipHeaders,
options.CallInvite.VoipHeaders == null ? new ChangeTrackingDictionary<string, string>() : options.CallInvite.VoipHeaders);
options.SipHeaders == null ? new ChangeTrackingDictionary<string, string>() : options.SipHeaders,
options.VoipHeaders == null ? new ChangeTrackingDictionary<string, string>() : options.VoipHeaders);

if (options.OperationContext != null && options.OperationContext.Length > CallAutomationConstants.InputValidation.StringMaxLength)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;

namespace Azure.Communication.CallAutomation
{
Expand All @@ -13,16 +14,47 @@ public class TransferToParticipantOptions
/// <summary>
/// Creates a new TransferToParticipantOptions object.
/// </summary>
/// <param name="callInvite"></param>
public TransferToParticipantOptions(CallInvite callInvite)
/// <param name="targetPhoneNumberIdentity"> The target to transfer the call to. </param>
/// <param name="sipHeaders"> Custom Context Sip headers. </param>
public TransferToParticipantOptions(PhoneNumberIdentifier targetPhoneNumberIdentity, IDictionary<string, string> sipHeaders = null)
{
CallInvite = callInvite;
Target = targetPhoneNumberIdentity;
SipHeaders = sipHeaders == null ? new Dictionary<string, string>() : sipHeaders;
}

/// <summary>
/// Call invitee information.
/// Creates a new TransferToParticipantOptions object.
/// </summary>
/// <param name="targetIdentity"> The target to transfer the call to. </param>
/// <param name="voipHeaders"> Custom Context Voip headers. </param>
public TransferToParticipantOptions(CommunicationUserIdentifier targetIdentity, IDictionary<string, string> voipHeaders = null)
{
Target = targetIdentity;
VoipHeaders = voipHeaders == null ? new Dictionary<string, string>() : voipHeaders;
}

/// <summary>
/// Creates a new TransferToParticipantOptions object.
/// </summary>
public CallInvite CallInvite { get; }
/// <param name="targetIdentity"> The target to transfer the call to. </param>
/// <param name="voipHeaders"> Custom Context Voip headers. </param>
public TransferToParticipantOptions(MicrosoftTeamsUserIdentifier targetIdentity, IDictionary<string, string> voipHeaders = null)
{
Target = targetIdentity;
VoipHeaders = voipHeaders == null ? new Dictionary<string, string>() : voipHeaders;
}

/// <summary>
/// The target callee.
/// </summary>
/// <value></value>
public CommunicationIdentifier Target { get; }

/// <summary> Dictionary of VOIP headers. </summary>
public IDictionary<string, string> VoipHeaders { get; }

/// <summary> Dictionary of SIP headers. </summary>
public IDictionary<string, string> SipHeaders { get; }

/// <summary>
/// The operationContext for this transfer call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task TransferCallToParticipantAsync_simpleMethod_202Accepted(CallIn
{
var callConnection = CreateMockCallConnection(202, OperationContextPayload);

var response = await callConnection.TransferCallToParticipantAsync(callInvite).ConfigureAwait(false);
var response = await callConnection.TransferCallToParticipantAsync(callInvite.Target).ConfigureAwait(false);
Assert.AreEqual((int)HttpStatusCode.Accepted, response.GetRawResponse().Status);
verifyOperationContext(response);
}
Expand All @@ -132,7 +132,7 @@ public async Task TransferCallToParticipantAsync_202Accepted(CallInvite callInvi
{
var callConnection = CreateMockCallConnection(202, OperationContextPayload);

var response = await callConnection.TransferCallToParticipantAsync(new TransferToParticipantOptions(callInvite)).ConfigureAwait(false);
var response = await callConnection.TransferCallToParticipantAsync(new TransferToParticipantOptions(callInvite.Target as CommunicationUserIdentifier)).ConfigureAwait(false);
Assert.AreEqual((int)HttpStatusCode.Accepted, response.GetRawResponse().Status);
verifyOperationContext(response);
}
Expand All @@ -142,7 +142,7 @@ public void TransferCallToParticipant_simpleMethod_202Accepted(CallInvite callIn
{
var callConnection = CreateMockCallConnection(202, OperationContextPayload);

var response = callConnection.TransferCallToParticipant(callInvite);
var response = callConnection.TransferCallToParticipant(callInvite.Target);
Assert.AreEqual((int)HttpStatusCode.Accepted, response.GetRawResponse().Status);
verifyOperationContext(response);
}
Expand All @@ -152,7 +152,7 @@ public void TransferCallToParticipant_202Accepted(CallInvite callInvite)
{
var callConnection = CreateMockCallConnection(202, OperationContextPayload);

var response = callConnection.TransferCallToParticipant(new TransferToParticipantOptions(callInvite));
var response = callConnection.TransferCallToParticipant(new TransferToParticipantOptions(callInvite.Target as CommunicationUserIdentifier));
Assert.AreEqual((int)HttpStatusCode.Accepted, response.GetRawResponse().Status);
verifyOperationContext(response);
}
Expand All @@ -162,7 +162,7 @@ public void TransferCallToParticipantAsync_404NotFound(CallInvite callInvite)
{
var callConnection = CreateMockCallConnection(404);

RequestFailedException? ex = Assert.ThrowsAsync<RequestFailedException>(async () => await callConnection.TransferCallToParticipantAsync(new TransferToParticipantOptions(callInvite)).ConfigureAwait(false));
RequestFailedException? ex = Assert.ThrowsAsync<RequestFailedException>(async () => await callConnection.TransferCallToParticipantAsync(new TransferToParticipantOptions(callInvite.Target as CommunicationUserIdentifier)).ConfigureAwait(false));
Assert.NotNull(ex);
Assert.AreEqual(ex?.Status, 404);
}
Expand All @@ -172,7 +172,7 @@ public void TransferCallToParticipant_404NotFound(CallInvite callInvite)
{
var callConnection = CreateMockCallConnection(404);

RequestFailedException? ex = Assert.Throws<RequestFailedException>(() => callConnection.TransferCallToParticipant(new TransferToParticipantOptions(callInvite)));
RequestFailedException? ex = Assert.Throws<RequestFailedException>(() => callConnection.TransferCallToParticipant(new TransferToParticipantOptions(callInvite.Target as CommunicationUserIdentifier)));
Assert.NotNull(ex);
Assert.AreEqual(ex?.Status, 404);
}
Expand All @@ -182,7 +182,7 @@ public void TransferCallToParticipant_ExceedsMaxOperationContextLength(CallInvit
{
var callConnection = CreateMockCallConnection(202);

var options = new TransferToParticipantOptions(callInvite) {
var options = new TransferToParticipantOptions(callInvite.Target as CommunicationUserIdentifier) {
OperationContext = new string('a', 1 + CallAutomationConstants.InputValidation.StringMaxLength)
};
ArgumentException? ex = Assert.Throws<ArgumentException>(() => callConnection.TransferCallToParticipant(options));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public async Task TransferCallEventResultSuccessTest()
CallAutomationEventProcessor handler = callConnection.EventProcessor;

var callInvite = new CallInvite(new CommunicationUserIdentifier(TargetUser));
var response = callConnection.TransferCallToParticipant(new TransferToParticipantOptions(callInvite));
var response = callConnection.TransferCallToParticipant(new TransferToParticipantOptions(callInvite.Target as CommunicationUserIdentifier));
Assert.AreEqual(successCode, response.GetRawResponse().Status);

// Create and send event to event processor
Expand All @@ -167,7 +167,7 @@ public async Task TransferCallEventResultFailedTest()
CallAutomationEventProcessor handler = callConnection.EventProcessor;

var callInvite = new CallInvite(new CommunicationUserIdentifier(TargetUser));
var response = callConnection.TransferCallToParticipant(new TransferToParticipantOptions(callInvite));
var response = callConnection.TransferCallToParticipant(new TransferToParticipantOptions(callInvite.Target as CommunicationUserIdentifier));
Assert.AreEqual(successCode, response.GetRawResponse().Status);

// Create and send event to event processor
Expand Down

0 comments on commit 0936533

Please sign in to comment.