Add RecognizeLanguage property in PromptOptions class (#6554)
This commit is contained in:
Родитель
a057f9c2d3
Коммит
55eb4f1dba
|
@ -189,7 +189,8 @@ namespace Microsoft.Bot.Builder.Dialogs
|
|||
}
|
||||
|
||||
var culture = DetermineCulture(turnContext.Activity);
|
||||
var results = ChoiceRecognizer.RecognizeBoolean(utterance, culture);
|
||||
|
||||
var results = ChoiceRecognizer.RecognizeBoolean(utterance, options.RecognizeLanguage ?? culture);
|
||||
if (results.Count > 0)
|
||||
{
|
||||
var first = results[0];
|
||||
|
|
|
@ -51,5 +51,15 @@ namespace Microsoft.Bot.Builder.Dialogs
|
|||
/// </summary>
|
||||
/// <value>Additional options for use with a prompt validator.</value>
|
||||
public object Validations { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the locale used for recognizing the user's choice.
|
||||
/// </summary>
|
||||
/// <value>The locale to be use for recognizing the utterance.</value>
|
||||
/// <remarks>
|
||||
/// When using a translator middleware, the user's choice is translated and it doesn't match the prompt's options.
|
||||
/// Setting this property with the translator's target language allows the prompt to recognize the utterance.
|
||||
/// </remarks>
|
||||
public string RecognizeLanguage { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -352,6 +352,63 @@ namespace Microsoft.Bot.Builder.Dialogs.Tests
|
|||
.StartTestAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConfirmPromptDifferentRecognizeLanguage()
|
||||
{
|
||||
var convoState = new ConversationState(new MemoryStorage());
|
||||
var dialogState = convoState.CreateProperty<DialogState>("dialogState");
|
||||
|
||||
var adapter = new TestAdapter(TestAdapter.CreateConversation(nameof(ConfirmPromptDifferentRecognizeLanguage)))
|
||||
.Use(new AutoSaveStateMiddleware(convoState))
|
||||
.Use(new TranscriptLoggerMiddleware(new TraceTranscriptLogger(traceActivity: false)));
|
||||
|
||||
var dialogs = new DialogSet(dialogState);
|
||||
var prompt = new ConfirmPrompt("ConfirmPrompt", defaultLocale: Culture.English);
|
||||
|
||||
dialogs.Add(prompt);
|
||||
|
||||
await new TestFlow(adapter, async (turnContext, cancellationToken) =>
|
||||
{
|
||||
var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken);
|
||||
|
||||
var results = await dc.ContinueDialogAsync(cancellationToken);
|
||||
if (results.Status == DialogTurnStatus.Empty)
|
||||
{
|
||||
var options = new PromptOptions
|
||||
{
|
||||
Prompt = new Activity
|
||||
{
|
||||
Type = ActivityTypes.Message,
|
||||
Text = "Please confirm.",
|
||||
},
|
||||
RetryPrompt = new Activity
|
||||
{
|
||||
Type = ActivityTypes.Message,
|
||||
Text = "Please confirm, say 'yes' or 'no' or something like that.",
|
||||
},
|
||||
RecognizeLanguage = "es-es"
|
||||
};
|
||||
await dc.PromptAsync("ConfirmPrompt", options, cancellationToken);
|
||||
}
|
||||
else if (results.Status == DialogTurnStatus.Complete)
|
||||
{
|
||||
if ((bool)results.Result)
|
||||
{
|
||||
await turnContext.SendActivityAsync(MessageFactory.Text("Confirmed."), cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
await turnContext.SendActivityAsync(MessageFactory.Text("Not confirmed."), cancellationToken);
|
||||
}
|
||||
}
|
||||
})
|
||||
.Send("hola")
|
||||
.AssertReply("Please confirm. (1) Yes or (2) No")
|
||||
.Send("si")
|
||||
.AssertReply("Confirmed.")
|
||||
.StartTestAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldUsePromptClassStyleProperty()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче