Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 614b016

Browse files
committed
removed prompt circular dependency
1 parent 0c54263 commit 614b016

File tree

4 files changed

+96
-5
lines changed

4 files changed

+96
-5
lines changed

libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from .activity_prompt import ActivityPrompt
99
from .attachment_prompt import AttachmentPrompt
10+
from .choice_prompt import ChoicePrompt
1011
from .confirm_prompt import ConfirmPrompt
1112
from .datetime_prompt import DateTimePrompt
1213
from .datetime_resolution import DateTimeResolution
@@ -21,6 +22,7 @@
2122
__all__ = [
2223
"ActivityPrompt",
2324
"AttachmentPrompt",
25+
"ChoicePrompt",
2426
"ConfirmPrompt",
2527
"DateTimePrompt",
2628
"DateTimeResolution",

libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/choice_prompt.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66

77
from botbuilder.core import TurnContext
88
from botbuilder.dialogs.choices import Choice, ChoiceFactory, ChoiceFactoryOptions, ChoiceRecognizers, FindChoicesOptions, ListStyle
9-
from botbuilder.dialogs.prompts import Prompt, PromptOptions, PromptValidatorContext, PromptRecognizerResult
109
from botbuilder.schema import Activity, ActivityTypes
1110

11+
from .prompt import Prompt
12+
from .prompt_options import PromptOptions
13+
from .prompt_validator_context import PromptValidatorContext
14+
from .prompt_recognizer_result import PromptRecognizerResult
15+
1216
class ChoicePrompt(Prompt):
1317
"""
14-
Prompts a user to select froma list of choices.
18+
Prompts a user to select from a list of choices.
1519
1620
By default the prompt will return to the calling dialog a `FoundChoice` object containing the choice that was selected.
1721
"""
@@ -20,7 +24,7 @@ class ChoicePrompt(Prompt):
2024
Culture.Dutch: ChoiceFactoryOptions(inline_separator = ', ', inline_or = ' of ', include_numbers = True),
2125
Culture.English: ChoiceFactoryOptions(inline_separator = ', ', inline_or = ' or ', include_numbers = True),
2226
Culture.French: ChoiceFactoryOptions(inline_separator = ', ', inline_or = ' ou ', include_numbers = True),
23-
Culture.German: ChoiceFactoryOptions(inline_separator = ', ', inline_or = ' oder ', include_numbers = True),
27+
'de-de': ChoiceFactoryOptions(inline_separator = ', ', inline_or = ' oder ', include_numbers = True),
2428
Culture.Japanese: ChoiceFactoryOptions(inline_separator = '、 ', inline_or = ' または ', include_numbers = True),
2529
Culture.Portuguese: ChoiceFactoryOptions(inline_separator = ', ', inline_or = ' ou ', include_numbers = True),
2630
Culture.Chinese: ChoiceFactoryOptions(inline_separator = ', ', inline_or = ' 要么 ', include_numbers = True),
@@ -93,7 +97,7 @@ async def on_recognize(
9397
if not turn_context:
9498
raise TypeError('ChoicePrompt.on_recognize(): turn_context cannot be None.')
9599

96-
choices: List[Choice] = options.choices if options.choices else []
100+
choices: List[Choice] = options.choices if (options and options.choices) else []
97101
result: PromptRecognizerResult = PromptRecognizerResult()
98102

99103
if turn_context.activity.type == ActivityTypes.message:
@@ -107,4 +111,5 @@ async def on_recognize(
107111
result.succeeded = True
108112
result.value = results[0].resolution
109113

110-
return result
114+
return result
115+

libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/prompt.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ async def on_recognize(self, turn_context: TurnContext, state: Dict[str, object]
119119
# TODO: Fix style to use ListStyle when ported.
120120
# TODO: Fix options to use ChoiceFactoryOptions object when ported.
121121
def append_choices(self, prompt: Activity, channel_id: str, choices: object, style: object, options : object = None ) -> Activity:
122+
"""
123+
Helper function to compose an output activity containing a set of choices.
124+
125+
Parameters:
126+
-----------
127+
128+
prompt: The prompt to append the user's choice to.
129+
130+
channel_id: ID of the channel the prompt is being sent to.
131+
132+
choices: List of choices to append.
133+
134+
style: Configured style for the list of choices.
135+
136+
options: (Optional) options to configure the underlying `ChoiceFactory` call.
137+
"""
122138
# Get base prompt text (if any)
123139
text = prompt.text if prompt != None and not prompt.text == False else ''
124140

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from typing import List
5+
6+
import aiounittest
7+
8+
from botbuilder.core import ConversationState, MemoryStorage
9+
from botbuilder.dialogs.choices import Choice
10+
from botbuilder.dialogs.prompts import ChoicePrompt
11+
12+
_color_choices: List[Choice] = [
13+
Choice(value='red'),
14+
Choice(value='green'),
15+
Choice(value='blue')
16+
]
17+
18+
class ChoicePromptTest(aiounittest.AsyncTestCase):
19+
20+
def test_choice_prompt_with_empty_id_should_fail(self):
21+
empty_id = ''
22+
23+
with self.assertRaises(TypeError):
24+
ChoicePrompt(empty_id)
25+
26+
def test_choice_prompt_with_none_id_should_fail(self):
27+
none_id = None
28+
29+
with self.assertRaises(TypeError):
30+
ChoicePrompt(none_id)
31+
32+
async def test_choice_prompt_with_card_action_and_no_value_should_not_fail(self):
33+
# convo_state = ConversationState(MemoryStorage())
34+
# dialog_state = convo_state.create_property('dialogState')
35+
pass
36+
37+
async def test_should_send_prompt(self):
38+
pass
39+
40+
async def test_should_send_prompt_as_an_inline_list(self):
41+
pass
42+
43+
async def test_should_send_prompt_as_a_numbered_list(self):
44+
pass
45+
46+
async def test_should_send_prompt_using_suggested_actions(self):
47+
pass
48+
49+
async def test_should_send_prompt_using_hero_card(self):
50+
pass
51+
52+
async def test_should_send_prompt_without_adding_a_list(self):
53+
pass
54+
55+
async def test_should_send_prompt_without_adding_a_list_but_adding_ssml(self):
56+
pass
57+
58+
async def test_should_recognize_a_choice(self):
59+
pass
60+
61+
async def test_shold_not_recognize_other_text(self):
62+
pass
63+
64+
async def test_should_call_custom_validator(self):
65+
pass
66+
67+
async def test_should_use_choice_style_if_present(self):
68+
pass

0 commit comments

Comments
 (0)