Skip to content

Commit

Permalink
[Azure Communication Services][CallAutomation]Create Customcontext cl…
Browse files Browse the repository at this point in the history
…ass (#37548)

* create Customcontext class

* fix UT

* update api

* for groupcall, create both headers by default

* fix comments

* update api
  • Loading branch information
fangchen0601 authored Jul 13, 2023
1 parent 29c31fe commit df84a93
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,13 @@ internal CallDisconnected() { }
}
public partial class CallInvite
{
public CallInvite(Azure.Communication.CommunicationUserIdentifier targetIdentity, System.Collections.Generic.IDictionary<string, string> voipHeaders = null) { }
public CallInvite(Azure.Communication.MicrosoftTeamsUserIdentifier targetIdentity, System.Collections.Generic.IDictionary<string, string> voipHeaders = null) { }
public CallInvite(Azure.Communication.PhoneNumberIdentifier targetPhoneNumberIdentity, Azure.Communication.PhoneNumberIdentifier callerIdNumber, System.Collections.Generic.IDictionary<string, string> sipHeaders = null) { }
public System.Collections.Generic.IDictionary<string, string> SipHeaders { get { throw null; } }
public CallInvite(Azure.Communication.CommunicationUserIdentifier targetIdentity) { }
public CallInvite(Azure.Communication.MicrosoftTeamsUserIdentifier targetIdentity) { }
public CallInvite(Azure.Communication.PhoneNumberIdentifier targetPhoneNumberIdentity, Azure.Communication.PhoneNumberIdentifier callerIdNumber) { }
public Azure.Communication.CallAutomation.CustomContext CustomContext { get { throw null; } }
public Azure.Communication.PhoneNumberIdentifier SourceCallerIdNumber { get { throw null; } }
public string SourceDisplayName { get { throw null; } set { } }
public Azure.Communication.CommunicationIdentifier Target { get { throw null; } }
public System.Collections.Generic.IDictionary<string, string> VoipHeaders { get { throw null; } }
}
public abstract partial class CallLocator : System.IEquatable<Azure.Communication.CallAutomation.CallLocator>
{
Expand Down Expand Up @@ -526,13 +525,25 @@ public partial class CreateGroupCallOptions
public CreateGroupCallOptions(System.Collections.Generic.IEnumerable<Azure.Communication.CommunicationIdentifier> targets, System.Uri callbackUri) { }
public System.Uri AzureCognitiveServicesEndpointUrl { get { throw null; } set { } }
public System.Uri CallbackUri { get { throw null; } }
public Azure.Communication.CallAutomation.CustomContext CustomContext { get { throw null; } }
public Azure.Communication.CallAutomation.MediaStreamingOptions MediaStreamingOptions { get { throw null; } set { } }
public string OperationContext { get { throw null; } set { } }
public System.Collections.Generic.IDictionary<string, string> SipHeaders { get { throw null; } set { } }
public Azure.Communication.PhoneNumberIdentifier SourceCallerIdNumber { get { throw null; } set { } }
public string SourceDisplayName { get { throw null; } set { } }
public System.Collections.Generic.IEnumerable<Azure.Communication.CommunicationIdentifier> Targets { get { throw null; } }
public System.Collections.Generic.IDictionary<string, string> VoipHeaders { get { throw null; } set { } }
}
public partial class CustomContext
{
internal CustomContext() { }
public System.Collections.Generic.IDictionary<string, string> SipHeaders { get { throw null; } }
public System.Collections.Generic.IDictionary<string, string> VoipHeaders { get { throw null; } }
public void Add(Azure.Communication.CallAutomation.CustomContextHeader header) { }
}
public abstract partial class CustomContextHeader
{
protected CustomContextHeader(string key, string value) { }
public string Key { get { throw null; } }
public string Value { get { throw null; } }
}
public partial class DialogCompleted : Azure.Communication.CallAutomation.CallAutomationEventBase
{
Expand Down Expand Up @@ -1174,6 +1185,14 @@ public ServerCallLocator(string id) { }
public override int GetHashCode() { throw null; }
public override string ToString() { throw null; }
}
public partial class SIPCustomHeader : Azure.Communication.CallAutomation.CustomContextHeader
{
public SIPCustomHeader(string key, string value) : base (default(string), default(string)) { }
}
public partial class SIPUUIHeader : Azure.Communication.CallAutomation.CustomContextHeader
{
public SIPUUIHeader(string value) : base (default(string), default(string)) { }
}
public partial class SpeechResult : Azure.Communication.CallAutomation.RecognizeResult
{
internal SpeechResult() { }
Expand Down Expand Up @@ -1253,13 +1272,12 @@ internal TransferCallToParticipantResult() { }
}
public partial class TransferToParticipantOptions
{
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 TransferToParticipantOptions(Azure.Communication.CommunicationUserIdentifier targetIdentity) { }
public TransferToParticipantOptions(Azure.Communication.MicrosoftTeamsUserIdentifier targetIdentity) { }
public TransferToParticipantOptions(Azure.Communication.PhoneNumberIdentifier targetPhoneNumberIdentity) { }
public Azure.Communication.CallAutomation.CustomContext CustomContext { get { throw 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 All @@ -1277,4 +1295,8 @@ public partial class UserConsent
internal UserConsent() { }
public int? Recording { get { throw null; } }
}
public partial class VoipHeader : Azure.Communication.CallAutomation.CustomContextHeader
{
public VoipHeader(string key, string value) : base (default(string), default(string)) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ public virtual async Task<Response> RedirectCallAsync(RedirectCallOptions option
var repeatabilityHeaders = new RepeatabilityHeaders();

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.CallInvite.CustomContext.SipHeaders == null ? new ChangeTrackingDictionary<string, string>() : options.CallInvite.CustomContext.SipHeaders,
options.CallInvite.CustomContext.VoipHeaders == null ? new ChangeTrackingDictionary<string, string>() : options.CallInvite.CustomContext.VoipHeaders);

return await AzureCommunicationServicesRestClient.RedirectCallAsync(
request,
Expand Down Expand Up @@ -346,8 +346,8 @@ public virtual Response RedirectCall(RedirectCallOptions options, CancellationTo
var repeatabilityHeaders = new RepeatabilityHeaders();

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.CallInvite.CustomContext.SipHeaders == null ? new ChangeTrackingDictionary<string, string>() : options.CallInvite.CustomContext.SipHeaders,
options.CallInvite.CustomContext.VoipHeaders == null ? new ChangeTrackingDictionary<string, string>() : options.CallInvite.CustomContext.VoipHeaders);

return AzureCommunicationServicesRestClient.RedirectCall(
request,
Expand Down Expand Up @@ -674,8 +674,8 @@ private CreateCallRequestInternal CreateCallRequest(CreateCallOptions options)
};

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.CallInvite.CustomContext.SipHeaders == null ? new ChangeTrackingDictionary<string, string>() : options.CallInvite.CustomContext.SipHeaders,
options.CallInvite.CustomContext.VoipHeaders == null ? new ChangeTrackingDictionary<string, string>() : options.CallInvite.CustomContext.VoipHeaders);

// Add custom cognitive service domain name
if (options.AzureCognitiveServicesEndpointUrl != null)
Expand Down Expand Up @@ -706,8 +706,8 @@ private CreateCallRequestInternal CreateCallRequest(CreateGroupCallOptions optio
};

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

// Add custom cognitive service domain name
if (options.AzureCognitiveServicesEndpointUrl != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ private static TransferToParticipantRequestInternal CreateTransferToParticipantR
TransferToParticipantRequestInternal request = new TransferToParticipantRequestInternal(CommunicationIdentifierSerializer.Serialize(options.Target));

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

if (options.OperationContext != null && options.OperationContext.Length > CallAutomationConstants.InputValidation.StringMaxLength)
{
Expand Down Expand Up @@ -444,8 +444,8 @@ private static AddParticipantRequestInternal CreateAddParticipantRequest(AddPart
}

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

return request;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,31 @@ public class CallInvite
/// </summary>
/// <param name="targetPhoneNumberIdentity"></param>
/// <param name="callerIdNumber"></param>
/// /// <param name="sipHeaders"></param>
public CallInvite(PhoneNumberIdentifier targetPhoneNumberIdentity, PhoneNumberIdentifier callerIdNumber, IDictionary<string, string> sipHeaders = null)
public CallInvite(PhoneNumberIdentifier targetPhoneNumberIdentity, PhoneNumberIdentifier callerIdNumber)
{
Target = targetPhoneNumberIdentity;
SourceCallerIdNumber = callerIdNumber;
SipHeaders= sipHeaders == null ? new Dictionary<string, string>() : sipHeaders;
CustomContext = new CustomContext(sipHeaders: new Dictionary<string, string>(), voipHeaders: null);
}

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

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

/// <summary>
Expand All @@ -57,16 +54,15 @@ public CallInvite(MicrosoftTeamsUserIdentifier targetIdentity, IDictionary<strin
/// <value></value>
public PhoneNumberIdentifier SourceCallerIdNumber { 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 display name to appear on target callee.
/// </summary>
/// <value></value>
public string SourceDisplayName { get; set; }

/// <summary>
/// The Custom Context which contains SIP and voip headers
/// </summary>
public CustomContext CustomContext { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public CreateGroupCallOptions(IEnumerable<CommunicationIdentifier> targets, Uri
{
Targets = targets;
CallbackUri = callbackUri;
CustomContext = new CustomContext(sipHeaders: new Dictionary<string, string>(), voipHeaders: new Dictionary<string, string>());
}

/// <summary>
Expand Down Expand Up @@ -57,13 +58,8 @@ public CreateGroupCallOptions(IEnumerable<CommunicationIdentifier> targets, Uri
public Uri AzureCognitiveServicesEndpointUrl { get; set; }

/// <summary>
/// Custom Context for PSTN targets.
/// The Custom Context which contains SIP and voip headers.
/// </summary>
public IDictionary<string, string> SipHeaders { get; set; }

/// <summary>
/// Custom Context for Voip targets.
/// </summary>
public IDictionary<string, string> VoipHeaders { get; set; }
public CustomContext CustomContext { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;

namespace Azure.Communication.CallAutomation
{
/// <summary>
/// CustomContext details.
/// </summary>
public class CustomContext
{
/// <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>
/// Creates a new CustomContext.
/// </summary>
internal CustomContext(IDictionary<string, string> sipHeaders, IDictionary<string, string> voipHeaders)
{
SipHeaders = sipHeaders;
VoipHeaders = voipHeaders;
}

/// <summary>
/// Add a custom context sip or voip header.
/// </summary>
/// <param name="header">custom context sip UUI, custom header or voip header.</param>
public void Add(CustomContextHeader header)
{
if (header is SIPUUIHeader sipUUIHeader)
{
if (SipHeaders == null)
{
throw new InvalidOperationException("Cannot add sip header, SipHeaders is null.");
}
SipHeaders.Add(sipUUIHeader.Key, sipUUIHeader.Value);
}
else if (header is SIPCustomHeader sipCustomHeader)
{
if (SipHeaders == null)
{
throw new InvalidOperationException("Cannot add sip header, SipHeaders is null.");
}
SipHeaders.Add(sipCustomHeader.Key, sipCustomHeader.Value);
}
else if (header is VoipHeader voipHeader)
{
if (VoipHeaders == null)
{
throw new InvalidOperationException("Cannot add voip header, VoipHeaders is null");
}
VoipHeaders.Add(voipHeader.Key, voipHeader.Value);
}
else
{
throw new InvalidOperationException("Unknown custom context header type.");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Azure.Communication.CallAutomation
{
/// <summary>
/// The base class of CustomContext SipHeader and VoipHeader.
/// </summary>
public abstract class CustomContextHeader
{
/// <summary>
/// The CustomContext Key name.
/// </summary>
public string Key { get; }

/// <summary>
/// The CustomContext Key value.
/// </summary>
public string Value { get; }

/// <summary>
/// Creates a new CustomContextHeader
/// </summary>
protected CustomContextHeader(string key, string value)
{
Key = key;
Value = value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Azure.Communication.CallAutomation
{
/// <summary>
/// Custom Context Sip header.
/// </summary>
public class SIPCustomHeader : CustomContextHeader
{
/// <summary>
/// Create a new Sip header.
/// </summary>
/// <param name="key">sip header key name.</param>
/// <param name="value">sip header value.</param>
public SIPCustomHeader(string key, string value) : base("X-MS-Custom-"+key, value)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Azure.Communication.CallAutomation
{
/// <summary>
/// Custom Context User-to-User Sip header.
/// </summary>
public class SIPUUIHeader : CustomContextHeader
{
/// <summary>
/// Create a new Sip UUI header.
/// </summary>
/// <param name="value">CustomContext Sip UUI value.</param>
public SIPUUIHeader(string value) : base("User-to-User", value)
{
}
}
}
Loading

0 comments on commit df84a93

Please sign in to comment.