How to use @microsoft/recognizers-text-choice - 4 common examples

To help you get started, we’ve selected a few @microsoft/recognizers-text-choice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / botbuilder-js / libraries / botbuilder-dialogs / src / prompts / confirmPrompt.ts View on Github external
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;
                }
            }
github microsoft / botbuilder-js / libraries / botbuilder-prompts / src / confirmPrompt.ts View on Github external
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);
        }
    };
github microsoft / botbuilder-js / libraries / botbuilder-prompts / lib / confirmPrompt.js View on Github external
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);
        }
    };
github microsoft / botbuilder-js / libraries / botbuilder-dialogs / lib / prompts / confirmPrompt.js View on Github external
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;
        });
    }

@microsoft/recognizers-text-choice

recognizers-text-choice provides recognition of Boolean (yes/no) answers expressed in multiple languages, as well as base classes to support lists of alternative choices.

MIT
Latest version published 1 year ago

Package Health Score

79 / 100
Full package analysis

Popular @microsoft/recognizers-text-choice functions