Skip to content

Commit

Permalink
port: [#4369] Prompt validation of confirm prompt in chatbot is not w…
Browse files Browse the repository at this point in the history
…orking for newly added language (#6554) (#4388)

* Add recognizeLanguage property in PromptOptions interface

* api file updated

Co-authored-by: Emiliano Quiroga <[email protected]>
  • Loading branch information
ceciliaavila and Emiliano Quiroga authored Jan 4, 2023
1 parent 7e87ca0 commit fe88652
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions libraries/botbuilder-dialogs/etc/botbuilder-dialogs.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ export class PromptCultureModels {
export interface PromptOptions {
choices?: (string | Choice)[];
prompt?: string | Partial<Activity>;
recognizeLanguage?: string;
retryPrompt?: string | Partial<Activity>;
style?: ListStyle;
validations?: object;
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-dialogs/src/prompts/confirmPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class ConfirmPrompt extends Prompt<boolean> {
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;
Expand Down
5 changes: 5 additions & 0 deletions libraries/botbuilder-dialogs/src/prompts/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
37 changes: 37 additions & 0 deletions libraries/botbuilder-dialogs/tests/confirmPrompt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fe88652

Please sign in to comment.