Skip to content

Commit 1153812

Browse files
authored
callautomation private review internal revision (Azure#33600)
* callautomation private review internal revision 1. Add text source constructor 2. Add polymorphism to recognizecomplete event * typo fix of recognize event collect tone result
1 parent e04f2ee commit 1153812

32 files changed

+1442
-1347
lines changed

sdk/communication/Azure.Communication.CallAutomation/api/Azure.Communication.CallAutomation.netstandard2.0.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ public partial class CallTransferFailed : Azure.Communication.CallAutomation.Cal
324324
internal CallTransferFailed() { }
325325
public static Azure.Communication.CallAutomation.CallTransferFailed Deserialize(string content) { throw null; }
326326
}
327-
public partial class ChoiceResult
327+
public partial class ChoiceResult : Azure.Communication.CallAutomation.RecognizeResult
328328
{
329329
internal ChoiceResult() { }
330330
public string Label { get { throw null; } }
331331
public string RecognizedPhrase { get { throw null; } }
332332
}
333-
public partial class CollectTonesResult
333+
public partial class CollectTonesResult : Azure.Communication.CallAutomation.RecognizeResult
334334
{
335335
internal CollectTonesResult() { }
336336
public System.Collections.Generic.IReadOnlyList<Azure.Communication.CallAutomation.DtmfTone> Tones { get { throw null; } }
@@ -611,7 +611,7 @@ public RecognizeChoice(string label, System.Collections.Generic.IEnumerable<stri
611611
}
612612
public partial class RecognizeCompleted : Azure.Communication.CallAutomation.CallAutomationEventWithReasonCodeName
613613
{
614-
internal RecognizeCompleted() { }
614+
public RecognizeCompleted(string callConnectionId, string serverCallId, string correlationId, string operationContext, Azure.Communication.CallAutomation.ResultInformation resultInformation, Azure.Communication.CallAutomation.CallMediaRecognitionType recognitionType, Azure.Communication.CallAutomation.RecognizeResult recognizeResult) { }
615615
public Azure.Communication.CallAutomation.ChoiceResult ChoiceResult { get { throw null; } }
616616
public Azure.Communication.CallAutomation.CollectTonesResult CollectTonesResult { get { throw null; } }
617617
public Azure.Communication.CallAutomation.CallMediaRecognitionType RecognitionType { get { throw null; } set { } }
@@ -640,6 +640,10 @@ internal RecognizeFailed() { }
640640
public static bool operator !=(Azure.Communication.CallAutomation.RecognizeInputType left, Azure.Communication.CallAutomation.RecognizeInputType right) { throw null; }
641641
public override string ToString() { throw null; }
642642
}
643+
public abstract partial class RecognizeResult
644+
{
645+
protected RecognizeResult() { }
646+
}
643647
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
644648
public readonly partial struct RecordingChannel : System.IEquatable<Azure.Communication.CallAutomation.RecordingChannel>
645649
{
@@ -806,6 +810,8 @@ public StartRecordingOptions(Azure.Communication.CallAutomation.CallLocator call
806810
public partial class TextSource : Azure.Communication.CallAutomation.PlaySource
807811
{
808812
public TextSource(string text) { }
813+
public TextSource(string text, System.Globalization.CultureInfo sourceLocale, Azure.Communication.CallAutomation.GenderType gender) { }
814+
public TextSource(string text, string voiceName) { }
809815
public string SourceLocale { get { throw null; } set { } }
810816
public string Text { get { throw null; } }
811817
public Azure.Communication.CallAutomation.GenderType? VoiceGender { get { throw null; } set { } }

sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/ChoiceResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Azure.Communication.CallAutomation
88
{
99
[CodeGenModel("ChoiceResult", Usage = new string[] { "output" }, Formats = new string[] { "json" })]
10-
public partial class ChoiceResult
10+
public partial class ChoiceResult : RecognizeResult
1111
{
1212
}
1313
}

sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/CollectTonesResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Azure.Communication.CallAutomation
88
{
99
[CodeGenModel("CollectTonesResult", Usage = new string[] { "output" }, Formats = new string[] { "json" })]
10-
public partial class CollectTonesResult
10+
public partial class CollectTonesResult : RecognizeResult
1111
{
1212
/// <summary>
1313
/// The Tones colelcted.

sdk/communication/Azure.Communication.CallAutomation/src/Models/Events/RecognizeCompleted.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public partial class RecognizeCompleted : CallAutomationEventWithReasonCodeName
2121
/// In case of cancel operation the this field is not set and is returned empty
2222
/// </param>
2323
/// <param name="collectTonesResult"> Defines the result for RecognitionType = Dtmf. </param>
24-
/// <param name="choiceResult"> Defines the result for RecognitionType = Choice. </param>
24+
/// <param name="choiceResult"> Defines the result for RecognitionType = Choices. </param>
2525
internal RecognizeCompleted(string callConnectionId, string serverCallId, string correlationId, string operationContext, ResultInformation resultInformation, CallMediaRecognitionType recognitionType, CollectTonesResult collectTonesResult, ChoiceResult choiceResult)
2626
{
2727
CallConnectionId = callConnectionId;
@@ -32,7 +32,36 @@ internal RecognizeCompleted(string callConnectionId, string serverCallId, string
3232
RecognitionType = recognitionType;
3333
CollectTonesResult = collectTonesResult;
3434
ChoiceResult = choiceResult;
35+
}
36+
37+
/// <summary> Initializes a new instance of RecognizeCompleted. </summary>
38+
/// <param name="callConnectionId"> Call connection ID. </param>
39+
/// <param name="serverCallId"> Server call ID. </param>
40+
/// <param name="correlationId"> Correlation ID for event to call correlation. Also called ChainId for skype chain ID. </param>
41+
/// <param name="operationContext"> Used by customers when calling mid-call actions to correlate the request to the response event. </param>
42+
/// <param name="resultInformation"> Contains the resulting SIP code/sub-code and message from NGC services. </param>
43+
/// <param name="recognitionType">
44+
/// Determines the sub-type of the recognize operation.
45+
/// In case of cancel operation the this field is not set and is returned empty
46+
/// </param>
47+
/// <param name="recognizeResult"> Defines the result for RecognitionType = Dtmf. </param>
48+
public RecognizeCompleted(string callConnectionId, string serverCallId, string correlationId, string operationContext, ResultInformation resultInformation, CallMediaRecognitionType recognitionType, RecognizeResult recognizeResult)
49+
{
50+
CallConnectionId = callConnectionId;
51+
ServerCallId = serverCallId;
52+
CorrelationId = correlationId;
53+
OperationContext = operationContext;
54+
ResultInformation = resultInformation;
55+
RecognitionType = recognitionType;
3556
ReasonCode = new ReasonCode(resultInformation.SubCode.ToString());
57+
if (recognizeResult is CollectTonesResult collectTonesResult)
58+
{
59+
CollectTonesResult = collectTonesResult;
60+
}
61+
else if (recognizeResult is ChoiceResult choiceResult)
62+
{
63+
ChoiceResult = choiceResult;
64+
}
3665
}
3766

3867
/// <summary>
@@ -52,7 +81,30 @@ public static RecognizeCompleted Deserialize(string content)
5281
using var document = JsonDocument.Parse(content);
5382
JsonElement element = document.RootElement;
5483

55-
return DeserializeRecognizeCompleted(element);
84+
RecognizeCompleted parsedRecognizeCompleted = DeserializeRecognizeCompleted(element);
85+
86+
if (parsedRecognizeCompleted.RecognitionType == CallMediaRecognitionType.Dtmf)
87+
{
88+
return new RecognizeCompleted(parsedRecognizeCompleted.CallConnectionId,
89+
parsedRecognizeCompleted.ServerCallId,
90+
parsedRecognizeCompleted.CorrelationId,
91+
parsedRecognizeCompleted.OperationContext,
92+
parsedRecognizeCompleted.ResultInformation,
93+
parsedRecognizeCompleted.RecognitionType,
94+
parsedRecognizeCompleted.CollectTonesResult);
95+
}
96+
else if (parsedRecognizeCompleted.RecognitionType == CallMediaRecognitionType.Choices)
97+
{
98+
return new RecognizeCompleted(parsedRecognizeCompleted.CallConnectionId,
99+
parsedRecognizeCompleted.ServerCallId,
100+
parsedRecognizeCompleted.CorrelationId,
101+
parsedRecognizeCompleted.OperationContext,
102+
parsedRecognizeCompleted.ResultInformation,
103+
parsedRecognizeCompleted.RecognitionType,
104+
parsedRecognizeCompleted.ChoiceResult);
105+
}
106+
107+
return null;
56108
}
57109
}
58110
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
using System.Text.Json;
6+
7+
namespace Azure.Communication.CallAutomation
8+
{
9+
/// <summary>
10+
/// The Recognize result which could be tone or choice result.
11+
/// </summary>
12+
public abstract class RecognizeResult
13+
{
14+
}
15+
}

sdk/communication/Azure.Communication.CallAutomation/src/Models/TextSource.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Collections.Generic;
5+
using System.Globalization;
66
using Azure.Core;
77

88
namespace Azure.Communication.CallAutomation
@@ -20,6 +20,32 @@ public TextSource(string text)
2020
Text = text;
2121
}
2222

23+
/// <summary> Initializes a new instance of TextSource. </summary>
24+
/// <param name="text"> Text for the cognitive service to be played. </param>
25+
/// <param name="voiceName"> The voiceName of the audio. </param>
26+
/// <exception cref="ArgumentNullException"> <paramref name="text"/> is null. </exception>
27+
public TextSource(string text, string voiceName)
28+
{
29+
Argument.AssertNotNull(text, nameof(text));
30+
31+
Text = text;
32+
VoiceName = voiceName;
33+
}
34+
35+
/// <summary> Initializes a new instance of TextSource. </summary>
36+
/// <param name="text"> Text for the cognitive service to be played. </param>
37+
/// <param name="sourceLocale"> The culture info of the voice. </param>
38+
/// <param name="gender"> The gender of the voice. </param>
39+
/// <exception cref="ArgumentNullException"> <paramref name="text"/> is null. </exception>
40+
public TextSource(string text, CultureInfo sourceLocale, GenderType gender)
41+
{
42+
Argument.AssertNotNull(text, nameof(text));
43+
44+
Text = text;
45+
SourceLocale = sourceLocale.Name;
46+
VoiceGender = gender;
47+
}
48+
2349
/// <summary> Text for the cognitive service to be played. </summary>
2450
public string Text { get; }
2551
/// <summary> Source language locale to be played. </summary>

sdk/communication/Azure.Communication.CallAutomation/tests/CallMedias/CallMediaTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ public class CallMediaTests : CallAutomationTestBase
1818
new CommunicationUserIdentifier("id")
1919
};
2020
private static readonly FileSource _fileSource = new FileSource(new System.Uri("file://path/to/file"));
21-
private static readonly TextSource _textSource = new TextSource("PlayTTS test text.")
22-
{
23-
SourceLocale = "en-US",
24-
VoiceGender = GenderType.Female,
25-
VoiceName = "LULU"
26-
};
21+
private static readonly TextSource _textSource = new TextSource("PlayTTS test text.", "en-US-ElizabethNeural");
2722
private static readonly PlayOptions _options = new PlayOptions()
2823
{
2924
Loop = false,

sdk/communication/Azure.Communication.CallAutomation/tests/Events/CallAutomationEventParserTests.cs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Reflection.Emit;
77
using System.Text.Json;
8+
using System.Text.Json.Serialization;
89
using Azure.Messaging;
910
using Newtonsoft.Json.Linq;
1011
using NUnit.Framework;
@@ -500,14 +501,15 @@ public void PlayCanceledEventParsed_Test()
500501
[Test]
501502
public void RecognizeCompletedWithDtmfEventParsed_Test()
502503
{
504+
CollectTonesResult collectTonesResult = new CollectTonesResult(new DtmfTone[] { DtmfTone.Five });
503505
RecognizeCompleted @event = CallAutomationModelFactory.RecognizeCompleted(
504506
callConnectionId: "callConnectionId",
505507
serverCallId: "serverCallId",
506508
correlationId: "correlationId",
507509
operationContext: "operationContext",
508510
recognitionType: CallMediaRecognitionType.Dtmf,
509-
collectTonesResult: new CollectTonesResult(new DtmfTone[] { DtmfTone.Five }),
510-
choiceResult: new ChoiceResult("testLabel", "testRecognizePhrase"),
511+
collectTonesResult: collectTonesResult,
512+
choiceResult: new ChoiceResult(),
511513
resultInformation: new ResultInformation(
512514
code: 200,
513515
subCode: 8531,
@@ -530,48 +532,23 @@ public void RecognizeCompletedWithDtmfEventParsed_Test()
530532
}
531533
}
532534

533-
[Test]
534-
public void RecognizeFailedEventParsed_Test()
535-
{
536-
RecognizeFailed @event = CallAutomationModelFactory.RecognizeFailed(
537-
operationContext: "operationContext",
538-
resultInformation: new ResultInformation(code: 400, subCode: 8510, message: "Action failed, initial silence timeout reached."),
539-
callConnectionId: "callConnectionId",
540-
serverCallId: "serverCallId",
541-
correlationId: "correlationId");
542-
JsonSerializerOptions jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
543-
string jsonEvent = JsonSerializer.Serialize(@event, jsonOptions);
544-
var parsedEvent = CallAutomationEventParser.Parse(jsonEvent, "Microsoft.Communication.RecognizeFailed");
545-
if (parsedEvent is RecognizeFailed recognizeFailed)
546-
{
547-
Assert.AreEqual("correlationId", recognizeFailed.CorrelationId);
548-
Assert.AreEqual("serverCallId", recognizeFailed.ServerCallId);
549-
Assert.AreEqual(400, recognizeFailed.ResultInformation?.Code);
550-
Assert.AreEqual(ReasonCode.RecognizeInitialSilenceTimedOut, recognizeFailed.ReasonCode);
551-
}
552-
else
553-
{
554-
Assert.Fail("Event parsed wrongfully");
555-
}
556-
}
557-
558535
[Test]
559536
public void RecognizeCompletedWithChoiceEventParsed_Test()
560537
{
538+
ChoiceResult choiceResult = new ChoiceResult("testLabel", "testRecognizePhrase");
561539
RecognizeCompleted @event = CallAutomationModelFactory.RecognizeCompleted(
562540
callConnectionId: "callConnectionId",
563541
serverCallId: "serverCallId",
564542
correlationId: "correlationId",
565543
operationContext: "operationContext",
566544
recognitionType: CallMediaRecognitionType.Choices,
567-
collectTonesResult: new CollectTonesResult(new DtmfTone[] { DtmfTone.Five }),
568-
choiceResult: new ChoiceResult("testLabel", "testRecognizePhrase"),
545+
collectTonesResult: new CollectTonesResult(),
546+
choiceResult: choiceResult,
569547
resultInformation: new ResultInformation(
570548
code: 200,
571-
subCode: 8545,
572-
message: "Action completed, Recognized phrase matches a valid option."));
549+
subCode: 8531,
550+
message: "Action completed, max digits received"));
573551
JsonSerializerOptions jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
574-
575552
string jsonEvent = JsonSerializer.Serialize(@event, jsonOptions);
576553

577554
var parsedEvent = CallAutomationEventParser.Parse(jsonEvent, "Microsoft.Communication.RecognizeCompleted");
@@ -580,9 +557,33 @@ public void RecognizeCompletedWithChoiceEventParsed_Test()
580557
Assert.AreEqual("correlationId", recognizeCompleted.CorrelationId);
581558
Assert.AreEqual("serverCallId", recognizeCompleted.ServerCallId);
582559
Assert.AreEqual(200, recognizeCompleted.ResultInformation?.Code);
583-
Assert.NotZero(recognizeCompleted.CollectTonesResult.Tones.Count());
584560
Assert.AreEqual("testLabel", recognizeCompleted.ChoiceResult.Label);
585-
Assert.AreEqual(ReasonCode.RecognizeSpeechOptionMatched, recognizeCompleted.ReasonCode);
561+
Assert.AreEqual("testRecognizePhrase", recognizeCompleted.ChoiceResult.RecognizedPhrase);
562+
}
563+
else
564+
{
565+
Assert.Fail("Event parsed wrongfully");
566+
}
567+
}
568+
569+
[Test]
570+
public void RecognizeFailedEventParsed_Test()
571+
{
572+
RecognizeFailed @event = CallAutomationModelFactory.RecognizeFailed(
573+
operationContext: "operationContext",
574+
resultInformation: new ResultInformation(code: 400, subCode: 8510, message: "Action failed, initial silence timeout reached."),
575+
callConnectionId: "callConnectionId",
576+
serverCallId: "serverCallId",
577+
correlationId: "correlationId");
578+
JsonSerializerOptions jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
579+
string jsonEvent = JsonSerializer.Serialize(@event, jsonOptions);
580+
var parsedEvent = CallAutomationEventParser.Parse(jsonEvent, "Microsoft.Communication.RecognizeFailed");
581+
if (parsedEvent is RecognizeFailed recognizeFailed)
582+
{
583+
Assert.AreEqual("correlationId", recognizeFailed.CorrelationId);
584+
Assert.AreEqual("serverCallId", recognizeFailed.ServerCallId);
585+
Assert.AreEqual(400, recognizeFailed.ResultInformation?.Code);
586+
Assert.AreEqual(ReasonCode.RecognizeInitialSilenceTimedOut, recognizeFailed.ReasonCode);
586587
}
587588
else
588589
{

0 commit comments

Comments
 (0)