async def on_recognize(self, turn_context: TurnContext,
                           state: Dict[str, object],
                           options: PromptOptions) -> PromptRecognizerResult:
        if not turn_context:
            raise TypeError(
                'ChoicePrompt.on_recognize(): turn_context cannot be None.')

        choices: List[Choice] = options.choices if (
            options and options.choices) else []
        result: PromptRecognizerResult = PromptRecognizerResult()

        if turn_context.activity.type == ActivityTypes.message:
            activity: Activity = turn_context.activity
            utterance: str = activity.text
            opt: FindChoicesOptions = self.recognizer_options if self.recognizer_options else FindChoicesOptions(
            )
            opt.locale = activity.locale if activity.locale else (
                self.default_locale or Culture.English)
            results = ChoiceRecognizers.recognize_choices(
                utterance, choices, opt)

            if results is not None and len(results) > 0:
                result.succeeded = True
                result.value = results[0].resolution

        return result
 def test_should_find_multiple_choices_in_an_utterance_by_numerical_index(
         self):
     found = ChoiceRecognizers.recognize_choices("option one and 3.",
                                                 _color_choices)
     assert len(found) == 2
     assert_choice(found[0], "red", 0, 1.0)
     assert_choice(found[1], "blue", 2, 1.0)
 def test_should_find_multiple_choices_in_an_utterance_by_ordinal_position(
         self):
     found = ChoiceRecognizers.recognize_choices(
         "the first and third one please", _color_choices)
     assert len(found) == 2
     assert_choice(found[0], "red", 0, 1.0)
     assert_choice(found[1], "blue", 2, 1.0)
    async def on_recognize(
        self,
        turn_context: TurnContext,
        state: Dict[str, object],
        options: PromptOptions,
    ) -> PromptRecognizerResult:
        if not turn_context:
            raise TypeError(
                "ChoicePrompt.on_recognize(): turn_context cannot be None.")

        choices: List[Choice] = options.choices if (
            options and options.choices) else []
        result: PromptRecognizerResult = PromptRecognizerResult()

        if turn_context.activity.type == ActivityTypes.message:
            activity: Activity = turn_context.activity
            utterance: str = activity.text
            if not utterance:
                return result
            opt: FindChoicesOptions = self.recognizer_options if self.recognizer_options else FindChoicesOptions(
            )
            opt.locale = self._determine_culture(turn_context.activity, opt)
            results = ChoiceRecognizers.recognize_choices(
                utterance, choices, opt)

            if results is not None and results:
                result.succeeded = True
                result.value = results[0].resolution

        return result
    async def on_recognize(
        self,
        turn_context: TurnContext,
        state: Dict[str, object],
        options: PromptOptions,
    ) -> PromptRecognizerResult:
        if not turn_context:
            raise TypeError(
                "ConfirmPrompt.on_prompt(): turn_context cannot be None.")

        result = PromptRecognizerResult()
        if turn_context.activity.type == ActivityTypes.message:
            # Recognize utterance
            utterance = turn_context.activity.text
            if not utterance:
                return result
            culture = self.determine_culture(turn_context.activity)
            results = recognize_boolean(utterance, culture)
            if results:
                first = results[0]
                if "value" in first.resolution:
                    result.succeeded = True
                    result.value = first.resolution["value"]
            else:
                # First check whether the prompt was sent to the user with numbers
                # if it was we should recognize numbers
                defaults = self.choice_defaults[culture]
                opts = (self.choice_options
                        if self.choice_options is not None else defaults[2])

                # This logic reflects the fact that IncludeNumbers is nullable and True is the default set in
                # Inline style
                if opts.include_numbers is None or opts.include_numbers:
                    # The text may be a number in which case we will interpret that as a choice.
                    confirm_choices = (self.confirm_choices
                                       if self.confirm_choices is not None else
                                       (defaults[0], defaults[1]))
                    choices = {confirm_choices[0], confirm_choices[1]}
                    second_attempt_results = ChoiceRecognizers.recognize_choices(
                        utterance, choices)
                    if second_attempt_results:
                        result.succeeded = True
                        result.value = second_attempt_results[
                            0].resolution.index == 0

        return result
 def test_should_accept_null_utterance_in_recognize_choices(self):
     found = ChoiceRecognizers.recognize_choices(None, _color_choices)
     assert not found
 def test_should_find_a_choice_in_an_utterance_by_numerical_index_text(
         self):
     found = ChoiceRecognizers.recognize_choices("one", _color_choices)
     assert len(found) == 1
     assert_result(found[0], 0, 2, "one")
     assert_choice(found[0], "red", 0, 1.0)
 def test_should_find_a_choice_in_an_utterance_by_ordinal_position(self):
     found = ChoiceRecognizers.recognize_choices("the first one please.",
                                                 _color_choices)
     assert len(found) == 1
     assert_result(found[0], 4, 8, "first")
     assert_choice(found[0], "red", 0, 1.0)
 def test_should_find_a_choice_in_an_utterance_by_name(self):
     found = ChoiceRecognizers.recognize_choices("the red one please.",
                                                 _color_choices)
     assert len(found) == 1
     assert_result(found[0], 4, 6, "red")
     assert_choice(found[0], "red", 0, 1.0, "red")
 def test_should_find_a_choice_in_an_utterance_by_numerical_index_digit(
         self):
     found = ChoiceRecognizers.recognize_choices('1', _color_choices)
     assert len(found) == 1
     assert_result(found[0], 0, 0, '1')
     assert_choice(found[0], 'red', 0, 1.0)