Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected async onRecognize(context: TurnContext, state: any, options: PromptOptions): Promise> {
const result: PromptRecognizerResult = { succeeded: false };
const activity: Activity = context.activity;
const utterance: string = activity.text;
const culture: string = this.determineCulture(context.activity);
const results: any = Recognizers.recognizeBoolean(utterance, culture);
if (results.length > 0 && results[0].resolution) {
result.succeeded = true;
result.value = results[0].resolution.value;
} else {
// If the prompt text was sent to the user with numbers, the prompt should recognize number choices.
const choiceOptions = this.choiceOptions || this.choiceDefaults[culture].options;
if (typeof choiceOptions.includeNumbers !== 'boolean' || choiceOptions.includeNumbers) {
const confirmChoices = this.confirmChoices || this.choiceDefaults[culture].choices;
const choices = [confirmChoices[0], confirmChoices[1]];
const secondOrMoreAttemptResults = recognizeChoices(utterance, choices);
if (secondOrMoreAttemptResults.length > 0) {
result.succeeded = true;
result.value = secondOrMoreAttemptResults[0].resolution.index === 0;
}
}
recognize: function recognize(context) {
const request = context.activity || {};
const utterance = request.text || '';
const locale = request.locale || defaultLocale || 'en-us';
const results = Recognizers.recognizeBoolean(utterance, locale);
const value = results.length > 0 && results[0].resolution ? results[0].resolution.value : undefined;
return Promise.resolve(validator ? validator(context, value) : value as any);
}
};
recognize: function recognize(context) {
const request = context.activity || {};
const utterance = request.text || '';
const locale = request.locale || defaultLocale || 'en-us';
const results = Recognizers.recognizeBoolean(utterance, locale);
const value = results.length > 0 && results[0].resolution ? results[0].resolution.value : undefined;
return Promise.resolve(validator ? validator(context, value) : value);
}
};
return __awaiter(this, void 0, void 0, function* () {
const result = { succeeded: false };
const activity = context.activity;
const utterance = activity.text;
const locale = activity.locale || this.defaultLocale || 'en-us';
const results = Recognizers.recognizeBoolean(utterance, locale);
if (results.length > 0 && results[0].resolution) {
result.succeeded = true;
result.value = results[0].resolution.value;
}
return result;
});
}