diff --git a/sdk/communication/Azure.Communication.CallAutomation/api/Azure.Communication.CallAutomation.netstandard2.0.cs b/sdk/communication/Azure.Communication.CallAutomation/api/Azure.Communication.CallAutomation.netstandard2.0.cs index 689f2d7ca0171..346174086aa3f 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/api/Azure.Communication.CallAutomation.netstandard2.0.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/api/Azure.Communication.CallAutomation.netstandard2.0.cs @@ -40,6 +40,7 @@ internal AddParticipantSucceeded() { } public partial class AnswerCallEventResult { internal AnswerCallEventResult() { } + public Azure.Communication.CallAutomation.AnswerFailed FailureResult { get { throw null; } } public bool IsSuccess { get { throw null; } } public Azure.Communication.CallAutomation.CallConnected SuccessResult { get { throw null; } } } @@ -63,6 +64,11 @@ internal AnswerCallResult() { } public Azure.Communication.CallAutomation.AnswerCallEventResult WaitForEventProcessor(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public System.Threading.Tasks.Task WaitForEventProcessorAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } + public partial class AnswerFailed : Azure.Communication.CallAutomation.CallAutomationEventBase + { + internal AnswerFailed() { } + public static Azure.Communication.CallAutomation.AnswerFailed Deserialize(string content) { throw null; } + } public partial class AudioData : Azure.Communication.CallAutomation.StreamingData { internal AudioData() { } @@ -181,6 +187,7 @@ public static partial class CallAutomationModelFactory public static Azure.Communication.CallAutomation.AddParticipantResult AddParticipantsResult(Azure.Communication.CallAutomation.CallParticipant participant = null, string operationContext = null, string invitationId = null) { throw null; } public static Azure.Communication.CallAutomation.AddParticipantSucceeded AddParticipantSucceeded(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, Azure.Communication.CommunicationIdentifier participant = null) { throw null; } public static Azure.Communication.CallAutomation.AnswerCallResult AnswerCallResult(Azure.Communication.CallAutomation.CallConnection callConnection = null, Azure.Communication.CallAutomation.CallConnectionProperties callConnectionProperties = null) { throw null; } + public static Azure.Communication.CallAutomation.AnswerFailed AnswerFailed(string callConnectionId = null, string serverCallId = null, string correlationId = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, string operationContext = null) { throw null; } public static Azure.Communication.CallAutomation.CallConnected CallConnected(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null) { throw null; } public static Azure.Communication.CallAutomation.CallConnectionProperties CallConnectionProperties(string callConnectionId = null, string serverCallId = null, System.Collections.Generic.IEnumerable targets = null, Azure.Communication.CallAutomation.CallConnectionState callConnectionState = default(Azure.Communication.CallAutomation.CallConnectionState), System.Uri callbackUri = null, Azure.Communication.CommunicationIdentifier sourceIdentity = null, Azure.Communication.PhoneNumberIdentifier sourceCallerIdNumber = null, string sourceDisplayName = null, Azure.Communication.CommunicationUserIdentifier answeredBy = null, string mediaSubscriptionId = null, string dataSubscriptionId = null) { throw null; } public static Azure.Communication.CallAutomation.CallDisconnected CallDisconnected(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null) { throw null; } @@ -195,6 +202,7 @@ public static partial class CallAutomationModelFactory public static Azure.Communication.CallAutomation.ContinuousDtmfRecognitionStopped ContinuousDtmfRecognitionStopped(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null) { throw null; } public static Azure.Communication.CallAutomation.ContinuousDtmfRecognitionToneFailed ContinuousDtmfRecognitionToneFailed(string callConnectionId = null, string serverCallId = null, string correlationId = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, string operationContext = null) { throw null; } public static Azure.Communication.CallAutomation.ContinuousDtmfRecognitionToneReceived ContinuousDtmfRecognitionToneReceived(int? sequenceId = default(int?), Azure.Communication.CallAutomation.DtmfTone? tone = default(Azure.Communication.CallAutomation.DtmfTone?), string callConnectionId = null, string serverCallId = null, string correlationId = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, string operationContext = null) { throw null; } + public static Azure.Communication.CallAutomation.CreateCallFailed CreateCallFailed(string callConnectionId = null, string serverCallId = null, string correlationId = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, string operationContext = null) { throw null; } public static Azure.Communication.CallAutomation.CreateCallResult CreateCallResult(Azure.Communication.CallAutomation.CallConnection callConnection = null, Azure.Communication.CallAutomation.CallConnectionProperties callConnectionProperties = null) { throw null; } public static Azure.Communication.CallAutomation.DtmfResult DtmfResult(System.Collections.Generic.IEnumerable tones = null) { throw null; } public static Azure.Communication.CallAutomation.MuteParticipantResult MuteParticipantResult(string operationContext = null) { throw null; } @@ -617,9 +625,15 @@ internal ContinuousDtmfRecognitionToneReceived() { } public partial class CreateCallEventResult { internal CreateCallEventResult() { } + public Azure.Communication.CallAutomation.CreateCallFailed FailureResult { get { throw null; } } public bool IsSuccess { get { throw null; } } public Azure.Communication.CallAutomation.CallConnected SuccessResult { get { throw null; } } } + public partial class CreateCallFailed : Azure.Communication.CallAutomation.CallAutomationEventBase + { + internal CreateCallFailed() { } + public static Azure.Communication.CallAutomation.CreateCallFailed Deserialize(string content) { throw null; } + } public partial class CreateCallOptions { public CreateCallOptions(Azure.Communication.CallAutomation.CallInvite callInvite, System.Uri callbackUri) { } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationEventProcessor/EventResult/AnswerCallEventResult.cs b/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationEventProcessor/EventResult/AnswerCallEventResult.cs index 72f748b768972..70a68b7da14fb 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationEventProcessor/EventResult/AnswerCallEventResult.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationEventProcessor/EventResult/AnswerCallEventResult.cs @@ -16,10 +16,17 @@ public class AnswerCallEventResult /// public CallConnected SuccessResult { get; } - internal AnswerCallEventResult(bool isSuccess, CallConnected successResult) + /// + /// evnet will be returned when the call was not answered. + /// + /// + public AnswerFailed FailureResult { get; } + + internal AnswerCallEventResult(bool isSuccess, CallConnected successResult, AnswerFailed failureResult) { IsSuccess = isSuccess; SuccessResult = successResult; + FailureResult = failureResult; } } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationEventProcessor/EventResult/CreateCallEventResult.cs b/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationEventProcessor/EventResult/CreateCallEventResult.cs index 4e98b10c991ea..b7a0414a7a05b 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationEventProcessor/EventResult/CreateCallEventResult.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationEventProcessor/EventResult/CreateCallEventResult.cs @@ -16,10 +16,17 @@ public class CreateCallEventResult /// public CallConnected SuccessResult { get; } - internal CreateCallEventResult(bool isSuccess, CallConnected successResult) + /// + /// evnet will be returned when the call was not created. + /// + /// + public CreateCallFailed FailureResult { get; } + + internal CreateCallEventResult(bool isSuccess, CallConnected successResult, CreateCallFailed failureResult) { IsSuccess = isSuccess; SuccessResult = successResult; + FailureResult = failureResult; } } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CallConnectionRestClient.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CallConnectionRestClient.cs index a3e117789d043..e830733f91458 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CallConnectionRestClient.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CallConnectionRestClient.cs @@ -598,7 +598,7 @@ public async Task> MuteAsync(string callConnecti await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { - case 202: + case 200: { MuteParticipantResult value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); @@ -630,7 +630,7 @@ public Response Mute(string callConnectionId, MutePartici _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { - case 202: + case 200: { MuteParticipantResult value = default; using var document = JsonDocument.Parse(message.Response.ContentStream); diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/AnswerFailedInternal.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/AnswerFailedInternal.Serialization.cs new file mode 100644 index 0000000000000..4464a6a7617bc --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/AnswerFailedInternal.Serialization.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + internal partial class AnswerFailedInternal + { + internal static AnswerFailedInternal DeserializeAnswerFailedInternal(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional operationContext = default; + Optional resultInformation = default; + Optional callConnectionId = default; + Optional serverCallId = default; + Optional correlationId = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("operationContext"u8)) + { + operationContext = property.Value.GetString(); + continue; + } + if (property.NameEquals("resultInformation"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + resultInformation = ResultInformation.DeserializeResultInformation(property.Value); + continue; + } + if (property.NameEquals("callConnectionId"u8)) + { + callConnectionId = property.Value.GetString(); + continue; + } + if (property.NameEquals("serverCallId"u8)) + { + serverCallId = property.Value.GetString(); + continue; + } + if (property.NameEquals("correlationId"u8)) + { + correlationId = property.Value.GetString(); + continue; + } + } + return new AnswerFailedInternal(operationContext.Value, resultInformation.Value, callConnectionId.Value, serverCallId.Value, correlationId.Value); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/AnswerFailedInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/AnswerFailedInternal.cs new file mode 100644 index 0000000000000..3798b80585463 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/AnswerFailedInternal.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Communication.CallAutomation +{ + /// AnswerFailed event. + internal partial class AnswerFailedInternal + { + /// Initializes a new instance of . + internal AnswerFailedInternal() + { + } + + /// Initializes a new instance of . + /// Used by customers when calling mid-call actions to correlate the request to the response event. + /// Contains the resulting SIP code, sub-code and message. + /// Call connection ID. + /// Server call ID. + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + internal AnswerFailedInternal(string operationContext, ResultInformation resultInformation, string callConnectionId, string serverCallId, string correlationId) + { + OperationContext = operationContext; + ResultInformation = resultInformation; + CallConnectionId = callConnectionId; + ServerCallId = serverCallId; + CorrelationId = correlationId; + } + + /// Used by customers when calling mid-call actions to correlate the request to the response event. + public string OperationContext { get; } + /// Contains the resulting SIP code, sub-code and message. + public ResultInformation ResultInformation { get; } + /// Call connection ID. + public string CallConnectionId { get; } + /// Server call ID. + public string ServerCallId { get; } + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + public string CorrelationId { get; } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CallConnectionPropertiesInternal.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CallConnectionPropertiesInternal.Serialization.cs index 7e806555aa642..c5ad585328001 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CallConnectionPropertiesInternal.Serialization.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CallConnectionPropertiesInternal.Serialization.cs @@ -32,7 +32,7 @@ internal static CallConnectionPropertiesInternal DeserializeCallConnectionProper Optional source = default; Optional correlationId = default; Optional answeredBy = default; - Optional originalPSTNTarget = default; + Optional originalPstnTarget = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("callConnectionId"u8)) @@ -120,17 +120,17 @@ internal static CallConnectionPropertiesInternal DeserializeCallConnectionProper answeredBy = CommunicationUserIdentifierModel.DeserializeCommunicationUserIdentifierModel(property.Value); continue; } - if (property.NameEquals("originalPSTNTarget"u8)) + if (property.NameEquals("originalPstnTarget"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } - originalPSTNTarget = PhoneNumberIdentifierModel.DeserializePhoneNumberIdentifierModel(property.Value); + originalPstnTarget = PhoneNumberIdentifierModel.DeserializePhoneNumberIdentifierModel(property.Value); continue; } } - return new CallConnectionPropertiesInternal(callConnectionId.Value, serverCallId.Value, Optional.ToList(targets), Optional.ToNullable(callConnectionState), callbackUri.Value, mediaSubscriptionId.Value, dataSubscriptionId.Value, sourceCallerIdNumber.Value, sourceDisplayName.Value, source.Value, correlationId.Value, answeredBy.Value, originalPSTNTarget.Value); + return new CallConnectionPropertiesInternal(callConnectionId.Value, serverCallId.Value, Optional.ToList(targets), Optional.ToNullable(callConnectionState), callbackUri.Value, mediaSubscriptionId.Value, dataSubscriptionId.Value, sourceCallerIdNumber.Value, sourceDisplayName.Value, source.Value, correlationId.Value, answeredBy.Value, originalPstnTarget.Value); } } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CreateCallFailedInternal.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CreateCallFailedInternal.Serialization.cs new file mode 100644 index 0000000000000..beda467b6cd61 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CreateCallFailedInternal.Serialization.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + internal partial class CreateCallFailedInternal + { + internal static CreateCallFailedInternal DeserializeCreateCallFailedInternal(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional operationContext = default; + Optional resultInformation = default; + Optional callConnectionId = default; + Optional serverCallId = default; + Optional correlationId = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("operationContext"u8)) + { + operationContext = property.Value.GetString(); + continue; + } + if (property.NameEquals("resultInformation"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + resultInformation = ResultInformation.DeserializeResultInformation(property.Value); + continue; + } + if (property.NameEquals("callConnectionId"u8)) + { + callConnectionId = property.Value.GetString(); + continue; + } + if (property.NameEquals("serverCallId"u8)) + { + serverCallId = property.Value.GetString(); + continue; + } + if (property.NameEquals("correlationId"u8)) + { + correlationId = property.Value.GetString(); + continue; + } + } + return new CreateCallFailedInternal(operationContext.Value, resultInformation.Value, callConnectionId.Value, serverCallId.Value, correlationId.Value); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CreateCallFailedInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CreateCallFailedInternal.cs new file mode 100644 index 0000000000000..506c8ca5891e7 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CreateCallFailedInternal.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Communication.CallAutomation +{ + /// The CreateCallFailed event. + internal partial class CreateCallFailedInternal + { + /// Initializes a new instance of . + internal CreateCallFailedInternal() + { + } + + /// Initializes a new instance of . + /// Used by customers when calling mid-call actions to correlate the request to the response event. + /// Contains the resulting SIP code, sub-code and message. + /// Call connection ID. + /// Server call ID. + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + internal CreateCallFailedInternal(string operationContext, ResultInformation resultInformation, string callConnectionId, string serverCallId, string correlationId) + { + OperationContext = operationContext; + ResultInformation = resultInformation; + CallConnectionId = callConnectionId; + ServerCallId = serverCallId; + CorrelationId = correlationId; + } + + /// Used by customers when calling mid-call actions to correlate the request to the response event. + public string OperationContext { get; } + /// Contains the resulting SIP code, sub-code and message. + public ResultInformation ResultInformation { get; } + /// Call connection ID. + public string CallConnectionId { get; } + /// Server call ID. + public string ServerCallId { get; } + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + public string CorrelationId { get; } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/AnswerCallResult.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/AnswerCallResult.cs index 848a8fb66986a..eb7908c0ea1dd 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Models/AnswerCallResult.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/AnswerCallResult.cs @@ -49,7 +49,7 @@ public AnswerCallEventResult WaitForEventProcessor(CancellationToken cancellatio var returnedEvent = _evHandler.WaitForEventProcessor(filter => filter.CallConnectionId == _callConnectionId && (filter.OperationContext == _operationContext || _operationContext is null) - && filter.GetType() == typeof(CallConnected), + && (filter.GetType() == typeof(CallConnected) || filter.GetType() == typeof(AnswerFailed)), cancellationToken); return SetReturnedEvent(returnedEvent); @@ -70,7 +70,7 @@ public async Task WaitForEventProcessorAsync(Cancellation var returnedEvent = await _evHandler.WaitForEventProcessorAsync(filter => filter.CallConnectionId == _callConnectionId && (filter.OperationContext == _operationContext || _operationContext is null) - && filter.GetType() == typeof(CallConnected), + && (filter.GetType() == typeof(CallConnected) || filter.GetType() == typeof(AnswerFailed)), cancellationToken).ConfigureAwait(false); return SetReturnedEvent(returnedEvent); @@ -78,7 +78,15 @@ public async Task WaitForEventProcessorAsync(Cancellation private static AnswerCallEventResult SetReturnedEvent(CallAutomationEventBase returnedEvent) { - return new AnswerCallEventResult(true, (CallConnected)returnedEvent); + switch (returnedEvent) + { + case CallConnected: + return new AnswerCallEventResult(true, (CallConnected)returnedEvent, null); + case AnswerFailed: + return new AnswerCallEventResult(false, null, (AnswerFailed)returnedEvent); + default: + throw new NotSupportedException(returnedEvent.GetType().Name); + } } } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CallAutomationModelFactory.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CallAutomationModelFactory.cs index c78044b9721f0..5f4a360dee35a 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CallAutomationModelFactory.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CallAutomationModelFactory.cs @@ -293,6 +293,46 @@ public static CancelAddParticipantFailed CancelAddParticipantFailed( return new CancelAddParticipantFailed(internalObject); } + /// + /// Initializes a new instance of create call failed event. + /// + public static CreateCallFailed CreateCallFailed( + string callConnectionId = default, + string serverCallId = default, + string correlationId = default, + ResultInformation resultInformation = default, + string operationContext = default) + { + var internalObject = new CreateCallFailedInternal( + operationContext, + resultInformation, + callConnectionId, + serverCallId, + correlationId); + + return new CreateCallFailed(internalObject); + } + + /// + /// Initializes a new instance of answer failed event. + /// + public static AnswerFailed AnswerFailed( + string callConnectionId = default, + string serverCallId = default, + string correlationId = default, + ResultInformation resultInformation = default, + string operationContext = default) + { + var internalObject = new AnswerFailedInternal( + operationContext, + resultInformation, + callConnectionId, + serverCallId, + correlationId); + + return new AnswerFailed(internalObject); + } + /// Initializes a new instance of CallConnected. /// Call connection ID. /// Server call ID. diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateCallResult.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateCallResult.cs index 599fcb96b8af1..334fdc085e32c 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateCallResult.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateCallResult.cs @@ -48,7 +48,7 @@ public CreateCallEventResult WaitForEventProcessor(CancellationToken cancellatio var returnedEvent = _evHandler.WaitForEventProcessor(filter => filter.CallConnectionId == _callConnectionId && (filter.OperationContext == _operationContext || _operationContext is null) - && filter.GetType() == typeof(CallConnected), + && (filter.GetType() == typeof(CallConnected) || filter.GetType() == typeof(CreateCallFailed)), cancellationToken); return SetReturnedEvent(returnedEvent); @@ -69,7 +69,7 @@ public async Task WaitForEventProcessorAsync(Cancellation var returnedEvent = await _evHandler.WaitForEventProcessorAsync(filter => filter.CallConnectionId == _callConnectionId && (filter.OperationContext == _operationContext || _operationContext is null) - && filter.GetType() == typeof(CallConnected), + && (filter.GetType() == typeof(CallConnected) || filter.GetType() == typeof(CreateCallFailed)), cancellationToken).ConfigureAwait(false); return SetReturnedEvent(returnedEvent); @@ -77,7 +77,15 @@ public async Task WaitForEventProcessorAsync(Cancellation private static CreateCallEventResult SetReturnedEvent(CallAutomationEventBase returnedEvent) { - return new CreateCallEventResult(true, (CallConnected)returnedEvent); + switch (returnedEvent) + { + case CallConnected: + return new CreateCallEventResult(true, (CallConnected)returnedEvent, null); + case CreateCallFailed: + return new CreateCallEventResult(false, null, (CreateCallFailed)returnedEvent); + default: + throw new NotSupportedException(returnedEvent.GetType().Name); + } } } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/AnswerFailed.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/AnswerFailed.cs new file mode 100644 index 0000000000000..cdfdde748b379 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/AnswerFailed.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; + +namespace Azure.Communication.CallAutomation +{ + /// + /// The answer failed event. + /// + public partial class AnswerFailed : CallAutomationEventBase + { + /// Initializes a new instance of AnswerFailed. + internal AnswerFailed() + { + } + + internal AnswerFailed(AnswerFailedInternal internalEvent) + { + OperationContext = internalEvent.OperationContext; + ResultInformation = internalEvent.ResultInformation; + CallConnectionId = internalEvent.CallConnectionId; + ServerCallId = internalEvent.ServerCallId; + CorrelationId = internalEvent.CorrelationId; + } + + /// + /// Deserialize event. + /// + /// The json content. + /// The new object. + public static AnswerFailed Deserialize(string content) + { + using var document = JsonDocument.Parse(content); + JsonElement element = document.RootElement; + var internalEvent = AnswerFailedInternal.DeserializeAnswerFailedInternal(element); + return new AnswerFailed(internalEvent); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/AnswerFailedInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/AnswerFailedInternal.cs new file mode 100644 index 0000000000000..7744582a0bebc --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/AnswerFailedInternal.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + /// + /// The answer failed event internal. + /// + [CodeGenModel("AnswerFailed", Usage = new string[] { "output" }, Formats = new string[] { "json" })] + internal partial class AnswerFailedInternal + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CallAutomationEventParser.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CallAutomationEventParser.cs index 155668c98bbee..9efa05fe23bde 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CallAutomationEventParser.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CallAutomationEventParser.cs @@ -150,6 +150,10 @@ private static CallAutomationEventBase Deserialize(string eventData, string type return TranscriptionStopped.Deserialize(eventData); case nameof(TranscriptionFailed): return TranscriptionFailed.Deserialize(eventData); + case nameof(AnswerFailed): + return AnswerFailed.Deserialize(eventData); + case nameof(CreateCallFailed): + return CreateCallFailed.Deserialize(eventData); #region Dialog case nameof(DialogCompleted): return DialogCompleted.Deserialize(eventData); diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CreateCallFailed.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CreateCallFailed.cs new file mode 100644 index 0000000000000..64979e1525ec0 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CreateCallFailed.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; + +namespace Azure.Communication.CallAutomation +{ + /// + /// The create call failed event. + /// + public partial class CreateCallFailed : CallAutomationEventBase + { + /// Initializes a new instance of CreateCallFailed. + internal CreateCallFailed() + { + } + + internal CreateCallFailed(CreateCallFailedInternal internalEvent) + { + OperationContext = internalEvent.OperationContext; + ResultInformation = internalEvent.ResultInformation; + CallConnectionId = internalEvent.CallConnectionId; + ServerCallId = internalEvent.ServerCallId; + CorrelationId = internalEvent.CorrelationId; + } + + /// + /// Deserialize event. + /// + /// The json content. + /// The new object. + public static CreateCallFailed Deserialize(string content) + { + using var document = JsonDocument.Parse(content); + JsonElement element = document.RootElement; + var internalEvent = CreateCallFailedInternal.DeserializeCreateCallFailedInternal(element); + return new CreateCallFailed(internalEvent); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CreateCallFailedInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CreateCallFailedInternal.cs new file mode 100644 index 0000000000000..d439eb1e72bd7 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CreateCallFailedInternal.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + /// + /// The create call failed event internal. + /// + [CodeGenModel("CreateCallFailed", Usage = new string[] { "output" }, Formats = new string[] { "json" })] + internal partial class CreateCallFailedInternal + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/autorest.md b/sdk/communication/Azure.Communication.CallAutomation/src/autorest.md index d6bba19cfbb62..c6b16add72f45 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/autorest.md +++ b/sdk/communication/Azure.Communication.CallAutomation/src/autorest.md @@ -10,7 +10,7 @@ model-namespace: false tag: package-2023-10-03-preview require: - - https://github.com/Azure/azure-rest-api-specs/blob/384aedb56cfbadfa16ccb35737eab58dfeae81c5/specification/communication/data-plane/CallAutomation/readme.md + - https://github.com/Azure/azure-rest-api-specs/blob/3abbcd8fe3f0527560c7db59255f654366e965d8/specification/communication/data-plane/CallAutomation/readme.md title: Azure Communication Services diff --git a/sdk/communication/Azure.Communication.CallAutomation/tests/CallConnections/CallConnectionTests.cs b/sdk/communication/Azure.Communication.CallAutomation/tests/CallConnections/CallConnectionTests.cs index 259ce4fba794a..fafda426262e7 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/tests/CallConnections/CallConnectionTests.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/tests/CallConnections/CallConnectionTests.cs @@ -396,12 +396,12 @@ public void GetCallMediaTest() } [TestCaseSource(nameof(TestData_MuteParticipant))] - public void MuteParticipant_202Accepted(CommunicationIdentifier participant) + public void MuteParticipant_200Ok(CommunicationIdentifier participant) { - var callConnection = CreateMockCallConnection(202, OperationContextPayload); + var callConnection = CreateMockCallConnection(200, OperationContextPayload); var response = callConnection.MuteParticipant(participant); - Assert.AreEqual((int)HttpStatusCode.Accepted, response.GetRawResponse().Status); + Assert.AreEqual((int)HttpStatusCode.OK, response.GetRawResponse().Status); } [TestCaseSource(nameof(TestData_MuteParticipant))] @@ -414,15 +414,15 @@ public void UnmuteParticipant_200Accepted(CommunicationIdentifier participant) } [TestCaseSource(nameof(TestData_MuteParticipant))] - public void MuteParticipant_WithOptions_202Accepted(CommunicationIdentifier participant) + public void MuteParticipant_WithOptions_200Ok(CommunicationIdentifier participant) { - var callConnection = CreateMockCallConnection(202, OperationContextPayload); + var callConnection = CreateMockCallConnection(200, OperationContextPayload); var options = new MuteParticipantOptions(participant) { OperationContext = OperationContext }; var response = callConnection.MuteParticipant(options); - Assert.AreEqual((int)HttpStatusCode.Accepted, response.GetRawResponse().Status); + Assert.AreEqual((int)HttpStatusCode.OK, response.GetRawResponse().Status); Assert.AreEqual(OperationContext, response.Value.OperationContext); } @@ -441,12 +441,12 @@ public void UnmuteParticipant_WithOptions_200Accepted(CommunicationIdentifier pa } [TestCaseSource(nameof(TestData_MuteParticipant))] - public async Task MuteParticipantAsync_202Accepted(CommunicationIdentifier participant) + public async Task MuteParticipantAsync_200Accepted(CommunicationIdentifier participant) { - var callConnection = CreateMockCallConnection(202, OperationContextPayload); + var callConnection = CreateMockCallConnection(200, OperationContextPayload); var response = await callConnection.MuteParticipantAsync(participant); - Assert.AreEqual((int)HttpStatusCode.Accepted, response.GetRawResponse().Status); + Assert.AreEqual((int)HttpStatusCode.OK, response.GetRawResponse().Status); } [Test] @@ -475,16 +475,16 @@ public void UnmuteParticipantAsync_NotAcsUser_400BadRequest() } [TestCaseSource(nameof(TestData_MuteParticipant))] - public async Task MuteParticipantAsync_WithOptions_202OK(CommunicationIdentifier participant) + public async Task MuteParticipantAsync_WithOptions_200OK(CommunicationIdentifier participant) { - var callConnection = CreateMockCallConnection(202, OperationContextPayload); + var callConnection = CreateMockCallConnection(200, OperationContextPayload); var options = new MuteParticipantOptions(participant) { OperationContext = OperationContext, }; var response = await callConnection.MuteParticipantAsync(options); - Assert.AreEqual((int)HttpStatusCode.Accepted, response.GetRawResponse().Status); + Assert.AreEqual((int)HttpStatusCode.OK, response.GetRawResponse().Status); Assert.AreEqual(OperationContext, response.Value.OperationContext); } diff --git a/sdk/communication/Azure.Communication.CallAutomation/tests/EventProcessors/ResultWithEventProcessorAsyncTests.cs b/sdk/communication/Azure.Communication.CallAutomation/tests/EventProcessors/ResultWithEventProcessorAsyncTests.cs index e7dc9d17bebb7..396bc43ab288c 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/tests/EventProcessors/ResultWithEventProcessorAsyncTests.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/tests/EventProcessors/ResultWithEventProcessorAsyncTests.cs @@ -58,20 +58,17 @@ public async Task CreateCallEventResultFailedTest() var response = callAutomationClient.CreateCall(new CreateCallOptions(CreateMockInvite(), new Uri(CallBackUri))); Assert.AreEqual(successCode, response.GetRawResponse().Status); - // Create and send event to event processor - SendAndProcessEvent(handler, new CallConnected("mismatchedOperationId", CallConnectionId, ServerCallId, CorelationId)); + SendAndProcessEvent(handler, new CreateCallFailed(new CreateCallFailedInternal("mismatchedOperationId", null, CallConnectionId, ServerCallId, CorelationId))); - try - { - CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(3)); - CancellationToken token = cts.Token; - _ = await response.Value.WaitForEventProcessorAsync(token); - } - catch (TimeoutException) - { - // success - return; - } + CreateCallEventResult returnedResult = await response.Value.WaitForEventProcessorAsync(); + + // Assert + Assert.NotNull(returnedResult); + Assert.AreEqual(false, returnedResult.IsSuccess); + Assert.NotNull(returnedResult.FailureResult); + Assert.IsNull(returnedResult.SuccessResult); + Assert.AreEqual(typeof(CreateCallFailed), returnedResult.FailureResult.GetType()); + Assert.AreEqual(CallConnectionId, returnedResult.FailureResult.CallConnectionId); } [Test] @@ -117,19 +114,17 @@ public async Task AnswerCallEventResultFailedTest() Assert.AreEqual(successCode, response.GetRawResponse().Status); // Create and send event to event processor - SendAndProcessEvent(handler, new CallConnected("mismatchedOperationId", CallConnectionId, ServerCallId, CorelationId)); + SendAndProcessEvent(handler, new AnswerFailed(new AnswerFailedInternal("mismatchedOperationId", null, CallConnectionId, ServerCallId, CorelationId))); - try - { - CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(3)); - CancellationToken token = cts.Token; - _ = await response.Value.WaitForEventProcessorAsync(); - } - catch (TimeoutException) - { - // Success - return; - } + AnswerCallEventResult returnedResult = await response.Value.WaitForEventProcessorAsync(); + + // Assert + Assert.NotNull(returnedResult); + Assert.AreEqual(false, returnedResult.IsSuccess); + Assert.NotNull(returnedResult.FailureResult); + Assert.IsNull(returnedResult.SuccessResult); + Assert.AreEqual(typeof(AnswerFailed), returnedResult.FailureResult.GetType()); + Assert.AreEqual(CallConnectionId, returnedResult.FailureResult.CallConnectionId); } [Test] diff --git a/sdk/communication/Azure.Communication.CallAutomation/tests/Events/CallAutomationEventParserTests.cs b/sdk/communication/Azure.Communication.CallAutomation/tests/Events/CallAutomationEventParserTests.cs index 0ed9e72d9b257..bdb43a38ea64c 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/tests/Events/CallAutomationEventParserTests.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/tests/Events/CallAutomationEventParserTests.cs @@ -942,6 +942,60 @@ public void CancelAddParticipantFailedEventParsed_Test() } } + [Test] + public void CreateCallFailedEventParsed_Test() + { + CreateCallFailed @event = CallAutomationModelFactory.CreateCallFailed( + callConnectionId: "callConnectionId", + serverCallId: "serverCallId", + correlationId: "correlationId", + resultInformation: new ResultInformation(code: 400, subCode: 8510, message: "Action failed, some error."), + operationContext: "operationContext"); + JsonSerializerOptions jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; + string jsonEvent = JsonSerializer.Serialize(@event, jsonOptions); + var parsedEvent = CallAutomationEventParser.Parse(jsonEvent, "Microsoft.Communication.CreateCallFailed"); + + if (parsedEvent is CreateCallFailed createCallFailed) + { + Assert.AreEqual("operationContext", createCallFailed.OperationContext); + Assert.AreEqual("callConnectionId", createCallFailed.CallConnectionId); + Assert.AreEqual("correlationId", createCallFailed.CorrelationId); + Assert.AreEqual("serverCallId", createCallFailed.ServerCallId); + Assert.AreEqual(400, createCallFailed.ResultInformation?.Code); + } + else + { + Assert.Fail("Event parsed wrongfully"); + } + } + + [Test] + public void AnswerFailedEventParsed_Test() + { + AnswerFailed @event = CallAutomationModelFactory.AnswerFailed( + callConnectionId: "callConnectionId", + serverCallId: "serverCallId", + correlationId: "correlationId", + resultInformation: new ResultInformation(code: 400, subCode: 8510, message: "Action failed, some error."), + operationContext: "operationContext"); + JsonSerializerOptions jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; + string jsonEvent = JsonSerializer.Serialize(@event, jsonOptions); + var parsedEvent = CallAutomationEventParser.Parse(jsonEvent, "Microsoft.Communication.AnswerFailed"); + + if (parsedEvent is AnswerFailed answerFailed) + { + Assert.AreEqual("operationContext", answerFailed.OperationContext); + Assert.AreEqual("callConnectionId", answerFailed.CallConnectionId); + Assert.AreEqual("correlationId", answerFailed.CorrelationId); + Assert.AreEqual("serverCallId", answerFailed.ServerCallId); + Assert.AreEqual(400, answerFailed.ResultInformation?.Code); + } + else + { + Assert.Fail("Event parsed wrongfully"); + } + } + [Test] public void TranscriptionStartedEventParsed_Test() {