From 42f7757cf8f34d2743f55f28d7e776607ef174e8 Mon Sep 17 00:00:00 2001 From: Vivek More <123148745+vivekmore-msft@users.noreply.github.com> Date: Thu, 28 Sep 2023 22:08:18 +0530 Subject: [PATCH] Added transcription APIs and events (#38988) * Autorest generated code * Adding SDK methods for start, stop and update transcription * Add transcription options for the create & answer call * Adding events * Adding event parser test cases * Adding tests * Refactoring code to make options param optional * Adding models and parser for the transcription schema * Fixing enum conversion logic for transcription schema * Cleaning up code * Add transcription options in create/answer/group call and tests * Updted TranscriptionUpdate to take TranscriptionUpdate and TranscriptionStatusDetails as enums * Fixed API typo * Adding SDK methods for start, stop and update transcription * Add transcription options for the create & answer call * Adding models and parser for the transcription schema * Adding events * Adding event parser test cases * Adding tests * Refactoring code to make options param optional * Fixing enum conversion logic for transcription schema * Cleaning up code * Add transcription options in create/answer/group call and tests * Updted TranscriptionUpdate to take TranscriptionUpdate and TranscriptionStatusDetails as enums * Fixed API typo * Updated contract after rebase * Removed duplicate tests * Update in transcription ws schema * Fixed TranscriptionOptions review comment * Fixing TranscriptionOptions arguments in create call, group call & answer call * Fixing build issues --------- Co-authored-by: abhishesingh-msft --- ...unication.CallAutomation.netstandard2.0.cs | 161 ++++++++++++++-- .../src/CallAutomationClient.cs | 11 +- .../src/CallMedia.cs | 144 ++++++++++++++ .../src/Generated/CallMediaRestClient.cs | 20 +- ...CommunicationCallAutomationModelFactory.cs | 61 ++++++ .../Models/AnswerCallRequestInternal.cs | 2 +- .../Models/CreateCallRequestInternal.cs | 2 +- ...scriptionRequestInternal.Serialization.cs} | 2 +- ...s => StartTranscriptionRequestInternal.cs} | 6 +- ...scriptionRequestInternal.Serialization.cs} | 2 +- ...cs => StopTranscriptionRequestInternal.cs} | 6 +- .../TranscriptionFailed.Serialization.cs | 71 +++++++ .../Generated/Models/TranscriptionFailed.cs | 28 +-- ...scriptionOptionsInternal.Serialization.cs} | 2 +- ...ion.cs => TranscriptionOptionsInternal.cs} | 8 +- .../TranscriptionResumed.Serialization.cs | 71 +++++++ .../Generated/Models/TranscriptionResumed.cs | 28 +-- .../TranscriptionStarted.Serialization.cs | 71 +++++++ .../Generated/Models/TranscriptionStarted.cs | 28 +-- .../Generated/Models/TranscriptionStatus.cs | 63 ++++++ .../Models/TranscriptionStatusDetails.cs | 72 +++++++ .../TranscriptionStopped.Serialization.cs | 71 +++++++ .../Generated/Models/TranscriptionStopped.cs | 28 +-- ...sportType.cs => TranscriptionTransport.cs} | 24 +-- .../TranscriptionUpdate.Serialization.cs | 47 +++++ .../Generated/Models/TranscriptionUpdate.cs | 15 +- ...ptionDataRequestInternal.Serialization.cs} | 2 +- ...UpdateTranscriptionDataRequestInternal.cs} | 6 +- .../src/Models/AnswerCallOptions.cs | 5 + .../src/Models/CallConnectionProperties.cs | 7 +- ...CommunicationCallAutomationModelFactory.cs | 6 +- .../src/Models/CreateCallOptions.cs | 5 + .../src/Models/CreateGroupCallOptions.cs | 5 + .../Events/CallAutomationEventParser.cs | 8 + .../src/Models/Events/TranscriptionFailed.cs | 29 +++ .../src/Models/Events/TranscriptionResumed.cs | 29 +++ .../src/Models/Events/TranscriptionStarted.cs | 29 +++ .../src/Models/Events/TranscriptionStopped.cs | 29 +++ .../src/Models/Events/TranscriptionUpdate.cs | 12 ++ .../src/Models/StartTranscriptionOptions.cs | 20 ++ .../StartTranscriptionRequestInternal.cs | 12 ++ .../src/Models/StopTranscriptionOptions.cs | 17 ++ .../StopTranscriptionRequestInternal.cs | 12 ++ .../src/Models/Transcription/ResultStatus.cs | 21 ++ .../src/Models/Transcription/TextFormat.cs | 16 ++ .../Models/Transcription/TranscriptionData.cs | 89 +++++++++ .../TranscriptionDataInternal.cs | 57 ++++++ .../Transcription/TranscriptionMetadata.cs | 31 +++ .../Transcription/TranscriptionPackageBase.cs | 12 ++ .../TranscriptionPackageParser.cs | 69 +++++++ .../src/Models/Transcription/Word.cs | 21 ++ .../src/Models/TranscriptionOptions.cs | 42 ++++ .../Models/TranscriptionOptionsInternal.cs | 12 ++ .../src/Models/TranscriptionStatus.cs | 15 ++ .../src/Models/TranscriptionStatusDetails.cs | 15 ++ .../src/Models/TranscriptionTransport.cs | 15 ++ .../UpdateTranscriptionDataRequestInternal.cs | 12 ++ .../src/autorest.md | 2 +- .../CallAutomationClientTests.cs | 36 +++- .../tests/CallMedias/CallMediaTests.cs | 182 +++++++++++++++++- .../Events/CallAutomationEventParserTests.cs | 116 +++++++++++ .../Infrastructure/CallAutomationTestBase.cs | 9 +- .../TranscriptionPackageParserTests.cs | 175 +++++++++++++++++ 63 files changed, 2097 insertions(+), 127 deletions(-) rename sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/{StartTranscriptionRequest.Serialization.cs => StartTranscriptionRequestInternal.Serialization.cs} (90%) rename sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/{StartTranscriptionRequest.cs => StartTranscriptionRequestInternal.cs} (80%) rename sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/{StopTranscriptionRequest.Serialization.cs => StopTranscriptionRequestInternal.Serialization.cs} (87%) rename sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/{StopTranscriptionRequest.cs => StopTranscriptionRequestInternal.cs} (76%) create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionFailed.Serialization.cs rename sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/{TranscriptionConfiguration.Serialization.cs => TranscriptionOptionsInternal.Serialization.cs} (91%) rename sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/{TranscriptionConfiguration.cs => TranscriptionOptionsInternal.cs} (86%) create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionResumed.Serialization.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStarted.Serialization.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStatus.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStatusDetails.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStopped.Serialization.cs rename sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/{TranscriptionTransportType.cs => TranscriptionTransport.cs} (56%) create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionUpdate.Serialization.cs rename sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/{UpdateTranscriptionDataRequest.Serialization.cs => UpdateTranscriptionDataRequestInternal.Serialization.cs} (84%) rename sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/{UpdateTranscriptionDataRequest.cs => UpdateTranscriptionDataRequestInternal.cs} (81%) create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionFailed.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionResumed.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionStarted.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionStopped.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionUpdate.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/StartTranscriptionOptions.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/StartTranscriptionRequestInternal.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/StopTranscriptionOptions.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/StopTranscriptionRequestInternal.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/ResultStatus.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TextFormat.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionData.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionDataInternal.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionMetadata.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionPackageBase.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionPackageParser.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/Word.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionOptions.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionOptionsInternal.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionStatus.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionStatusDetails.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionTransport.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/src/Models/UpdateTranscriptionDataRequestInternal.cs create mode 100644 sdk/communication/Azure.Communication.CallAutomation/tests/Transcription/TranscriptionPackageParserTests.cs 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 abf6e3d08cfde..35e2b38cdb3c3 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 @@ -59,6 +59,7 @@ public AnswerCallOptions(string incomingCallContext, System.Uri callbackUri) { } public string IncomingCallContext { get { throw null; } } public Azure.Communication.CallAutomation.MediaStreamingOptions MediaStreamingOptions { get { throw null; } set { } } public string OperationContext { get { throw null; } set { } } + public Azure.Communication.CallAutomation.TranscriptionOptions TranscriptionOptions { get { throw null; } set { } } } public partial class AnswerCallResult { @@ -194,6 +195,7 @@ internal CallConnectionProperties() { } public string CallConnectionId { get { throw null; } } public Azure.Communication.CallAutomation.CallConnectionState CallConnectionState { get { throw null; } } public string CorrelationId { get { throw null; } } + public string DataSubscriptionId { get { throw null; } } public string MediaSubscriptionId { get { throw null; } } public string ServerCallId { get { throw null; } } public Azure.Communication.CommunicationIdentifier Source { get { throw null; } } @@ -278,10 +280,16 @@ protected CallMedia() { } public virtual System.Threading.Tasks.Task StartHoldMusicAsync(Azure.Communication.CallAutomation.StartHoldMusicOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response StartRecognizing(Azure.Communication.CallAutomation.CallMediaRecognizeOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> StartRecognizingAsync(Azure.Communication.CallAutomation.CallMediaRecognizeOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response StartTranscription(Azure.Communication.CallAutomation.StartTranscriptionOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task StartTranscriptionAsync(Azure.Communication.CallAutomation.StartTranscriptionOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response StopContinuousDtmfRecognition(Azure.Communication.CommunicationIdentifier targetParticipant, string operationContext = null, System.Uri callbackUri = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task StopContinuousDtmfRecognitionAsync(Azure.Communication.CommunicationIdentifier targetParticipant, string operationContext = null, System.Uri callbackUri = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response StopHoldMusic(Azure.Communication.CallAutomation.StopHoldMusicOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task StopHoldMusicAsync(Azure.Communication.CallAutomation.StopHoldMusicOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response StopTranscription(Azure.Communication.CallAutomation.StopTranscriptionOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task StopTranscriptionAsync(Azure.Communication.CallAutomation.StopTranscriptionOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UpdateTranscriptionData(string locale, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task UpdateTranscriptionDataAsync(string locale, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct CallMediaRecognitionType : System.IEquatable @@ -471,7 +479,7 @@ public static partial class CommunicationCallAutomationModelFactory 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.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, string mediaSubscriptionId = 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, 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; } public static Azure.Communication.CallAutomation.CallParticipant CallParticipant(Azure.Communication.CommunicationIdentifier identifier = null, bool isMuted = false) { throw null; } public static Azure.Communication.CallAutomation.CallTransferAccepted CallTransferAccepted(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, Azure.Communication.CommunicationIdentifier transferee = null, Azure.Communication.CommunicationIdentifier transferTarget = null) { throw null; } @@ -503,6 +511,11 @@ public static partial class CommunicationCallAutomationModelFactory public static Azure.Communication.CallAutomation.SendDtmfFailed SendDtmfFailed(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.SpeechResult SpeechResult(string speech = null) { throw null; } public static Azure.Communication.CallAutomation.ToneInfo ToneInfo(int sequenceId = 0, Azure.Communication.CallAutomation.DtmfTone tone = default(Azure.Communication.CallAutomation.DtmfTone)) { throw null; } + public static Azure.Communication.CallAutomation.TranscriptionFailed TranscriptionFailed(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, Azure.Communication.CallAutomation.TranscriptionUpdate transcriptionUpdateResult = null) { throw null; } + public static Azure.Communication.CallAutomation.TranscriptionResumed TranscriptionResumed(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, Azure.Communication.CallAutomation.TranscriptionUpdate transcriptionUpdateResult = null) { throw null; } + public static Azure.Communication.CallAutomation.TranscriptionStarted TranscriptionStarted(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, Azure.Communication.CallAutomation.TranscriptionUpdate transcriptionUpdateResult = null) { throw null; } + public static Azure.Communication.CallAutomation.TranscriptionStopped TranscriptionStopped(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, Azure.Communication.CallAutomation.TranscriptionUpdate transcriptionUpdateResult = null) { throw null; } + public static Azure.Communication.CallAutomation.TranscriptionUpdate TranscriptionUpdate(Azure.Communication.CallAutomation.TranscriptionStatus? transcriptionStatus = default(Azure.Communication.CallAutomation.TranscriptionStatus?), Azure.Communication.CallAutomation.TranscriptionStatusDetails? transcriptionStatusDetails = default(Azure.Communication.CallAutomation.TranscriptionStatusDetails?)) { throw null; } public static Azure.Communication.CallAutomation.TransferCallToParticipantResult TransferCallToParticipantResult(string operationContext = null) { throw null; } public static Azure.Communication.CallAutomation.UnmuteParticipantsResult UnmuteParticipantsResult(string operationContext = null) { throw null; } public static Azure.Communication.CallAutomation.UserConsent UserConsent(int? recording = default(int?)) { throw null; } @@ -554,6 +567,7 @@ public CreateCallOptions(Azure.Communication.CallAutomation.CallInvite callInvit public Azure.Communication.CallAutomation.CallInvite CallInvite { get { throw null; } } public Azure.Communication.CallAutomation.MediaStreamingOptions MediaStreamingOptions { get { throw null; } set { } } public string OperationContext { get { throw null; } set { } } + public Azure.Communication.CallAutomation.TranscriptionOptions TranscriptionOptions { get { throw null; } set { } } } public partial class CreateCallResult { @@ -574,6 +588,7 @@ public CreateGroupCallOptions(System.Collections.Generic.IEnumerable Targets { get { throw null; } } + public Azure.Communication.CallAutomation.TranscriptionOptions TranscriptionOptions { get { throw null; } set { } } } public partial class CustomContext { @@ -1307,9 +1322,9 @@ public StartRecordingOptions(Azure.Communication.CallAutomation.CallLocator call public Azure.Communication.CallAutomation.RecordingFormat RecordingFormat { get { throw null; } set { } } public System.Uri RecordingStateCallbackUri { get { throw null; } set { } } } - public partial class StartTranscriptionRequest + public partial class StartTranscriptionOptions { - public StartTranscriptionRequest() { } + public StartTranscriptionOptions() { } public string Locale { get { throw null; } set { } } public string OperationContext { get { throw null; } set { } } } @@ -1319,9 +1334,9 @@ public StopHoldMusicOptions(Azure.Communication.CommunicationIdentifier targetPa public string OperationContext { get { throw null; } set { } } public Azure.Communication.CommunicationIdentifier TargetParticipant { get { throw null; } } } - public partial class StopTranscriptionRequest + public partial class StopTranscriptionOptions { - public StopTranscriptionRequest() { } + public StopTranscriptionOptions() { } public string OperationContext { get { throw null; } set { } } } public partial class TextSource : Azure.Communication.CallAutomation.PlaySource @@ -1341,31 +1356,128 @@ internal ToneInfo() { } public int SequenceId { get { throw null; } } public Azure.Communication.CallAutomation.DtmfTone Tone { get { throw null; } } } - public partial class TranscriptionConfiguration + public partial class TranscriptionFailed : Azure.Communication.CallAutomation.CallAutomationEventBase { - public TranscriptionConfiguration(string transportUrl, Azure.Communication.CallAutomation.TranscriptionTransportType transportType, string locale, bool startTranscription) { } + internal TranscriptionFailed() { } + public Azure.Communication.CallAutomation.TranscriptionUpdate TranscriptionUpdateResult { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionFailed Deserialize(string content) { throw null; } + } + public partial class TranscriptionMetadata : Azure.Communication.CallAutomation.TranscriptionPackageBase + { + public TranscriptionMetadata() { } + [System.Text.Json.Serialization.JsonPropertyNameAttribute("callConnectionId")] + public string CallConnectionId { get { throw null; } set { } } + [System.Text.Json.Serialization.JsonPropertyNameAttribute("locale")] + public string Locale { get { throw null; } set { } } + [System.Text.Json.Serialization.JsonPropertyNameAttribute("subscriptionId")] + public string TranscriptionSubscriptionId { get { throw null; } set { } } + } + public partial class TranscriptionOptions + { + public TranscriptionOptions(System.Uri transportUri, Azure.Communication.CallAutomation.TranscriptionTransport transportType, string locale, bool startTranscription) { } public string Locale { get { throw null; } } public bool StartTranscription { get { throw null; } } - public Azure.Communication.CallAutomation.TranscriptionTransportType TransportType { get { throw null; } } - public string TransportUrl { get { throw null; } } + public Azure.Communication.CallAutomation.TranscriptionTransport TranscriptionTransport { get { throw null; } } + public System.Uri TransportUrl { get { throw null; } } + } + public abstract partial class TranscriptionPackageBase + { + protected TranscriptionPackageBase() { } + } + public static partial class TranscriptionPackageParser + { + public static Azure.Communication.CallAutomation.TranscriptionPackageBase Parse(System.BinaryData json) { throw null; } + public static Azure.Communication.CallAutomation.TranscriptionPackageBase Parse(byte[] receivedBytes) { throw null; } + public static Azure.Communication.CallAutomation.TranscriptionPackageBase Parse(string stringJson) { throw null; } + } + public partial class TranscriptionResumed : Azure.Communication.CallAutomation.CallAutomationEventBase + { + internal TranscriptionResumed() { } + public Azure.Communication.CallAutomation.TranscriptionUpdate TranscriptionUpdateResult { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionResumed Deserialize(string content) { throw null; } + } + public partial class TranscriptionStarted : Azure.Communication.CallAutomation.CallAutomationEventBase + { + internal TranscriptionStarted() { } + public Azure.Communication.CallAutomation.TranscriptionUpdate TranscriptionUpdateResult { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStarted Deserialize(string content) { throw null; } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct TranscriptionStatus : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public TranscriptionStatus(string value) { throw null; } + public static Azure.Communication.CallAutomation.TranscriptionStatus TranscriptionFailed { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatus TranscriptionLocaleUpdated { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatus TranscriptionResumed { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatus TranscriptionStarted { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatus TranscriptionStopped { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatus UnspecifiedError { get { throw null; } } + public bool Equals(Azure.Communication.CallAutomation.TranscriptionStatus other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.Communication.CallAutomation.TranscriptionStatus left, Azure.Communication.CallAutomation.TranscriptionStatus right) { throw null; } + public static implicit operator Azure.Communication.CallAutomation.TranscriptionStatus (string value) { throw null; } + public static bool operator !=(Azure.Communication.CallAutomation.TranscriptionStatus left, Azure.Communication.CallAutomation.TranscriptionStatus right) { throw null; } + public override string ToString() { throw null; } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct TranscriptionStatusDetails : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public TranscriptionStatusDetails(string value) { throw null; } + public static Azure.Communication.CallAutomation.TranscriptionStatusDetails ServiceShutdown { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatusDetails SpeechServicesConnectionError { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatusDetails StreamConnectionInterrupted { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatusDetails StreamConnectionReestablished { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatusDetails StreamConnectionUnsuccessful { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatusDetails StreamUrlMissing { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatusDetails SubscriptionStarted { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatusDetails SubscriptionStopped { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStatusDetails UnspecifiedError { get { throw null; } } + public bool Equals(Azure.Communication.CallAutomation.TranscriptionStatusDetails other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.Communication.CallAutomation.TranscriptionStatusDetails left, Azure.Communication.CallAutomation.TranscriptionStatusDetails right) { throw null; } + public static implicit operator Azure.Communication.CallAutomation.TranscriptionStatusDetails (string value) { throw null; } + public static bool operator !=(Azure.Communication.CallAutomation.TranscriptionStatusDetails left, Azure.Communication.CallAutomation.TranscriptionStatusDetails right) { throw null; } + public override string ToString() { throw null; } + } + public partial class TranscriptionStopped : Azure.Communication.CallAutomation.CallAutomationEventBase + { + internal TranscriptionStopped() { } + public Azure.Communication.CallAutomation.TranscriptionUpdate TranscriptionUpdateResult { get { throw null; } } + public static Azure.Communication.CallAutomation.TranscriptionStopped Deserialize(string content) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct TranscriptionTransportType : System.IEquatable + public readonly partial struct TranscriptionTransport : System.IEquatable { private readonly object _dummy; private readonly int _dummyPrimitive; - public TranscriptionTransportType(string value) { throw null; } - public static Azure.Communication.CallAutomation.TranscriptionTransportType Websocket { get { throw null; } } - public bool Equals(Azure.Communication.CallAutomation.TranscriptionTransportType other) { throw null; } + public TranscriptionTransport(string value) { throw null; } + public static Azure.Communication.CallAutomation.TranscriptionTransport Websocket { get { throw null; } } + public bool Equals(Azure.Communication.CallAutomation.TranscriptionTransport other) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override bool Equals(object obj) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } - public static bool operator ==(Azure.Communication.CallAutomation.TranscriptionTransportType left, Azure.Communication.CallAutomation.TranscriptionTransportType right) { throw null; } - public static implicit operator Azure.Communication.CallAutomation.TranscriptionTransportType (string value) { throw null; } - public static bool operator !=(Azure.Communication.CallAutomation.TranscriptionTransportType left, Azure.Communication.CallAutomation.TranscriptionTransportType right) { throw null; } + public static bool operator ==(Azure.Communication.CallAutomation.TranscriptionTransport left, Azure.Communication.CallAutomation.TranscriptionTransport right) { throw null; } + public static implicit operator Azure.Communication.CallAutomation.TranscriptionTransport (string value) { throw null; } + public static bool operator !=(Azure.Communication.CallAutomation.TranscriptionTransport left, Azure.Communication.CallAutomation.TranscriptionTransport right) { throw null; } public override string ToString() { throw null; } } + public partial class TranscriptionUpdate + { + internal TranscriptionUpdate() { } + public Azure.Communication.CallAutomation.TranscriptionStatus? TranscriptionStatus { get { throw null; } } + public Azure.Communication.CallAutomation.TranscriptionStatusDetails? TranscriptionStatusDetails { get { throw null; } } + } public partial class TransferCallToParticipantEventResult { internal TransferCallToParticipantEventResult() { } @@ -1402,11 +1514,6 @@ public partial class UnmuteParticipantsResult internal UnmuteParticipantsResult() { } public string OperationContext { get { throw null; } } } - public partial class UpdateTranscriptionDataRequest - { - public UpdateTranscriptionDataRequest(string locale) { } - public string Locale { get { throw null; } } - } public partial class UserConsent { internal UserConsent() { } @@ -1417,3 +1524,15 @@ public partial class VoipHeader : Azure.Communication.CallAutomation.CustomConte public VoipHeader(string key, string value) : base (default(string), default(string)) { } } } +namespace Azure.Communication.CallAutomation.Models.Transcription +{ + public enum ResultStatus + { + Intermediate = 0, + Final = 1, + } + public enum TextFormat + { + Display = 0, + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationClient.cs b/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationClient.cs index 462fcb6864628..b3873d2d43a5b 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationClient.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationClient.cs @@ -188,7 +188,6 @@ public virtual async Task> AnswerCallAsync(AnswerCall throw; } } - /// Answer an incoming call. /// The incoming call context /// The callback Uri to receive status notifications. @@ -246,6 +245,7 @@ private AnswerCallRequestInternal CreateAnswerCallRequest(AnswerCallOptions opti request.AzureCognitiveServicesEndpointUrl = options.AzureCognitiveServicesEndpointUri.AbsoluteUri; } request.MediaStreamingConfiguration = CreateMediaStreamingOptionsInternal(options.MediaStreamingOptions); + request.TranscriptionConfiguration = CreateTranscriptionOptionsInternal(options.TranscriptionOptions); request.AnsweredByIdentifier = Source == null ? null : new CommunicationUserIdentifierModel(Source.Id); request.OperationContext = options.OperationContext; @@ -624,6 +624,7 @@ private CreateCallRequestInternal CreateCallRequest(CreateCallOptions options) } request.OperationContext = options.OperationContext; request.MediaStreamingConfiguration = CreateMediaStreamingOptionsInternal(options.MediaStreamingOptions); + request.TranscriptionConfiguration = CreateTranscriptionOptionsInternal(options.TranscriptionOptions); return request; } @@ -652,6 +653,7 @@ private CreateCallRequestInternal CreateCallRequest(CreateGroupCallOptions optio } request.OperationContext = options.OperationContext; request.MediaStreamingConfiguration = CreateMediaStreamingOptionsInternal(options.MediaStreamingOptions); + request.TranscriptionConfiguration = CreateTranscriptionOptionsInternal(options.TranscriptionOptions); return request; } @@ -675,6 +677,13 @@ private static MediaStreamingOptionsInternal CreateMediaStreamingOptionsInternal : new MediaStreamingOptionsInternal(configuration.TransportUri.AbsoluteUri, configuration.MediaStreamingTransport, configuration.MediaStreamingContent, configuration.MediaStreamingAudioChannel); } + private static TranscriptionOptionsInternal CreateTranscriptionOptionsInternal(TranscriptionOptions configuration) + { + return configuration == default + ? default + : new TranscriptionOptionsInternal(configuration.TransportUrl.AbsoluteUri, configuration.TranscriptionTransport, configuration.Locale, + configuration.StartTranscription); + } /// Initializes a new instance of CallConnection. . /// The call connection id for the GetCallConnection instance. diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/CallMedia.cs b/sdk/communication/Azure.Communication.CallAutomation/src/CallMedia.cs index 8355bed4a9672..3e6a845ae74d7 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/CallMedia.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/CallMedia.cs @@ -856,5 +856,149 @@ public virtual Response SendDtmf(IEnumerable tones, Co throw; } } + + /// + /// Starts transcription in the call. + /// + /// An optional object containing start transcription options and configurations. + /// An optional CancellationToken to cancel the request. + /// Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error. + public virtual Response StartTranscription(StartTranscriptionOptions options = default, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(StartTranscription)}"); + scope.Start(); + try + { + var request = options == default + ? new StartTranscriptionRequestInternal() + : new StartTranscriptionRequestInternal() { Locale = options.Locale, OperationContext = options.OperationContext }; + + return CallMediaRestClient.StartTranscription(CallConnectionId, request, cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Starts transcription in the call. + /// + /// An optional object containing start transcription options and configurations. + /// An optional CancellationToken to cancel the request. + /// Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error. + public virtual async Task StartTranscriptionAsync(StartTranscriptionOptions options = default, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(StartTranscription)}"); + scope.Start(); + try + { + var request = options == default + ? new StartTranscriptionRequestInternal() + : new StartTranscriptionRequestInternal() { Locale = options.Locale, OperationContext = options.OperationContext }; + + return await CallMediaRestClient.StartTranscriptionAsync(CallConnectionId, request, cancellationToken).ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Stops transcription in the call. + /// + /// An optional object containing stop transcription options and configurations. + /// An optional CancellationToken to cancel the request. + /// Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error. + public virtual Response StopTranscription(StopTranscriptionOptions options = default, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(StopTranscription)}"); + scope.Start(); + try + { + var request = options == default + ? new StopTranscriptionRequestInternal() + : new StopTranscriptionRequestInternal() { OperationContext = options.OperationContext }; + + return CallMediaRestClient.StopTranscription(CallConnectionId, request, cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Stops transcription in the call. + /// + /// An optional object containing stop transcription options and configurations. + /// An optional CancellationToken to cancel the request. + /// Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error. + public virtual async Task StopTranscriptionAsync(StopTranscriptionOptions options = default, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(StopTranscription)}"); + scope.Start(); + try + { + var request = options == default + ? new StopTranscriptionRequestInternal() + : new StopTranscriptionRequestInternal() { OperationContext = options.OperationContext }; + + return await CallMediaRestClient.StopTranscriptionAsync(CallConnectionId, request, cancellationToken).ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// API to change transcription language. + /// + /// Defines new locale for transcription. + /// An optional CancellationToken to cancel the request. + /// Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error. + public virtual Response UpdateTranscriptionData(String locale, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(UpdateTranscriptionData)}"); + scope.Start(); + try + { + UpdateTranscriptionDataRequestInternal request = new UpdateTranscriptionDataRequestInternal(locale); + return CallMediaRestClient.UpdateTranscriptionData(CallConnectionId, request, cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// API to change transcription language. + /// + /// Defines new locale for transcription. + /// An optional CancellationToken to cancel the request. + /// Returns an HTTP response with a 202 status code for success, or an HTTP failure error code in case of an error. + public virtual async Task UpdateTranscriptionDataAsync(String locale, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(UpdateTranscriptionData)}"); + scope.Start(); + try + { + UpdateTranscriptionDataRequestInternal request = new UpdateTranscriptionDataRequestInternal(locale); + return await CallMediaRestClient.UpdateTranscriptionDataAsync(CallConnectionId, request, cancellationToken).ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CallMediaRestClient.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CallMediaRestClient.cs index 1cb5b08d74770..7440c371e5289 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CallMediaRestClient.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CallMediaRestClient.cs @@ -111,7 +111,7 @@ public Response Play(string callConnectionId, PlayRequestInternal playRequest, C } } - internal HttpMessage CreateStartTranscriptionRequest(string callConnectionId, StartTranscriptionRequest startTranscriptionRequest) + internal HttpMessage CreateStartTranscriptionRequest(string callConnectionId, StartTranscriptionRequestInternal startTranscriptionRequest) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -136,7 +136,7 @@ internal HttpMessage CreateStartTranscriptionRequest(string callConnectionId, St /// The StartTranscriptionRequest to use. /// The cancellation token to use. /// or is null. - public async Task StartTranscriptionAsync(string callConnectionId, StartTranscriptionRequest startTranscriptionRequest, CancellationToken cancellationToken = default) + public async Task StartTranscriptionAsync(string callConnectionId, StartTranscriptionRequestInternal startTranscriptionRequest, CancellationToken cancellationToken = default) { if (callConnectionId == null) { @@ -163,7 +163,7 @@ public async Task StartTranscriptionAsync(string callConnectionId, Sta /// The StartTranscriptionRequest to use. /// The cancellation token to use. /// or is null. - public Response StartTranscription(string callConnectionId, StartTranscriptionRequest startTranscriptionRequest, CancellationToken cancellationToken = default) + public Response StartTranscription(string callConnectionId, StartTranscriptionRequestInternal startTranscriptionRequest, CancellationToken cancellationToken = default) { if (callConnectionId == null) { @@ -185,7 +185,7 @@ public Response StartTranscription(string callConnectionId, StartTranscriptionRe } } - internal HttpMessage CreateStopTranscriptionRequest(string callConnectionId, StopTranscriptionRequest stopTranscriptionRequest) + internal HttpMessage CreateStopTranscriptionRequest(string callConnectionId, StopTranscriptionRequestInternal stopTranscriptionRequest) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -194,7 +194,7 @@ internal HttpMessage CreateStopTranscriptionRequest(string callConnectionId, Sto uri.Reset(_endpoint); uri.AppendPath("/calling/callConnections/", false); uri.AppendPath(callConnectionId, true); - uri.AppendPath(":StopTranscripition", false); + uri.AppendPath(":StopTranscription", false); uri.AppendQuery("api-version", _apiVersion, true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); @@ -210,7 +210,7 @@ internal HttpMessage CreateStopTranscriptionRequest(string callConnectionId, Sto /// stop transcription request payload. /// The cancellation token to use. /// or is null. - public async Task StopTranscriptionAsync(string callConnectionId, StopTranscriptionRequest stopTranscriptionRequest, CancellationToken cancellationToken = default) + public async Task StopTranscriptionAsync(string callConnectionId, StopTranscriptionRequestInternal stopTranscriptionRequest, CancellationToken cancellationToken = default) { if (callConnectionId == null) { @@ -237,7 +237,7 @@ public async Task StopTranscriptionAsync(string callConnectionId, Stop /// stop transcription request payload. /// The cancellation token to use. /// or is null. - public Response StopTranscription(string callConnectionId, StopTranscriptionRequest stopTranscriptionRequest, CancellationToken cancellationToken = default) + public Response StopTranscription(string callConnectionId, StopTranscriptionRequestInternal stopTranscriptionRequest, CancellationToken cancellationToken = default) { if (callConnectionId == null) { @@ -615,7 +615,7 @@ public Response SendDtmf(string callConnectionId, SendDtmfRequestInternal sendDt } } - internal HttpMessage CreateUpdateTranscriptionDataRequest(string callConnectionId, UpdateTranscriptionDataRequest updateTranscriptionDataRequest) + internal HttpMessage CreateUpdateTranscriptionDataRequest(string callConnectionId, UpdateTranscriptionDataRequestInternal updateTranscriptionDataRequest) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -641,7 +641,7 @@ internal HttpMessage CreateUpdateTranscriptionDataRequest(string callConnectionI /// The cancellation token to use. /// or is null. /// API to change transcription language. - public async Task UpdateTranscriptionDataAsync(string callConnectionId, UpdateTranscriptionDataRequest updateTranscriptionDataRequest, CancellationToken cancellationToken = default) + public async Task UpdateTranscriptionDataAsync(string callConnectionId, UpdateTranscriptionDataRequestInternal updateTranscriptionDataRequest, CancellationToken cancellationToken = default) { if (callConnectionId == null) { @@ -669,7 +669,7 @@ public async Task UpdateTranscriptionDataAsync(string callConnectionId /// The cancellation token to use. /// or is null. /// API to change transcription language. - public Response UpdateTranscriptionData(string callConnectionId, UpdateTranscriptionDataRequest updateTranscriptionDataRequest, CancellationToken cancellationToken = default) + public Response UpdateTranscriptionData(string callConnectionId, UpdateTranscriptionDataRequestInternal updateTranscriptionDataRequest, CancellationToken cancellationToken = default) { if (callConnectionId == null) { diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CommunicationCallAutomationModelFactory.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CommunicationCallAutomationModelFactory.cs index 5fe9ae11294f4..bf7a7d52bf4d6 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CommunicationCallAutomationModelFactory.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/CommunicationCallAutomationModelFactory.cs @@ -280,5 +280,66 @@ public static SendDtmfFailed SendDtmfFailed(string callConnectionId = null, stri { return new SendDtmfFailed(callConnectionId, serverCallId, correlationId, operationContext, resultInformation); } + + /// Initializes a new instance of TranscriptionStarted. + /// Call connection ID. + /// Server call ID. + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + /// Used by customers when calling answerCall action to correlate the request to the response event. + /// Contains the resulting SIP code/sub-code and message from NGC services. + /// Defines the result for TranscriptionUpdate with the current status and the details about the status. + /// A new instance for mocking. + public static TranscriptionStarted TranscriptionStarted(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, ResultInformation resultInformation = null, TranscriptionUpdate transcriptionUpdateResult = null) + { + return new TranscriptionStarted(callConnectionId, serverCallId, correlationId, operationContext, resultInformation, transcriptionUpdateResult); + } + + /// Initializes a new instance of TranscriptionUpdate. + /// + /// + /// A new instance for mocking. + public static TranscriptionUpdate TranscriptionUpdate(TranscriptionStatus? transcriptionStatus = null, TranscriptionStatusDetails? transcriptionStatusDetails = null) + { + return new TranscriptionUpdate(transcriptionStatus, transcriptionStatusDetails); + } + + /// Initializes a new instance of TranscriptionStopped. + /// Call connection ID. + /// Server call ID. + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + /// Used by customers when calling answerCall action to correlate the request to the response event. + /// Contains the resulting SIP code/sub-code and message from NGC services. + /// Defines the result for TranscriptionUpdate with the current status and the details about the status. + /// A new instance for mocking. + public static TranscriptionStopped TranscriptionStopped(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, ResultInformation resultInformation = null, TranscriptionUpdate transcriptionUpdateResult = null) + { + return new TranscriptionStopped(callConnectionId, serverCallId, correlationId, operationContext, resultInformation, transcriptionUpdateResult); + } + + /// Initializes a new instance of TranscriptionResumed. + /// Call connection ID. + /// Server call ID. + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + /// Used by customers when calling answerCall action to correlate the request to the response event. + /// Contains the resulting SIP code/sub-code and message from NGC services. + /// Defines the result for TranscriptionUpdate with the current status and the details about the status. + /// A new instance for mocking. + public static TranscriptionResumed TranscriptionResumed(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, ResultInformation resultInformation = null, TranscriptionUpdate transcriptionUpdateResult = null) + { + return new TranscriptionResumed(callConnectionId, serverCallId, correlationId, operationContext, resultInformation, transcriptionUpdateResult); + } + + /// Initializes a new instance of TranscriptionFailed. + /// Call connection ID. + /// Server call ID. + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + /// Used by customers when calling answerCall action to correlate the request to the response event. + /// Contains the resulting SIP code/sub-code and message from NGC services. + /// Defines the result for TranscriptionUpdate with the current status and the details about the status. + /// A new instance for mocking. + public static TranscriptionFailed TranscriptionFailed(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, ResultInformation resultInformation = null, TranscriptionUpdate transcriptionUpdateResult = null) + { + return new TranscriptionFailed(callConnectionId, serverCallId, correlationId, operationContext, resultInformation, transcriptionUpdateResult); + } } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/AnswerCallRequestInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/AnswerCallRequestInternal.cs index 5dc780871a5d6..359624a4792b0 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/AnswerCallRequestInternal.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/AnswerCallRequestInternal.cs @@ -36,7 +36,7 @@ public AnswerCallRequestInternal(string incomingCallContext, string callbackUri) /// Media Streaming Configuration. public MediaStreamingOptionsInternal MediaStreamingConfiguration { get; set; } /// Live Transcription Configuration. - public TranscriptionConfiguration TranscriptionConfiguration { get; set; } + public TranscriptionOptionsInternal TranscriptionConfiguration { get; set; } /// The endpoint URL of the Azure Cognitive Services resource attached. public string AzureCognitiveServicesEndpointUrl { get; set; } /// The identifier of the call automation entity which answers the call. diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CreateCallRequestInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CreateCallRequestInternal.cs index 778d8c1b08330..2f0dc0ecd32aa 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CreateCallRequestInternal.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/CreateCallRequestInternal.cs @@ -47,7 +47,7 @@ public CreateCallRequestInternal(IEnumerable targe /// Media Streaming Configuration. public MediaStreamingOptionsInternal MediaStreamingConfiguration { get; set; } /// Live Transcription Configuration. - public TranscriptionConfiguration TranscriptionConfiguration { get; set; } + public TranscriptionOptionsInternal TranscriptionConfiguration { get; set; } /// The identifier of the Cognitive Service resource assigned to this call. public string AzureCognitiveServicesEndpointUrl { get; set; } /// Used by customer to send custom context to targets. diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequest.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequestInternal.Serialization.cs similarity index 90% rename from sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequest.Serialization.cs rename to sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequestInternal.Serialization.cs index 59b2f04761028..cc634a87ec48d 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequest.Serialization.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequestInternal.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.Communication.CallAutomation { - public partial class StartTranscriptionRequest : IUtf8JsonSerializable + internal partial class StartTranscriptionRequestInternal : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequest.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequestInternal.cs similarity index 80% rename from sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequest.cs rename to sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequestInternal.cs index 7d08c51e2484f..0024408ab7651 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequest.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StartTranscriptionRequestInternal.cs @@ -8,10 +8,10 @@ namespace Azure.Communication.CallAutomation { /// The StartTranscriptionRequest. - public partial class StartTranscriptionRequest + internal partial class StartTranscriptionRequestInternal { - /// Initializes a new instance of StartTranscriptionRequest. - public StartTranscriptionRequest() + /// Initializes a new instance of StartTranscriptionRequestInternal. + public StartTranscriptionRequestInternal() { } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequest.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequestInternal.Serialization.cs similarity index 87% rename from sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequest.Serialization.cs rename to sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequestInternal.Serialization.cs index fdaebe2606e52..f3d9f5c3b0278 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequest.Serialization.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequestInternal.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.Communication.CallAutomation { - public partial class StopTranscriptionRequest : IUtf8JsonSerializable + internal partial class StopTranscriptionRequestInternal : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequest.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequestInternal.cs similarity index 76% rename from sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequest.cs rename to sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequestInternal.cs index 3620267539101..d7fe1524182eb 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequest.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/StopTranscriptionRequestInternal.cs @@ -8,10 +8,10 @@ namespace Azure.Communication.CallAutomation { /// The StopTranscriptionRequest. - public partial class StopTranscriptionRequest + internal partial class StopTranscriptionRequestInternal { - /// Initializes a new instance of StopTranscriptionRequest. - public StopTranscriptionRequest() + /// Initializes a new instance of StopTranscriptionRequestInternal. + public StopTranscriptionRequestInternal() { } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionFailed.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionFailed.Serialization.cs new file mode 100644 index 0000000000000..ae3c40353c871 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionFailed.Serialization.cs @@ -0,0 +1,71 @@ +// 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 +{ + public partial class TranscriptionFailed + { + internal static TranscriptionFailed DeserializeTranscriptionFailed(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional callConnectionId = default; + Optional serverCallId = default; + Optional correlationId = default; + Optional operationContext = default; + Optional resultInformation = default; + Optional transcriptionUpdateResult = default; + foreach (var property in element.EnumerateObject()) + { + 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; + } + 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("transcriptionUpdateResult"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + transcriptionUpdateResult = TranscriptionUpdate.DeserializeTranscriptionUpdate(property.Value); + continue; + } + } + return new TranscriptionFailed(callConnectionId.Value, serverCallId.Value, correlationId.Value, operationContext.Value, resultInformation.Value, transcriptionUpdateResult.Value); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionFailed.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionFailed.cs index 1f29ea9a23c58..b9e57cbc9b402 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionFailed.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionFailed.cs @@ -8,23 +8,29 @@ namespace Azure.Communication.CallAutomation { /// The TranscriptionFailed. - internal partial class TranscriptionFailed + public partial class TranscriptionFailed { /// Initializes a new instance of TranscriptionFailed. internal TranscriptionFailed() { } - /// 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; } - /// Used by customers when calling answerCall action to correlate the request to the response event. - public string OperationContext { get; } - /// Contains the resulting SIP code/sub-code and message from NGC services. - public ResultInformation ResultInformation { get; } + /// Initializes a new instance of TranscriptionFailed. + /// Call connection ID. + /// Server call ID. + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + /// Used by customers when calling answerCall action to correlate the request to the response event. + /// Contains the resulting SIP code/sub-code and message from NGC services. + /// Defines the result for TranscriptionUpdate with the current status and the details about the status. + internal TranscriptionFailed(string callConnectionId, string serverCallId, string correlationId, string operationContext, ResultInformation resultInformation, TranscriptionUpdate transcriptionUpdateResult) + { + CallConnectionId = callConnectionId; + ServerCallId = serverCallId; + CorrelationId = correlationId; + OperationContext = operationContext; + ResultInformation = resultInformation; + TranscriptionUpdateResult = transcriptionUpdateResult; + } /// Defines the result for TranscriptionUpdate with the current status and the details about the status. public TranscriptionUpdate TranscriptionUpdateResult { get; } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionConfiguration.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionOptionsInternal.Serialization.cs similarity index 91% rename from sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionConfiguration.Serialization.cs rename to sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionOptionsInternal.Serialization.cs index 57cf84d402eb5..a942ec83b1d24 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionConfiguration.Serialization.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionOptionsInternal.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.Communication.CallAutomation { - public partial class TranscriptionConfiguration : IUtf8JsonSerializable + internal partial class TranscriptionOptionsInternal : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionConfiguration.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionOptionsInternal.cs similarity index 86% rename from sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionConfiguration.cs rename to sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionOptionsInternal.cs index c6a267d51b68c..9e28bcc630622 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionConfiguration.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionOptionsInternal.cs @@ -11,15 +11,15 @@ namespace Azure.Communication.CallAutomation { /// Configuration of live transcription. - public partial class TranscriptionConfiguration + internal partial class TranscriptionOptionsInternal { - /// Initializes a new instance of TranscriptionConfiguration. + /// Initializes a new instance of TranscriptionOptionsInternal. /// Transport URL for live transcription. /// The type of transport to be used for live transcription, eg. Websocket. /// Defines the locale for the data e.g en-CA, en-AU. /// Determines if the transcription should be started immediately after call is answered or not. /// or is null. - public TranscriptionConfiguration(string transportUrl, TranscriptionTransportType transportType, string locale, bool startTranscription) + public TranscriptionOptionsInternal(string transportUrl, TranscriptionTransport transportType, string locale, bool startTranscription) { Argument.AssertNotNull(transportUrl, nameof(transportUrl)); Argument.AssertNotNull(locale, nameof(locale)); @@ -33,7 +33,7 @@ public TranscriptionConfiguration(string transportUrl, TranscriptionTransportTyp /// Transport URL for live transcription. public string TransportUrl { get; } /// The type of transport to be used for live transcription, eg. Websocket. - public TranscriptionTransportType TransportType { get; } + public TranscriptionTransport TransportType { get; } /// Defines the locale for the data e.g en-CA, en-AU. public string Locale { get; } /// Determines if the transcription should be started immediately after call is answered or not. diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionResumed.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionResumed.Serialization.cs new file mode 100644 index 0000000000000..02e792a44b866 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionResumed.Serialization.cs @@ -0,0 +1,71 @@ +// 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 +{ + public partial class TranscriptionResumed + { + internal static TranscriptionResumed DeserializeTranscriptionResumed(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional callConnectionId = default; + Optional serverCallId = default; + Optional correlationId = default; + Optional operationContext = default; + Optional resultInformation = default; + Optional transcriptionUpdateResult = default; + foreach (var property in element.EnumerateObject()) + { + 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; + } + 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("transcriptionUpdateResult"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + transcriptionUpdateResult = TranscriptionUpdate.DeserializeTranscriptionUpdate(property.Value); + continue; + } + } + return new TranscriptionResumed(callConnectionId.Value, serverCallId.Value, correlationId.Value, operationContext.Value, resultInformation.Value, transcriptionUpdateResult.Value); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionResumed.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionResumed.cs index b94d62cc9fd02..9563c5f7eeef4 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionResumed.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionResumed.cs @@ -8,23 +8,29 @@ namespace Azure.Communication.CallAutomation { /// The TranscriptionResumed. - internal partial class TranscriptionResumed + public partial class TranscriptionResumed { /// Initializes a new instance of TranscriptionResumed. internal TranscriptionResumed() { } - /// 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; } - /// Used by customers when calling answerCall action to correlate the request to the response event. - public string OperationContext { get; } - /// Contains the resulting SIP code/sub-code and message from NGC services. - public ResultInformation ResultInformation { get; } + /// Initializes a new instance of TranscriptionResumed. + /// Call connection ID. + /// Server call ID. + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + /// Used by customers when calling answerCall action to correlate the request to the response event. + /// Contains the resulting SIP code/sub-code and message from NGC services. + /// Defines the result for TranscriptionUpdate with the current status and the details about the status. + internal TranscriptionResumed(string callConnectionId, string serverCallId, string correlationId, string operationContext, ResultInformation resultInformation, TranscriptionUpdate transcriptionUpdateResult) + { + CallConnectionId = callConnectionId; + ServerCallId = serverCallId; + CorrelationId = correlationId; + OperationContext = operationContext; + ResultInformation = resultInformation; + TranscriptionUpdateResult = transcriptionUpdateResult; + } /// Defines the result for TranscriptionUpdate with the current status and the details about the status. public TranscriptionUpdate TranscriptionUpdateResult { get; } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStarted.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStarted.Serialization.cs new file mode 100644 index 0000000000000..9c63d4353c300 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStarted.Serialization.cs @@ -0,0 +1,71 @@ +// 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 +{ + public partial class TranscriptionStarted + { + internal static TranscriptionStarted DeserializeTranscriptionStarted(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional callConnectionId = default; + Optional serverCallId = default; + Optional correlationId = default; + Optional operationContext = default; + Optional resultInformation = default; + Optional transcriptionUpdateResult = default; + foreach (var property in element.EnumerateObject()) + { + 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; + } + 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("transcriptionUpdateResult"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + transcriptionUpdateResult = TranscriptionUpdate.DeserializeTranscriptionUpdate(property.Value); + continue; + } + } + return new TranscriptionStarted(callConnectionId.Value, serverCallId.Value, correlationId.Value, operationContext.Value, resultInformation.Value, transcriptionUpdateResult.Value); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStarted.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStarted.cs index c97f91d1530eb..d40541ff944bc 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStarted.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStarted.cs @@ -8,23 +8,29 @@ namespace Azure.Communication.CallAutomation { /// The TranscriptionStarted. - internal partial class TranscriptionStarted + public partial class TranscriptionStarted { /// Initializes a new instance of TranscriptionStarted. internal TranscriptionStarted() { } - /// 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; } - /// Used by customers when calling answerCall action to correlate the request to the response event. - public string OperationContext { get; } - /// Contains the resulting SIP code/sub-code and message from NGC services. - public ResultInformation ResultInformation { get; } + /// Initializes a new instance of TranscriptionStarted. + /// Call connection ID. + /// Server call ID. + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + /// Used by customers when calling answerCall action to correlate the request to the response event. + /// Contains the resulting SIP code/sub-code and message from NGC services. + /// Defines the result for TranscriptionUpdate with the current status and the details about the status. + internal TranscriptionStarted(string callConnectionId, string serverCallId, string correlationId, string operationContext, ResultInformation resultInformation, TranscriptionUpdate transcriptionUpdateResult) + { + CallConnectionId = callConnectionId; + ServerCallId = serverCallId; + CorrelationId = correlationId; + OperationContext = operationContext; + ResultInformation = resultInformation; + TranscriptionUpdateResult = transcriptionUpdateResult; + } /// Defines the result for TranscriptionUpdate with the current status and the details about the status. public TranscriptionUpdate TranscriptionUpdateResult { get; } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStatus.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStatus.cs new file mode 100644 index 0000000000000..32d9c8eef3290 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStatus.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Communication.CallAutomation +{ + /// The TranscriptionStatus. + public readonly partial struct TranscriptionStatus : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public TranscriptionStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string TranscriptionStartedValue = "transcriptionStarted"; + private const string TranscriptionFailedValue = "transcriptionFailed"; + private const string TranscriptionResumedValue = "transcriptionResumed"; + private const string TranscriptionLocaleUpdatedValue = "transcriptionLocaleUpdated"; + private const string TranscriptionStoppedValue = "transcriptionStopped"; + private const string UnspecifiedErrorValue = "unspecifiedError"; + + /// transcriptionStarted. + public static TranscriptionStatus TranscriptionStarted { get; } = new TranscriptionStatus(TranscriptionStartedValue); + /// transcriptionFailed. + public static TranscriptionStatus TranscriptionFailed { get; } = new TranscriptionStatus(TranscriptionFailedValue); + /// transcriptionResumed. + public static TranscriptionStatus TranscriptionResumed { get; } = new TranscriptionStatus(TranscriptionResumedValue); + /// transcriptionLocaleUpdated. + public static TranscriptionStatus TranscriptionLocaleUpdated { get; } = new TranscriptionStatus(TranscriptionLocaleUpdatedValue); + /// transcriptionStopped. + public static TranscriptionStatus TranscriptionStopped { get; } = new TranscriptionStatus(TranscriptionStoppedValue); + /// unspecifiedError. + public static TranscriptionStatus UnspecifiedError { get; } = new TranscriptionStatus(UnspecifiedErrorValue); + /// Determines if two values are the same. + public static bool operator ==(TranscriptionStatus left, TranscriptionStatus right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(TranscriptionStatus left, TranscriptionStatus right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator TranscriptionStatus(string value) => new TranscriptionStatus(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is TranscriptionStatus other && Equals(other); + /// + public bool Equals(TranscriptionStatus other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStatusDetails.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStatusDetails.cs new file mode 100644 index 0000000000000..16c8dddccca22 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStatusDetails.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Communication.CallAutomation +{ + /// The TranscriptionStatusDetails. + public readonly partial struct TranscriptionStatusDetails : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public TranscriptionStatusDetails(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string SubscriptionStartedValue = "subscriptionStarted"; + private const string StreamConnectionReestablishedValue = "streamConnectionReestablished"; + private const string StreamConnectionUnsuccessfulValue = "streamConnectionUnsuccessful"; + private const string StreamUrlMissingValue = "streamUrlMissing"; + private const string ServiceShutdownValue = "serviceShutdown"; + private const string StreamConnectionInterruptedValue = "streamConnectionInterrupted"; + private const string SpeechServicesConnectionErrorValue = "speechServicesConnectionError"; + private const string SubscriptionStoppedValue = "subscriptionStopped"; + private const string UnspecifiedErrorValue = "unspecifiedError"; + + /// subscriptionStarted. + public static TranscriptionStatusDetails SubscriptionStarted { get; } = new TranscriptionStatusDetails(SubscriptionStartedValue); + /// streamConnectionReestablished. + public static TranscriptionStatusDetails StreamConnectionReestablished { get; } = new TranscriptionStatusDetails(StreamConnectionReestablishedValue); + /// streamConnectionUnsuccessful. + public static TranscriptionStatusDetails StreamConnectionUnsuccessful { get; } = new TranscriptionStatusDetails(StreamConnectionUnsuccessfulValue); + /// streamUrlMissing. + public static TranscriptionStatusDetails StreamUrlMissing { get; } = new TranscriptionStatusDetails(StreamUrlMissingValue); + /// serviceShutdown. + public static TranscriptionStatusDetails ServiceShutdown { get; } = new TranscriptionStatusDetails(ServiceShutdownValue); + /// streamConnectionInterrupted. + public static TranscriptionStatusDetails StreamConnectionInterrupted { get; } = new TranscriptionStatusDetails(StreamConnectionInterruptedValue); + /// speechServicesConnectionError. + public static TranscriptionStatusDetails SpeechServicesConnectionError { get; } = new TranscriptionStatusDetails(SpeechServicesConnectionErrorValue); + /// subscriptionStopped. + public static TranscriptionStatusDetails SubscriptionStopped { get; } = new TranscriptionStatusDetails(SubscriptionStoppedValue); + /// unspecifiedError. + public static TranscriptionStatusDetails UnspecifiedError { get; } = new TranscriptionStatusDetails(UnspecifiedErrorValue); + /// Determines if two values are the same. + public static bool operator ==(TranscriptionStatusDetails left, TranscriptionStatusDetails right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(TranscriptionStatusDetails left, TranscriptionStatusDetails right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator TranscriptionStatusDetails(string value) => new TranscriptionStatusDetails(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is TranscriptionStatusDetails other && Equals(other); + /// + public bool Equals(TranscriptionStatusDetails other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStopped.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStopped.Serialization.cs new file mode 100644 index 0000000000000..9cb683ea0e462 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStopped.Serialization.cs @@ -0,0 +1,71 @@ +// 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 +{ + public partial class TranscriptionStopped + { + internal static TranscriptionStopped DeserializeTranscriptionStopped(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional callConnectionId = default; + Optional serverCallId = default; + Optional correlationId = default; + Optional operationContext = default; + Optional resultInformation = default; + Optional transcriptionUpdateResult = default; + foreach (var property in element.EnumerateObject()) + { + 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; + } + 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("transcriptionUpdateResult"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + transcriptionUpdateResult = TranscriptionUpdate.DeserializeTranscriptionUpdate(property.Value); + continue; + } + } + return new TranscriptionStopped(callConnectionId.Value, serverCallId.Value, correlationId.Value, operationContext.Value, resultInformation.Value, transcriptionUpdateResult.Value); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStopped.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStopped.cs index 82a7cb32cc476..55252fff73b51 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStopped.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionStopped.cs @@ -8,23 +8,29 @@ namespace Azure.Communication.CallAutomation { /// The TranscriptionStopped. - internal partial class TranscriptionStopped + public partial class TranscriptionStopped { /// Initializes a new instance of TranscriptionStopped. internal TranscriptionStopped() { } - /// 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; } - /// Used by customers when calling answerCall action to correlate the request to the response event. - public string OperationContext { get; } - /// Contains the resulting SIP code/sub-code and message from NGC services. - public ResultInformation ResultInformation { get; } + /// Initializes a new instance of TranscriptionStopped. + /// Call connection ID. + /// Server call ID. + /// Correlation ID for event to call correlation. Also called ChainId for skype chain ID. + /// Used by customers when calling answerCall action to correlate the request to the response event. + /// Contains the resulting SIP code/sub-code and message from NGC services. + /// Defines the result for TranscriptionUpdate with the current status and the details about the status. + internal TranscriptionStopped(string callConnectionId, string serverCallId, string correlationId, string operationContext, ResultInformation resultInformation, TranscriptionUpdate transcriptionUpdateResult) + { + CallConnectionId = callConnectionId; + ServerCallId = serverCallId; + CorrelationId = correlationId; + OperationContext = operationContext; + ResultInformation = resultInformation; + TranscriptionUpdateResult = transcriptionUpdateResult; + } /// Defines the result for TranscriptionUpdate with the current status and the details about the status. public TranscriptionUpdate TranscriptionUpdateResult { get; } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionTransportType.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionTransport.cs similarity index 56% rename from sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionTransportType.cs rename to sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionTransport.cs index 4962a085de336..aa9a61c1635e4 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionTransportType.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionTransport.cs @@ -11,13 +11,13 @@ namespace Azure.Communication.CallAutomation { /// The type of transport to be used for live transcription, eg. Websocket. - public readonly partial struct TranscriptionTransportType : IEquatable + public readonly partial struct TranscriptionTransport : IEquatable { private readonly string _value; - /// Initializes a new instance of . + /// Initializes a new instance of . /// is null. - public TranscriptionTransportType(string value) + public TranscriptionTransport(string value) { _value = value ?? throw new ArgumentNullException(nameof(value)); } @@ -25,19 +25,19 @@ public TranscriptionTransportType(string value) private const string WebsocketValue = "websocket"; /// websocket. - public static TranscriptionTransportType Websocket { get; } = new TranscriptionTransportType(WebsocketValue); - /// Determines if two values are the same. - public static bool operator ==(TranscriptionTransportType left, TranscriptionTransportType right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(TranscriptionTransportType left, TranscriptionTransportType right) => !left.Equals(right); - /// Converts a string to a . - public static implicit operator TranscriptionTransportType(string value) => new TranscriptionTransportType(value); + public static TranscriptionTransport Websocket { get; } = new TranscriptionTransport(WebsocketValue); + /// Determines if two values are the same. + public static bool operator ==(TranscriptionTransport left, TranscriptionTransport right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(TranscriptionTransport left, TranscriptionTransport right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator TranscriptionTransport(string value) => new TranscriptionTransport(value); /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is TranscriptionTransportType other && Equals(other); + public override bool Equals(object obj) => obj is TranscriptionTransport other && Equals(other); /// - public bool Equals(TranscriptionTransportType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + public bool Equals(TranscriptionTransport other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionUpdate.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionUpdate.Serialization.cs new file mode 100644 index 0000000000000..95a2e023e5c82 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionUpdate.Serialization.cs @@ -0,0 +1,47 @@ +// 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 +{ + public partial class TranscriptionUpdate + { + internal static TranscriptionUpdate DeserializeTranscriptionUpdate(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional transcriptionStatus = default; + Optional transcriptionStatusDetails = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("transcriptionStatus"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + transcriptionStatus = new TranscriptionStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("transcriptionStatusDetails"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + transcriptionStatusDetails = new TranscriptionStatusDetails(property.Value.GetString()); + continue; + } + } + return new TranscriptionUpdate(Optional.ToNullable(transcriptionStatus), Optional.ToNullable(transcriptionStatusDetails)); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionUpdate.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionUpdate.cs index 25237c7ab8a3e..2cd54a244ba26 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionUpdate.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/TranscriptionUpdate.cs @@ -8,16 +8,25 @@ namespace Azure.Communication.CallAutomation { /// The TranscriptionUpdate. - internal partial class TranscriptionUpdate + public partial class TranscriptionUpdate { /// Initializes a new instance of TranscriptionUpdate. internal TranscriptionUpdate() { } + /// Initializes a new instance of TranscriptionUpdate. + /// + /// + internal TranscriptionUpdate(TranscriptionStatus? transcriptionStatus, TranscriptionStatusDetails? transcriptionStatusDetails) + { + TranscriptionStatus = transcriptionStatus; + TranscriptionStatusDetails = transcriptionStatusDetails; + } + /// Gets the transcription status. - public string TranscriptionStatus { get; } + public TranscriptionStatus? TranscriptionStatus { get; } /// Gets the transcription status details. - public string TranscriptionStatusDetails { get; } + public TranscriptionStatusDetails? TranscriptionStatusDetails { get; } } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequest.Serialization.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequestInternal.Serialization.cs similarity index 84% rename from sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequest.Serialization.cs rename to sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequestInternal.Serialization.cs index 0f76b6afdc77b..906f8b8e63761 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequest.Serialization.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequestInternal.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.Communication.CallAutomation { - public partial class UpdateTranscriptionDataRequest : IUtf8JsonSerializable + internal partial class UpdateTranscriptionDataRequestInternal : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequest.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequestInternal.cs similarity index 81% rename from sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequest.cs rename to sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequestInternal.cs index abc8246a960ba..8d4f6ee07a320 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequest.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Generated/Models/UpdateTranscriptionDataRequestInternal.cs @@ -11,12 +11,12 @@ namespace Azure.Communication.CallAutomation { /// The UpdateTranscriptionDataRequest. - public partial class UpdateTranscriptionDataRequest + internal partial class UpdateTranscriptionDataRequestInternal { - /// Initializes a new instance of UpdateTranscriptionDataRequest. + /// Initializes a new instance of UpdateTranscriptionDataRequestInternal. /// Defines new locale for transcription. /// is null. - public UpdateTranscriptionDataRequest(string locale) + public UpdateTranscriptionDataRequestInternal(string locale) { Argument.AssertNotNull(locale, nameof(locale)); diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/AnswerCallOptions.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/AnswerCallOptions.cs index 9b52e394413a6..7c936f3b31fb0 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Models/AnswerCallOptions.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/AnswerCallOptions.cs @@ -36,6 +36,11 @@ public AnswerCallOptions(string incomingCallContext, Uri callbackUri) /// public MediaStreamingOptions MediaStreamingOptions { get; set; } + /// + /// Live Transcription Configuration. + /// + public TranscriptionOptions TranscriptionOptions { get; set; } + /// /// The endpoint uri of the Azure Cognitive Services resource attached /// diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CallConnectionProperties.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CallConnectionProperties.cs index 1c125a42848c1..a04995d333f88 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CallConnectionProperties.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CallConnectionProperties.cs @@ -19,7 +19,8 @@ internal CallConnectionProperties( CommunicationIdentifier sourceIdentity, PhoneNumberIdentifier sourceCallerIdNumber, string sourceDisplayName, - string mediaSubscriptionId + string mediaSubscriptionId, + string dataSubscriptionId ) { CallConnectionId = callConnectionId; @@ -31,6 +32,7 @@ string mediaSubscriptionId SourceCallerIdNumber = sourceCallerIdNumber; SourceDisplayName = sourceDisplayName; MediaSubscriptionId = mediaSubscriptionId; + DataSubscriptionId = dataSubscriptionId; } internal CallConnectionProperties(CallConnectionPropertiesInternal callConnectionPropertiesDtoInternal) @@ -50,6 +52,7 @@ internal CallConnectionProperties(CallConnectionPropertiesInternal callConnectio CallbackUri = new Uri(callConnectionPropertiesDtoInternal.CallbackUri); MediaSubscriptionId = callConnectionPropertiesDtoInternal.MediaSubscriptionId; + DataSubscriptionId = callConnectionPropertiesDtoInternal.DataSubscriptionId; Source = callConnectionPropertiesDtoInternal.SourceIdentity == null? null : CommunicationIdentifierSerializer.Deserialize(callConnectionPropertiesDtoInternal.SourceIdentity); SourceDisplayName = callConnectionPropertiesDtoInternal.SourceDisplayName; CorrelationId = callConnectionPropertiesDtoInternal.CorrelationId; @@ -73,6 +76,8 @@ internal CallConnectionProperties(CallConnectionPropertiesInternal callConnectio public Uri CallbackUri { get; } /// SubscriptionId for media streaming. public string MediaSubscriptionId { get; } + /// SubscriptionId for transcription. + public string DataSubscriptionId { get; } /// /// Caller ID phone number to appear on the invitee. /// diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CommunicationCallAutomationModelFactory.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CommunicationCallAutomationModelFactory.cs index 857262a1e1152..28465f8f7381d 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CommunicationCallAutomationModelFactory.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CommunicationCallAutomationModelFactory.cs @@ -40,6 +40,7 @@ public static AnswerCallResult AnswerCallResult(CallConnection callConnection = /// Caller ID phone number to appear on the invitee. /// Display name to appear on the invitee. /// The subscriptionId for Media Streaming. + /// The subscriptionId for transcription. /// A new instance for mocking. public static CallConnectionProperties CallConnectionProperties( string callConnectionId = default, @@ -50,9 +51,10 @@ public static CallConnectionProperties CallConnectionProperties( CommunicationIdentifier sourceIdentity = default, PhoneNumberIdentifier sourceCallerIdNumber = default, string sourceDisplayName = default, - string mediaSubscriptionId = default) + string mediaSubscriptionId = default, + string dataSubscriptionId = default) { - return new CallConnectionProperties(callConnectionId, serverCallId, targets, callConnectionState, callbackUri, sourceIdentity, sourceCallerIdNumber, sourceDisplayName, mediaSubscriptionId); + return new CallConnectionProperties(callConnectionId, serverCallId, targets, callConnectionState, callbackUri, sourceIdentity, sourceCallerIdNumber, sourceDisplayName, mediaSubscriptionId, dataSubscriptionId); } /// Initializes a new instance of CallParticipant. diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateCallOptions.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateCallOptions.cs index 228b4545aaaab..52291c9c59f27 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateCallOptions.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateCallOptions.cs @@ -40,6 +40,11 @@ public CreateCallOptions(CallInvite callInvite, Uri callbackUri) /// public MediaStreamingOptions MediaStreamingOptions { get; set; } + /// + /// Live Transcription Configuration. + /// + public TranscriptionOptions TranscriptionOptions { get; set; } + /// /// The endpoint URL of the Azure Cognitive Services resource attached /// diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateGroupCallOptions.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateGroupCallOptions.cs index e392efff8f491..55bedb206ed69 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateGroupCallOptions.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/CreateGroupCallOptions.cs @@ -52,6 +52,11 @@ public CreateGroupCallOptions(IEnumerable targets, Uri /// public MediaStreamingOptions MediaStreamingOptions { get; set; } + /// + /// Live Transcription Configuration. + /// + public TranscriptionOptions TranscriptionOptions { get; set; } + /// /// The endpoint URL of the Azure Cognitive Services resource attached /// 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 a6eefcfd64f8a..ca709577bbcf5 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CallAutomationEventParser.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CallAutomationEventParser.cs @@ -138,6 +138,14 @@ private static CallAutomationEventBase Deserialize(string eventData, string type return CancelAddParticipantFailed.Deserialize(eventData); case nameof(AddParticipantCancelled): return AddParticipantCancelled.Deserialize(eventData); + case nameof(TranscriptionStarted): + return TranscriptionStarted.Deserialize(eventData); + case nameof(TranscriptionStopped): + return TranscriptionStopped.Deserialize(eventData); + case nameof(TranscriptionResumed): + return TranscriptionResumed.Deserialize(eventData); + case nameof(TranscriptionFailed): + return TranscriptionFailed.Deserialize(eventData); #region Dialog case nameof(DialogCompleted): return DialogCompleted.Deserialize(eventData); diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionFailed.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionFailed.cs new file mode 100644 index 0000000000000..9b5dd5baa4e2f --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionFailed.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + /// + /// The TranscriptionFailed event. + /// + + [CodeGenModel("TranscriptionFailed", Usage = new string[] { "output" }, Formats = new string[] { "json" })] + public partial class TranscriptionFailed : CallAutomationEventBase + { + /// + /// Deserialize event. + /// + /// The json content. + /// The new object. + public static TranscriptionFailed Deserialize(string content) + { + using var document = JsonDocument.Parse(content); + JsonElement element = document.RootElement; + + return DeserializeTranscriptionFailed(element); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionResumed.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionResumed.cs new file mode 100644 index 0000000000000..4237142e2b6dc --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionResumed.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + /// + /// The TranscriptionResumed event. + /// + + [CodeGenModel("TranscriptionResumed", Usage = new string[] { "output" }, Formats = new string[] { "json" })] + public partial class TranscriptionResumed : CallAutomationEventBase + { + /// + /// Deserialize event. + /// + /// The json content. + /// The new object. + public static TranscriptionResumed Deserialize(string content) + { + using var document = JsonDocument.Parse(content); + JsonElement element = document.RootElement; + + return DeserializeTranscriptionResumed(element); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionStarted.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionStarted.cs new file mode 100644 index 0000000000000..209cf0c7c1f76 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionStarted.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + /// + /// The TranscriptionStarted event. + /// + + [CodeGenModel("TranscriptionStarted", Usage = new string[] { "output" }, Formats = new string[] { "json" })] + public partial class TranscriptionStarted : CallAutomationEventBase + { + /// + /// Deserialize event. + /// + /// The json content. + /// The new object. + public static TranscriptionStarted Deserialize(string content) + { + using var document = JsonDocument.Parse(content); + JsonElement element = document.RootElement; + + return DeserializeTranscriptionStarted(element); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionStopped.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionStopped.cs new file mode 100644 index 0000000000000..a35c7def956a4 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionStopped.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + /// + /// The TranscriptionStopped event. + /// + + [CodeGenModel("TranscriptionStopped", Usage = new string[] { "output" }, Formats = new string[] { "json" })] + public partial class TranscriptionStopped : CallAutomationEventBase + { + /// + /// Deserialize event. + /// + /// The json content. + /// The new object. + public static TranscriptionStopped Deserialize(string content) + { + using var document = JsonDocument.Parse(content); + JsonElement element = document.RootElement; + + return DeserializeTranscriptionStopped(element); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionUpdate.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionUpdate.cs new file mode 100644 index 0000000000000..fb08933b8c930 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/TranscriptionUpdate.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + [CodeGenModel("TranscriptionUpdate", Usage = new string[] { "output" }, Formats = new string[] { "json" })] + public partial class TranscriptionUpdate + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/StartTranscriptionOptions.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/StartTranscriptionOptions.cs new file mode 100644 index 0000000000000..7c88f00a3c0b4 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/StartTranscriptionOptions.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; +using System.Linq; + +namespace Azure.Communication.CallAutomation +{ + /// + /// Options for the Start transcription Request. + /// + public class StartTranscriptionOptions + { + /// Defines Locale for the transcription e,g en-US. + public string Locale { get; set; } + + /// The value to identify context of the operation. + public string OperationContext { get; set; } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/StartTranscriptionRequestInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/StartTranscriptionRequestInternal.cs new file mode 100644 index 0000000000000..bbff6d4ec220e --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/StartTranscriptionRequestInternal.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + [CodeGenModel("StartTranscriptionRequest")] + internal partial class StartTranscriptionRequestInternal + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/StopTranscriptionOptions.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/StopTranscriptionOptions.cs new file mode 100644 index 0000000000000..7973652d6a58a --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/StopTranscriptionOptions.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; +using System.Linq; + +namespace Azure.Communication.CallAutomation +{ + /// + /// Options for the stop transcription Request. + /// + public class StopTranscriptionOptions + { + /// The value to identify context of the operation. + public string OperationContext { get; set; } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/StopTranscriptionRequestInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/StopTranscriptionRequestInternal.cs new file mode 100644 index 0000000000000..d8b806a1090f4 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/StopTranscriptionRequestInternal.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + [CodeGenModel("StopTranscriptionRequest")] + internal partial class StopTranscriptionRequestInternal + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/ResultStatus.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/ResultStatus.cs new file mode 100644 index 0000000000000..cd66549b8114c --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/ResultStatus.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Communication.CallAutomation.Models.Transcription +{ + /// + /// The status of the result of transcription + /// + public enum ResultStatus + { + /// + /// Intermediate result + /// + Intermediate, + + /// + /// Final result + /// + Final + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TextFormat.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TextFormat.cs new file mode 100644 index 0000000000000..f5464aca03bc2 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TextFormat.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Communication.CallAutomation.Models.Transcription +{ + /// + /// The format of transcription text + /// + public enum TextFormat + { + /// + /// Formatted recognize text with punctuations + /// + Display + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionData.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionData.cs new file mode 100644 index 0000000000000..c59841900cb1e --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionData.cs @@ -0,0 +1,89 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Azure.Communication.CallAutomation.Models.Transcription +{ + /// + /// Streaming Transcription. + /// + internal class TranscriptionData : TranscriptionPackageBase + { + internal TranscriptionData(string text, string format, double confidence, ulong offset, IEnumerable words, string participantRawID, string resultStatus) + { + Text = text; + Format = ConvertToTextFormatEnum(format); + Confidence = confidence; + Offset = offset; + Words = words; + if (participantRawID != null) + { + Participant = new CommunicationUserIdentifier(participantRawID); + } + ResultStatus = ConvertToResultStatusEnum(resultStatus); + } + + /// + /// The display form of the recognized word + /// + public string Text { get; set; } + + /// + /// The format of text + /// + public TextFormat Format { get; set; } + + /// + /// Confidence of recognition of the whole phrase, from 0.0 (no confidence) to 1.0 (full confidence) + /// + public double Confidence { get; set; } + + /// + /// The position of this payload + /// + + public ulong Offset { get; set; } + + /// + /// The result for each word of the phrase + /// + public IEnumerable Words { get; set; } + + /// + /// The identified speaker based on participant raw ID + /// + public CommunicationUserIdentifier Participant { get; set; } + + /// + /// Status of the result of transcription + /// + public ResultStatus ResultStatus { get; set; } + + private static ResultStatus ConvertToResultStatusEnum(string resultStatus) + { + switch (resultStatus) + { + case "intermediate": + return ResultStatus.Intermediate; + case "final": + return ResultStatus.Final; + default: + throw new NotSupportedException(resultStatus); + } + } + + private static TextFormat ConvertToTextFormatEnum(string format) + { + switch (format) + { + case "display": + return TextFormat.Display; + default: + throw new NotSupportedException(format); + } + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionDataInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionDataInternal.cs new file mode 100644 index 0000000000000..e4351402df224 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionDataInternal.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Azure.Communication.CallAutomation.Models.Transcription +{ + /// + /// Streaming Transcription. + /// + internal class TranscriptionDataInternal + { + /// + /// The display form of the recognized word + /// + [JsonPropertyName("text")] + public string Text { get; set; } + + /// + /// The format of text + /// + [JsonPropertyName("format")] + public string Format { get; set; } + + /// + /// Confidence of recognition of the whole phrase, from 0.0 (no confidence) to 1.0 (full confidence) + /// + [JsonPropertyName("confidence")] + public double Confidence { get; set; } + + /// + /// The position of this payload + /// + + [JsonPropertyName("offset")] + public ulong Offset { get; set; } + + /// + /// The result for each word of the phrase + /// + [JsonPropertyName("words")] + public IEnumerable Words { get; set; } + + /// + /// The identified speaker based on participant raw ID + /// + [JsonPropertyName("participantRawID")] + public string ParticipantRawID { get; set; } + + /// + /// Status of the result of transcription + /// + [JsonPropertyName("resultStatus")] + public string ResultStatus { get; set; } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionMetadata.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionMetadata.cs new file mode 100644 index 0000000000000..85211eb816ae7 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionMetadata.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json.Serialization; + +namespace Azure.Communication.CallAutomation +{ + /// + /// Transcription package for Transcription Streaming. + /// + public class TranscriptionMetadata : TranscriptionPackageBase + { + /// + /// Transcription Subscription Id. + /// + [JsonPropertyName("subscriptionId")] + public string TranscriptionSubscriptionId { get; set; } + + /// + /// The target locale in which the translated text needs to be + /// + [JsonPropertyName("locale")] + public string Locale { get; set; } + + /// + /// call connection Id. + /// + [JsonPropertyName("callConnectionId")] + public string CallConnectionId { get; set; } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionPackageBase.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionPackageBase.cs new file mode 100644 index 0000000000000..5077fa14d6175 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionPackageBase.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Communication.CallAutomation +{ + /// + /// Transcription Package. + /// + public abstract class TranscriptionPackageBase + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionPackageParser.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionPackageParser.cs new file mode 100644 index 0000000000000..d0e55e5742705 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/TranscriptionPackageParser.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text; +using System.Text.Json; +using Azure.Communication.CallAutomation.Models.Transcription; + +namespace Azure.Communication.CallAutomation +{ + /// + /// Parser of the different packages received as part of + /// Transcription data streaming. + /// + public static class TranscriptionPackageParser + { + /// + /// Parsing a Transcription package from BinaryData. + /// + /// + /// + public static TranscriptionPackageBase Parse(BinaryData json) + { + return Parse(json.ToString()); + } + + /// + /// Parsing a Transcription package from a byte array. + /// + /// a UTF8 byte array. + /// + public static TranscriptionPackageBase Parse(byte[] receivedBytes) + { + return Parse(Encoding.UTF8.GetString(receivedBytes)); + } + + /// + /// Parse the incoming package. + /// + /// + /// + /// + public static TranscriptionPackageBase Parse(string stringJson) + { + JsonElement package = JsonDocument.Parse(stringJson).RootElement; + if (package.GetProperty("kind").ToString() == "TranscriptionMetadata") + { + return JsonSerializer.Deserialize(package.GetProperty("transcriptionMetadata").ToString()); + } + else if (package.GetProperty("kind").ToString() == "TranscriptionData") + { + TranscriptionDataInternal transcriptionDataInternal = JsonSerializer.Deserialize( + package.GetProperty("transcriptionData").ToString() + ); + return new TranscriptionData( + transcriptionDataInternal.Text, + transcriptionDataInternal.Format, + transcriptionDataInternal.Confidence, + transcriptionDataInternal.Offset, + transcriptionDataInternal.Words, + transcriptionDataInternal.ParticipantRawID, + transcriptionDataInternal.ResultStatus + ); + } + else + throw new NotSupportedException(stringJson); + } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/Word.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/Word.cs new file mode 100644 index 0000000000000..fa3af8844d9bf --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/Transcription/Word.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json.Serialization; + +namespace Azure.Communication.CallAutomation.Models.Transcription +{ + internal class Word + { + /// + /// Text in the phrase. + /// + [JsonPropertyName("text")] + public string Text { get; set; } + /// + /// The word's position within the phrase. + /// + [JsonPropertyName("offset")] + public ulong Offset { get; set; } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionOptions.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionOptions.cs new file mode 100644 index 0000000000000..28f5687b881fc --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionOptions.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + /// Options of live transcription. + public partial class TranscriptionOptions + { + /// Initializes a new instance of TranscriptionOptions. + /// Transport URL for live transcription. + /// The type of transport to be used for live transcription, eg. Websocket. + /// Defines the locale for the data e.g en-CA, en-AU. + /// Determines if the transcription should be started immediately after call is answered or not. + /// or is null. + public TranscriptionOptions(Uri transportUri, TranscriptionTransport transportType, string locale, bool startTranscription) + { + Argument.AssertNotNull(transportUri, nameof(transportUri)); + Argument.AssertNotNull(locale, nameof(locale)); + + TransportUrl = transportUri; + TranscriptionTransport = transportType; + Locale = locale; + StartTranscription = startTranscription; + } + + /// Transport URL for live transcription. + public Uri TransportUrl { get; } + /// The type of transport to be used for live transcription, eg. Websocket. + public TranscriptionTransport TranscriptionTransport { get; } + /// Defines the locale for the data e.g en-CA, en-AU. + public string Locale { get; } + /// Determines if the transcription should be started immediately after call is answered or not. + public bool StartTranscription { get; } + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionOptionsInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionOptionsInternal.cs new file mode 100644 index 0000000000000..4832ba8e5fcb8 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionOptionsInternal.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + [CodeGenModel("TranscriptionConfiguration")] + internal partial class TranscriptionOptionsInternal + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionStatus.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionStatus.cs new file mode 100644 index 0000000000000..9545937f5e6bf --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionStatus.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json.Serialization; +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + [CodeGenModel("TranscriptionStatus", Usage = new string[] { "output" }, Formats = new string[] { "json" })] + [JsonConverter(typeof(EquatableEnumJsonConverter))] + public readonly partial struct TranscriptionStatus : IEquatable + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionStatusDetails.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionStatusDetails.cs new file mode 100644 index 0000000000000..7c3e145941f23 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionStatusDetails.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json.Serialization; +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + [CodeGenModel("TranscriptionStatusDetails", Usage = new string[] { "output" }, Formats = new string[] { "json" })] + [JsonConverter(typeof(EquatableEnumJsonConverter))] + public readonly partial struct TranscriptionStatusDetails : IEquatable + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionTransport.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionTransport.cs new file mode 100644 index 0000000000000..b25c70f5cc8ff --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/TranscriptionTransport.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 states of a call. + /// + [CodeGenModel("TranscriptionTransportType", Usage = new string[] { "input" }, Formats = new string[] { "json" })] + public readonly partial struct TranscriptionTransport + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/Models/UpdateTranscriptionDataRequestInternal.cs b/sdk/communication/Azure.Communication.CallAutomation/src/Models/UpdateTranscriptionDataRequestInternal.cs new file mode 100644 index 0000000000000..7af734778a475 --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/src/Models/UpdateTranscriptionDataRequestInternal.cs @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; + +namespace Azure.Communication.CallAutomation +{ + [CodeGenModel("UpdateTranscriptionDataRequest")] + internal partial class UpdateTranscriptionDataRequestInternal + { + } +} diff --git a/sdk/communication/Azure.Communication.CallAutomation/src/autorest.md b/sdk/communication/Azure.Communication.CallAutomation/src/autorest.md index 63aa64e69edaf..632070f1032a4 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-01-15-preview require: - - https://github.com/williamzhao87/azure-rest-api-specs/blob/8f5bd72f81f7fa9020f6834f06f3db54a475ee68/specification/communication/data-plane/CallAutomation/readme.md + - https://github.com/williamzhao87/azure-rest-api-specs/blob/e13717bd01daf5784c5923a2ebf54c32762b2051/specification/communication/data-plane/CallAutomation/readme.md title: Azure Communication Services diff --git a/sdk/communication/Azure.Communication.CallAutomation/tests/CallAutomationClients/CallAutomationClientTests.cs b/sdk/communication/Azure.Communication.CallAutomation/tests/CallAutomationClients/CallAutomationClientTests.cs index 79eecb444b28f..609fc7ab39036 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/tests/CallAutomationClients/CallAutomationClientTests.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/tests/CallAutomationClients/CallAutomationClientTests.cs @@ -18,6 +18,12 @@ public class CallAutomationClientTests : CallAutomationTestBase MediaStreamingContent.Audio, MediaStreamingAudioChannel.Mixed); + private readonly TranscriptionOptions _transcriptionConfiguration = new TranscriptionOptions( + new Uri("https://websocket"), + TranscriptionTransport.Websocket, + "en-CA", + true); + [TestCaseSource(nameof(TestData_AnswerCall))] public async Task AnswerCallAsync_200OK(string incomingCallContext, Uri callbackUri) { @@ -28,6 +34,7 @@ public async Task AnswerCallAsync_200OK(string incomingCallContext, Uri callback Assert.AreEqual((int)HttpStatusCode.OK, response.GetRawResponse().Status); verifyCallConnectionProperties(response.Value.CallConnectionProperties); Assert.Null(response.Value.CallConnectionProperties.MediaSubscriptionId); + Assert.Null(response.Value.CallConnectionProperties.DataSubscriptionId); Assert.AreEqual(CallConnectionId, response.Value.CallConnection.CallConnectionId); } @@ -41,16 +48,18 @@ public void AnswerCall_200OK(string incomingCallContext, Uri callbackUri) Assert.AreEqual((int)HttpStatusCode.OK, response.GetRawResponse().Status); verifyCallConnectionProperties(response.Value.CallConnectionProperties); Assert.Null(response.Value.CallConnectionProperties.MediaSubscriptionId); + Assert.Null(response.Value.CallConnectionProperties.DataSubscriptionId); Assert.AreEqual(CallConnectionId, response.Value.CallConnection.CallConnectionId); } [TestCaseSource(nameof(TestData_AnswerCall))] public async Task AnswerCallWithOptionsAsync_200OK(string incomingCallContext, Uri callbackUri) { - CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(200, CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionPayload); + CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(200, CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionAndTranscriptionPayload); AnswerCallOptions options = new AnswerCallOptions(incomingCallContext: incomingCallContext, callbackUri: callbackUri) { MediaStreamingOptions = _mediaStreamingConfiguration, + TranscriptionOptions = _transcriptionConfiguration, OperationContext = "operation_context" }; @@ -60,15 +69,17 @@ public async Task AnswerCallWithOptionsAsync_200OK(string incomingCallContext, U verifyCallConnectionProperties(response.Value.CallConnectionProperties); Assert.AreEqual(CallConnectionId, response.Value.CallConnection.CallConnectionId); Assert.AreEqual("mediaSubscriptionId", response.Value.CallConnectionProperties.MediaSubscriptionId); + Assert.AreEqual("dataSubscriptionId", response.Value.CallConnectionProperties.DataSubscriptionId); } [TestCaseSource(nameof(TestData_AnswerCall))] public void AnswerCallWithOptions_200OK(string incomingCallContext, Uri callbackUri) { - CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(200, CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionPayload); + CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(200, CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionAndTranscriptionPayload); AnswerCallOptions options = new AnswerCallOptions(incomingCallContext: incomingCallContext, callbackUri: callbackUri) { - MediaStreamingOptions = _mediaStreamingConfiguration + MediaStreamingOptions = _mediaStreamingConfiguration, + TranscriptionOptions = _transcriptionConfiguration }; var response = callAutomationClient.AnswerCall(options); @@ -77,6 +88,7 @@ public void AnswerCallWithOptions_200OK(string incomingCallContext, Uri callback verifyCallConnectionProperties(response.Value.CallConnectionProperties); Assert.AreEqual(CallConnectionId, response.Value.CallConnection.CallConnectionId); Assert.AreEqual("mediaSubscriptionId", response.Value.CallConnectionProperties.MediaSubscriptionId); + Assert.AreEqual("dataSubscriptionId", response.Value.CallConnectionProperties.DataSubscriptionId); } [TestCaseSource(nameof(TestData_AnswerCall))] @@ -203,6 +215,7 @@ public async Task CreateCallAsync_201Created(CallInvite target, Uri callbackUri) Assert.AreEqual((int)HttpStatusCode.Created, response.GetRawResponse().Status); verifyCallConnectionProperties(result.CallConnectionProperties); Assert.Null(result.CallConnectionProperties.MediaSubscriptionId); + Assert.Null(result.CallConnectionProperties.DataSubscriptionId); Assert.AreEqual(CallConnectionId, result.CallConnection.CallConnectionId); } @@ -218,18 +231,20 @@ public void CreateCall_201Created(CallInvite target, Uri callbackUri) Assert.AreEqual((int)HttpStatusCode.Created, response.GetRawResponse().Status); verifyCallConnectionProperties(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) { - CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(201, CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionPayload); + CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(201, CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionAndTranscriptionPayload); CreateCallOptions options = new CreateCallOptions( callInvite: target, callbackUri: callbackUri) { - MediaStreamingOptions = _mediaStreamingConfiguration + MediaStreamingOptions = _mediaStreamingConfiguration, + TranscriptionOptions = _transcriptionConfiguration }; var response = await callAutomationClient.CreateCallAsync(options).ConfigureAwait(false); @@ -239,17 +254,19 @@ public async Task CreateCallWithOptionsAsync_201Created(CallInvite target, Uri c verifyCallConnectionProperties(result.CallConnectionProperties); Assert.AreEqual(CallConnectionId, result.CallConnection.CallConnectionId); Assert.AreEqual("mediaSubscriptionId", result.CallConnectionProperties.MediaSubscriptionId); + Assert.AreEqual("dataSubscriptionId", result.CallConnectionProperties.DataSubscriptionId); } [TestCaseSource(nameof(TestData_CreateCall))] public void CreateCallWithOptions_201Created(CallInvite target, Uri callbackUri) { - CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(201, CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionPayload); + CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(201, CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionAndTranscriptionPayload); CreateCallOptions options = new CreateCallOptions( callInvite: target, callbackUri: callbackUri) { - MediaStreamingOptions = _mediaStreamingConfiguration + MediaStreamingOptions = _mediaStreamingConfiguration, + TranscriptionOptions = _transcriptionConfiguration }; var response = callAutomationClient.CreateCall(options); @@ -259,6 +276,7 @@ public void CreateCallWithOptions_201Created(CallInvite target, Uri callbackUri) verifyCallConnectionProperties(result.CallConnectionProperties); Assert.AreEqual(CallConnectionId, result.CallConnection.CallConnectionId); Assert.AreEqual("mediaSubscriptionId", result.CallConnectionProperties.MediaSubscriptionId); + Assert.AreEqual("dataSubscriptionId", result.CallConnectionProperties.DataSubscriptionId); } [TestCaseSource(nameof(TestData_CreateCall))] @@ -300,12 +318,13 @@ public void GetCallRecording() [TestCaseSource(nameof(TestData_CreateGroupCall))] public async Task CreateGroupCallAsync_201Created(IEnumerable targets, Uri callbackUri, PhoneNumberIdentifier callerIdNumber) { - CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(201, CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionPayload); + CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(201, CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionAndTranscriptionPayload); CreateGroupCallOptions options = new( targets: targets, callbackUri: callbackUri) { MediaStreamingOptions = _mediaStreamingConfiguration, + TranscriptionOptions = _transcriptionConfiguration, SourceCallerIdNumber = callerIdNumber, }; @@ -316,6 +335,7 @@ public async Task CreateGroupCallAsync_201Created(IEnumerable> operation) + { + _callMedia = GetCallMedia(202); + var result = await operation(_callMedia); + Assert.IsNotNull(result); + Assert.AreEqual((int)HttpStatusCode.Accepted, result.Status); + } + + [TestCaseSource(nameof(TestData_StopTranscriptionOperationsAsync))] + public async Task StopTranscriptionOperationsAsync_Return202Accepted(Func> operation) + { + _callMedia = GetCallMedia(202); + var result = await operation(_callMedia); + Assert.IsNotNull(result); + Assert.AreEqual((int)HttpStatusCode.Accepted, result.Status); + } + + [TestCaseSource(nameof(TestData_UpdateTranscriptionDataOperationsAsync))] + public async Task UpdateTranscriptionDataOperationsAsync_Return202Accepted(Func> operation) + { + _callMedia = GetCallMedia(202); + var result = await operation(_callMedia); + Assert.IsNotNull(result); + Assert.AreEqual((int)HttpStatusCode.Accepted, result.Status); + } + [TestCaseSource(nameof(TestData_PlayOperations))] public void MediaOperations_Return202Accepted(Func> operation) { @@ -273,6 +300,33 @@ public void StopContinuousRecognizeOperations_Return200OK(Func operation) + { + _callMedia = GetCallMedia(202); + var result = operation(_callMedia); + Assert.IsNotNull(result); + Assert.AreEqual((int)HttpStatusCode.Accepted, result.Status); + } + + [TestCaseSource(nameof(TestData_StopTranscriptionOperations))] + public void StopTranscriptionOperations_Return202Accepted(Func operation) + { + _callMedia = GetCallMedia(202); + var result = operation(_callMedia); + Assert.IsNotNull(result); + Assert.AreEqual((int)HttpStatusCode.Accepted, result.Status); + } + + [TestCaseSource(nameof(TestData_UpdateTranscriptionDataOperations))] + public void UpdateTranscriptionDataOperations_Return202Accepted(Func operation) + { + _callMedia = GetCallMedia(202); + var result = operation(_callMedia); + Assert.IsNotNull(result); + Assert.AreEqual((int)HttpStatusCode.Accepted, result.Status); + } + [TestCaseSource(nameof(TestData_PlayOperationsAsync))] public void PlayOperationsAsync_Return404NotFound(Func>> operation) { @@ -324,7 +378,6 @@ public void StartContinuousRecognitionOperationsAsync_Return404NotFound(Func> operation) { _callMedia = GetCallMedia(404); @@ -334,6 +387,36 @@ public void StopContinuousRecognitionOperationsAsync_Return404NotFound(Func> operation) + { + _callMedia = GetCallMedia(404); + RequestFailedException? ex = Assert.ThrowsAsync( + async () => await operation(_callMedia)); + Assert.NotNull(ex); + Assert.AreEqual(ex?.Status, 404); + } + + [TestCaseSource(nameof(TestData_UpdateTranscriptionDataOperationsAsync))] + public void UpdateTranscriptionDataOperationsAsync_Return404NotFound(Func> operation) + { + _callMedia = GetCallMedia(404); + RequestFailedException? ex = Assert.ThrowsAsync( + async () => await operation(_callMedia)); + Assert.NotNull(ex); + Assert.AreEqual(ex?.Status, 404); + } + + [TestCaseSource(nameof(TestData_StopTranscriptionOperationsAsync))] + public void StopTranscriptionOperationsAsync_Return404NotFound(Func> operation) + { + _callMedia = GetCallMedia(404); + RequestFailedException? ex = Assert.ThrowsAsync( + async () => await operation(_callMedia)); + Assert.NotNull(ex); + Assert.AreEqual(ex?.Status, 404); + } + [TestCaseSource(nameof(TestData_PlayOperations))] public void PlayOperations_Return404NotFound(Func> operation) { @@ -395,7 +478,6 @@ public void StartContinuousRecognitionOperations_Return404NotFound(Func operation) { _callMedia = GetCallMedia(404); @@ -405,6 +487,36 @@ public void StopContinuousRecognizeOperations_Return404NotFound(Func operation) + { + _callMedia = GetCallMedia(404); + RequestFailedException? ex = Assert.Throws( + () => operation(_callMedia)); + Assert.NotNull(ex); + Assert.AreEqual(ex?.Status, 404); + } + + [TestCaseSource(nameof(TestData_StopTranscriptionOperations))] + public void StopTranscriptionOperations_Return404NotFound(Func operation) + { + _callMedia = GetCallMedia(404); + RequestFailedException? ex = Assert.Throws( + () => operation(_callMedia)); + Assert.NotNull(ex); + Assert.AreEqual(ex?.Status, 404); + } + + [TestCaseSource(nameof(TestData_UpdateTranscriptionDataOperations))] + public void UpdateTranscriptionDataOperations_Return404NotFound(Func operation) + { + _callMedia = GetCallMedia(404); + RequestFailedException? ex = Assert.Throws( + () => operation(_callMedia)); + Assert.NotNull(ex); + Assert.AreEqual(ex?.Status, 404); + } + [TestCaseSource(nameof(TestData_HoldOperationsAsync))] public async Task HoldMusicAsyncOperations_Return200Ok(Func> operation) { @@ -663,5 +775,71 @@ public void HoldMusicOperations_Return200Ok(Func operation) } }; } + + private static IEnumerable TestData_StartTranscriptionOperations() + { + return new[] + { + new Func?[] + { + callMedia => callMedia.StartTranscription() + } + }; + } + + private static IEnumerable TestData_StartTranscriptionOperationsAsync() + { + return new[] + { + new Func>?[] + { + callMedia => callMedia.StartTranscriptionAsync(new StartTranscriptionOptions(){OperationContext = "OperationContext"}) + } + }; + } + + private static IEnumerable TestData_StopTranscriptionOperations() + { + return new[] + { + new Func?[] + { + callMedia => callMedia.StopTranscription(new StopTranscriptionOptions(){OperationContext = "OperationContext"}) + } + }; + } + + private static IEnumerable TestData_StopTranscriptionOperationsAsync() + { + return new[] + { + new Func>?[] + { + callMedia => callMedia.StopTranscriptionAsync(new StopTranscriptionOptions(){OperationContext = "OperationContext"}) + } + }; + } + + private static IEnumerable TestData_UpdateTranscriptionDataOperations() + { + return new[] + { + new Func?[] + { + callMedia => callMedia.UpdateTranscriptionData("locale") + } + }; + } + + private static IEnumerable TestData_UpdateTranscriptionDataOperationsAsync() + { + return new[] + { + new Func>?[] + { + callMedia => callMedia.UpdateTranscriptionDataAsync("locale") + } + }; + } } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/tests/Events/CallAutomationEventParserTests.cs b/sdk/communication/Azure.Communication.CallAutomation/tests/Events/CallAutomationEventParserTests.cs index d507d6a756acb..e1ba705aecf82 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/tests/Events/CallAutomationEventParserTests.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/tests/Events/CallAutomationEventParserTests.cs @@ -940,5 +940,121 @@ public void CancelAddParticipantFailedEventParsed_Test() Assert.Fail("Event parsed wrongfully"); } } + + [Test] + public void TranscriptionStartedEventParsed_Test() + { + TranscriptionStarted @event = CommunicationCallAutomationModelFactory.TranscriptionStarted( + callConnectionId: "callConnectionId", + serverCallId: "serverCallId", + correlationId: "correlationId", + operationContext: "operationContext", + resultInformation: new ResultInformation(code: 200, subCode: 0, message: "Action completed successfully"), + transcriptionUpdateResult: new TranscriptionUpdate(TranscriptionStatus.TranscriptionStarted, TranscriptionStatusDetails.SubscriptionStarted)); + JsonSerializerOptions jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; + string jsonEvent = JsonSerializer.Serialize(@event, jsonOptions); + var parsedEvent = CallAutomationEventParser.Parse(jsonEvent, "Microsoft.Communication.TranscriptionStarted"); + if (parsedEvent is TranscriptionStarted transcriptionStarted) + { + Assert.AreEqual("callConnectionId", transcriptionStarted.CallConnectionId); + Assert.AreEqual("correlationId", transcriptionStarted.CorrelationId); + Assert.AreEqual("serverCallId", transcriptionStarted.ServerCallId); + Assert.AreEqual("operationContext", transcriptionStarted.OperationContext); + Assert.AreEqual(200, transcriptionStarted.ResultInformation?.Code); + Assert.AreEqual(TranscriptionStatus.TranscriptionStarted, transcriptionStarted.TranscriptionUpdateResult.TranscriptionStatus); + Assert.AreEqual(TranscriptionStatusDetails.SubscriptionStarted, transcriptionStarted.TranscriptionUpdateResult.TranscriptionStatusDetails); + } + else + { + Assert.Fail("Event parsed wrongfully"); + } + } + + [Test] + public void TranscriptionStoppedEventParsed_Test() + { + TranscriptionStopped @event = CommunicationCallAutomationModelFactory.TranscriptionStopped( + callConnectionId: "callConnectionId", + serverCallId: "serverCallId", + correlationId: "correlationId", + operationContext: "operationContext", + resultInformation: new ResultInformation(code: 200, subCode: 0, message: "Action completed successfully"), + transcriptionUpdateResult: new TranscriptionUpdate(transcriptionStatus: TranscriptionStatus.TranscriptionStopped, transcriptionStatusDetails: TranscriptionStatusDetails.SubscriptionStopped)); + JsonSerializerOptions jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; + string jsonEvent = JsonSerializer.Serialize(@event, jsonOptions); + var parsedEvent = CallAutomationEventParser.Parse(jsonEvent, "Microsoft.Communication.TranscriptionStopped"); + if (parsedEvent is TranscriptionStopped transcriptionStopped) + { + Assert.AreEqual("callConnectionId", transcriptionStopped.CallConnectionId); + Assert.AreEqual("correlationId", transcriptionStopped.CorrelationId); + Assert.AreEqual("serverCallId", transcriptionStopped.ServerCallId); + Assert.AreEqual("operationContext", transcriptionStopped.OperationContext); + Assert.AreEqual(200, transcriptionStopped.ResultInformation?.Code); + Assert.AreEqual(TranscriptionStatus.TranscriptionStopped, transcriptionStopped.TranscriptionUpdateResult.TranscriptionStatus); + Assert.AreEqual(TranscriptionStatusDetails.SubscriptionStopped, transcriptionStopped.TranscriptionUpdateResult.TranscriptionStatusDetails); + } + else + { + Assert.Fail("Event parsed wrongfully"); + } + } + + [Test] + public void TranscriptionResumedEventParsed_Test() + { + TranscriptionResumed @event = CommunicationCallAutomationModelFactory.TranscriptionResumed( + callConnectionId: "callConnectionId", + serverCallId: "serverCallId", + correlationId: "correlationId", + operationContext: "operationContext", + resultInformation: new ResultInformation(code: 200, subCode: 0, message: "Action completed successfully"), + transcriptionUpdateResult: new TranscriptionUpdate(transcriptionStatus: TranscriptionStatus.TranscriptionResumed, transcriptionStatusDetails: TranscriptionStatusDetails.StreamConnectionReestablished)); + JsonSerializerOptions jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; + string jsonEvent = JsonSerializer.Serialize(@event, jsonOptions); + var parsedEvent = CallAutomationEventParser.Parse(jsonEvent, "Microsoft.Communication.TranscriptionResumed"); + if (parsedEvent is TranscriptionResumed transcriptionResumed) + { + Assert.AreEqual("callConnectionId", transcriptionResumed.CallConnectionId); + Assert.AreEqual("correlationId", transcriptionResumed.CorrelationId); + Assert.AreEqual("serverCallId", transcriptionResumed.ServerCallId); + Assert.AreEqual("operationContext", transcriptionResumed.OperationContext); + Assert.AreEqual(200, transcriptionResumed.ResultInformation?.Code); + Assert.AreEqual(TranscriptionStatus.TranscriptionResumed, transcriptionResumed.TranscriptionUpdateResult.TranscriptionStatus); + Assert.AreEqual(TranscriptionStatusDetails.StreamConnectionReestablished, transcriptionResumed.TranscriptionUpdateResult.TranscriptionStatusDetails); + } + else + { + Assert.Fail("Event parsed wrongfully"); + } + } + + [Test] + public void TranscriptionFailedEventParsed_Test() + { + TranscriptionFailed @event = CommunicationCallAutomationModelFactory.TranscriptionFailed( + callConnectionId: "callConnectionId", + serverCallId: "serverCallId", + correlationId: "correlationId", + operationContext: "operationContext", + resultInformation: new ResultInformation(code: 200, subCode: 0, message: "Action completed successfully"), + transcriptionUpdateResult: new TranscriptionUpdate(transcriptionStatus: TranscriptionStatus.TranscriptionFailed, transcriptionStatusDetails: TranscriptionStatusDetails.UnspecifiedError)); + JsonSerializerOptions jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; + string jsonEvent = JsonSerializer.Serialize(@event, jsonOptions); + var parsedEvent = CallAutomationEventParser.Parse(jsonEvent, "Microsoft.Communication.TranscriptionFailed"); + if (parsedEvent is TranscriptionFailed transcriptionFailed) + { + Assert.AreEqual("callConnectionId", transcriptionFailed.CallConnectionId); + Assert.AreEqual("correlationId", transcriptionFailed.CorrelationId); + Assert.AreEqual("serverCallId", transcriptionFailed.ServerCallId); + Assert.AreEqual("operationContext", transcriptionFailed.OperationContext); + Assert.AreEqual(200, transcriptionFailed.ResultInformation?.Code); + Assert.AreEqual(TranscriptionStatus.TranscriptionFailed, transcriptionFailed.TranscriptionUpdateResult.TranscriptionStatus); + Assert.AreEqual(TranscriptionStatusDetails.UnspecifiedError, transcriptionFailed.TranscriptionUpdateResult.TranscriptionStatusDetails); + } + else + { + Assert.Fail("Event parsed wrongfully"); + } + } } } diff --git a/sdk/communication/Azure.Communication.CallAutomation/tests/Infrastructure/CallAutomationTestBase.cs b/sdk/communication/Azure.Communication.CallAutomation/tests/Infrastructure/CallAutomationTestBase.cs index 68b642e140dd0..1945e80d2de80 100644 --- a/sdk/communication/Azure.Communication.CallAutomation/tests/Infrastructure/CallAutomationTestBase.cs +++ b/sdk/communication/Azure.Communication.CallAutomation/tests/Infrastructure/CallAutomationTestBase.cs @@ -31,7 +31,8 @@ public class CallAutomationTestBase "\"callConnectionState\": \"connecting\"," + "\"subject\": \"dummySubject\"," + "\"callbackUri\": \"https://bot.contoso.com/callback\"," + - "\"mediaSubscriptionId\": {0}" + + "\"mediaSubscriptionId\": {0}," + + "\"dataSubscriptionId\": {1}" + "}}"; protected const string SourceId = "sourceId"; protected const string TargetId = "targetId"; @@ -43,8 +44,10 @@ public class CallAutomationTestBase private const string NoneMediaSubscriptionId = "null"; private const string MediaSubscriptionId = "\"mediaSubscriptionId\""; - protected string CreateOrAnswerCallOrGetCallConnectionPayload = string.Format(DummyPayload, NoneMediaSubscriptionId); - protected string CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionPayload = string.Format(DummyPayload, MediaSubscriptionId); + private const string NoneDataSubscriptionId = "null"; + private const string DataSubscriptionId = "\"dataSubscriptionId\""; + protected string CreateOrAnswerCallOrGetCallConnectionPayload = string.Format(DummyPayload, NoneMediaSubscriptionId, NoneDataSubscriptionId); + protected string CreateOrAnswerCallOrGetCallConnectionWithMediaSubscriptionAndTranscriptionPayload = string.Format(DummyPayload, MediaSubscriptionId, DataSubscriptionId); internal CallAutomationClient CreateMockCallAutomationClient(int responseCode, object? responseContent = null, HttpHeader[]? httpHeaders = null) { diff --git a/sdk/communication/Azure.Communication.CallAutomation/tests/Transcription/TranscriptionPackageParserTests.cs b/sdk/communication/Azure.Communication.CallAutomation/tests/Transcription/TranscriptionPackageParserTests.cs new file mode 100644 index 0000000000000..cce2f591f9afb --- /dev/null +++ b/sdk/communication/Azure.Communication.CallAutomation/tests/Transcription/TranscriptionPackageParserTests.cs @@ -0,0 +1,175 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json; +using Azure.Communication.CallAutomation.Models.Transcription; +using Newtonsoft.Json.Linq; +using NUnit.Framework; + +namespace Azure.Communication.CallAutomation.Tests.Trascription +{ + internal class TranscriptionPackageParserTests + { + [Test] + public void ParseTranscriptionMetadata_Test() + { + var metadataJson = + "{" + + "\"kind\":\"TranscriptionMetadata\"," + + "\"transcriptionMetadata\":" + + "{" + + "\"subscriptionId\":\"subscriptionId\"," + + "\"locale\":\"en-US\"," + + "\"callConnectionId\":\"callConnectionId\"" + + "}" + + "}"; + + TranscriptionMetadata streamingMetadata = (TranscriptionMetadata)TranscriptionPackageParser.Parse(metadataJson); + ValidateMetadata(streamingMetadata); + } + + [Test] + public void ParseTranscription_Test() + { + var transcriptionJson = + "{" + + "\"kind\":\"TranscriptionData\"," + + "\"transcriptionData\":" + + "{" + + "\"text\":\"Hello World!\"," + + "\"format\":\"display\"," + + "\"confidence\":0.98," + + "\"offset\":1," + + "\"words\":" + + "[" + + "{" + + "\"text\":\"Hello\"," + + "\"offset\":1" + + "}," + + "{" + + "\"text\":\"World\"," + + "\"offset\":6" + + "}" + + "]," + + "\"participantRawID\":\"abc12345\"," + + "\"resultStatus\":\"final\"" + + "}" + + "}"; + + TranscriptionData transcription = (TranscriptionData) TranscriptionPackageParser.Parse(transcriptionJson); + ValidateTranscriptionData(transcription); + } + + [Test] + public void ParseBinaryData() + { + JObject jsonData = new() + { + ["kind"] = "TranscriptionData", + ["transcriptionData"] = new JObject() + }; + jsonData["transcriptionData"]["text"] = "Hello World!"; + jsonData["transcriptionData"]["format"] = "display"; + jsonData["transcriptionData"]["confidence"] = 0.98d; + jsonData["transcriptionData"]["offset"] = 1; + + JArray words = new(); + jsonData["transcriptionData"]["words"] = words; + + JObject word0 = new() + { + ["text"] = "Hello", + ["offset"] = 1 + }; + words.Add(word0); + + JObject word1 = new() + { + ["text"] = "World", + ["offset"] = 6 + }; + words.Add(word1); + + jsonData["transcriptionData"]["participantRawID"] = "abc12345"; + jsonData["transcriptionData"]["resultStatus"] = "final"; + + var binaryData = BinaryData.FromString(jsonData.ToString()); + + TranscriptionData transcription = (TranscriptionData)TranscriptionPackageParser.Parse(binaryData); + ValidateTranscriptionData(transcription); + } + + [Test] + public void ParseAudioEventsWithBynaryArray() + { + JObject jsonData = new() + { + ["kind"] = "TranscriptionData", + ["transcriptionData"] = new JObject() + }; + jsonData["transcriptionData"]["text"] = "Hello World!"; + jsonData["transcriptionData"]["format"] = "display"; + jsonData["transcriptionData"]["confidence"] = 0.98d; + jsonData["transcriptionData"]["offset"] = 1; + + JArray words = new(); + jsonData["transcriptionData"]["words"] = words; + + JObject word0 = new() + { + ["text"] = "Hello", + ["offset"] = 1 + }; + words.Add(word0); + + JObject word1 = new() + { + ["text"] = "World", + ["offset"] = 6 + }; + words.Add(word1); + + jsonData["transcriptionData"]["participantRawID"] = "abc12345"; + jsonData["transcriptionData"]["resultStatus"] = "final"; + + byte[] receivedBytes = System.Text.Encoding.UTF8.GetBytes(jsonData.ToString()); + TranscriptionData parsedPackage = (TranscriptionData) TranscriptionPackageParser.Parse(receivedBytes); + + Assert.NotNull(parsedPackage); + ValidateTranscriptionData(parsedPackage); + } + + private static void ValidateMetadata(TranscriptionMetadata transcriptionMetadata) + { + Assert.IsNotNull(transcriptionMetadata); + Assert.AreEqual("subscriptionId", transcriptionMetadata.TranscriptionSubscriptionId); + Assert.AreEqual("en-US", transcriptionMetadata.Locale); + Assert.AreEqual("callConnectionId", transcriptionMetadata.CallConnectionId); + } + + private static void ValidateTranscriptionData(TranscriptionData transcription) + { + Assert.IsNotNull(transcription); + Assert.AreEqual("Hello World!", transcription.Text); + Assert.AreEqual(TextFormat.Display, transcription.Format); + Assert.AreEqual(0.98d, transcription.Confidence); + Assert.AreEqual(1, transcription.Offset); + + // validate individual words + IList words = transcription.Words.ToList(); + Assert.AreEqual(2, words.Count); + Assert.AreEqual("Hello", words[0].Text); + Assert.AreEqual(1, words[0].Offset); + Assert.AreEqual("World", words[1].Text); + Assert.AreEqual(6, words[1].Offset); + + Assert.IsTrue(transcription.Participant is CommunicationIdentifier); + Assert.AreEqual("abc12345", transcription.Participant.RawId); + Console.WriteLine(transcription.ResultStatus.ToString()); + Assert.AreEqual(ResultStatus.Final, transcription.ResultStatus); + } + } +}