From fe8865250463cb0a1af551d66faedd13ff4c7324 Mon Sep 17 00:00:00 2001 From: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com> Date: Wed, 4 Jan 2023 16:36:26 -0300 Subject: [PATCH] port: [#4369] Prompt validation of confirm prompt in chatbot is not working for newly added language (#6554) (#4388) * Add recognizeLanguage property in PromptOptions interface * api file updated Co-authored-by: Emiliano Quiroga --- .../etc/botbuilder-dialogs.api.md | 1 + .../src/prompts/confirmPrompt.ts | 2 +- .../botbuilder-dialogs/src/prompts/prompt.ts | 5 +++ .../tests/confirmPrompt.test.js | 37 +++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/libraries/botbuilder-dialogs/etc/botbuilder-dialogs.api.md b/libraries/botbuilder-dialogs/etc/botbuilder-dialogs.api.md index fa60608c14..98c4cadac0 100644 --- a/libraries/botbuilder-dialogs/etc/botbuilder-dialogs.api.md +++ b/libraries/botbuilder-dialogs/etc/botbuilder-dialogs.api.md @@ -661,6 +661,7 @@ export class PromptCultureModels { export interface PromptOptions { choices?: (string | Choice)[]; prompt?: string | Partial; + recognizeLanguage?: string; retryPrompt?: string | Partial; style?: ListStyle; validations?: object; diff --git a/libraries/botbuilder-dialogs/src/prompts/confirmPrompt.ts b/libraries/botbuilder-dialogs/src/prompts/confirmPrompt.ts index 02c98cd84d..79ff6d6fc4 100644 --- a/libraries/botbuilder-dialogs/src/prompts/confirmPrompt.ts +++ b/libraries/botbuilder-dialogs/src/prompts/confirmPrompt.ts @@ -147,7 +147,7 @@ export class ConfirmPrompt extends Prompt { return result; } const culture = this.determineCulture(context.activity); - const results = Recognizers.recognizeBoolean(utterance, culture); + const results = Recognizers.recognizeBoolean(utterance, _options.recognizeLanguage ?? culture); if (results.length > 0 && results[0].resolution) { result.succeeded = true; result.value = results[0].resolution.value; diff --git a/libraries/botbuilder-dialogs/src/prompts/prompt.ts b/libraries/botbuilder-dialogs/src/prompts/prompt.ts index 4633b92819..d8a276a7fe 100644 --- a/libraries/botbuilder-dialogs/src/prompts/prompt.ts +++ b/libraries/botbuilder-dialogs/src/prompts/prompt.ts @@ -75,6 +75,11 @@ export interface PromptOptions { * (Optional) Additional validation rules to pass the prompts validator routine. */ validations?: object; + + /** + * The locale to be use for recognizing the utterance. + */ + recognizeLanguage?: string; } /** diff --git a/libraries/botbuilder-dialogs/tests/confirmPrompt.test.js b/libraries/botbuilder-dialogs/tests/confirmPrompt.test.js index 4a0d2833bf..90655b9c62 100644 --- a/libraries/botbuilder-dialogs/tests/confirmPrompt.test.js +++ b/libraries/botbuilder-dialogs/tests/confirmPrompt.test.js @@ -742,6 +742,43 @@ describe('ConfirmPrompt', function () { .startTest(); }); + it('should accept and recognize other languages', async function () { + const adapter = new TestAdapter(async (turnContext) => { + const dc = await dialogs.createContext(turnContext); + + const results = await dc.continueDialog(); + if (results.status === DialogTurnStatus.empty) { + await dc.prompt('prompt', { + prompt: { text: 'Please confirm.', type: ActivityTypes.Message }, + retryPrompt: { + text: 'Please confirm, say "yes" or "no" or something like that.', + type: ActivityTypes.Message, + }, + recognizeLanguage: 'es-es', + }); + } else if (results.status === DialogTurnStatus.complete) { + await turnContext.sendActivity(`The result found is '${results.result}'.`); + } + await convoState.saveChanges(turnContext); + }); + + const convoState = new ConversationState(new MemoryStorage()); + + const dialogState = convoState.createProperty('dialogState'); + const dialogs = new DialogSet(dialogState); + + const prompt = new ConfirmPrompt('prompt'); + prompt.choiceOptions = { includeNumbers: false }; + dialogs.add(prompt); + + await adapter + .send('Hola') + .assertReply('Please confirm. Yes or No') + .send('Si') + .assertReply("The result found is 'true'.") + .startTest(); + }); + it('should not recognize invalid number when choiceOptions.includeNumbers is true.', async function () { const adapter = new TestAdapter(async (turnContext) => { const dc = await dialogs.createContext(turnContext);