Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port: [#4369] Prompt validation of confirm prompt in chatbot is not working for newly added language (#6554) #4388

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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