Skip to content

Commit 70fdc22

Browse files
committed
Minor fixes on number_prompt
1 parent b4708f9 commit 70fdc22

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .prompt import Prompt
99
from .prompt_options import PromptOptions
1010
from .prompt_recognizer_result import PromptRecognizerResult
11+
from recognizers_date_time import recognize_datetime
1112

1213
class DateTimePrompt(Prompt):
1314
def __init__(self, dialog_id: str, validator: object = None, default_locale: str = None):
@@ -48,10 +49,9 @@ async def on_recognize(self, turn_context: TurnContext, state: Dict[str, object]
4849
if turn_context.activity.type == ActivityTypes.message:
4950
# Recognize utterance
5051
message = turn_context.activity
51-
# TODO: English contsant needs to be ported.
52+
# TODO: English constant needs to be ported.
5253
culture = message.locale if message.locale != None else "English"
53-
# TODO: Move this import to top of file when recognizers package is published
54-
from recognizers_date_time import recognize_datetime
54+
5555
results = recognize_datetime(message.text, culture)
5656
if len(results) > 0:
5757
result.succeeded = True

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,57 @@
44
from typing import Dict
55
from botbuilder.core.turn_context import TurnContext
66
from botbuilder.schema import (ActivityTypes, Activity)
7-
from .datetime_resolution import DateTimeResolution
87
from .prompt import Prompt
98
from .prompt_options import PromptOptions
109
from .prompt_recognizer_result import PromptRecognizerResult
11-
10+
from recognizers_number import recognize_number
1211

1312
class NumberPrompt(Prompt):
1413
# TODO: PromptValidator
1514
def __init__(self, dialog_id: str, validator: object, default_locale: str):
16-
super(ConfirmPrompt, self).__init__(dialog_id, validator)
15+
super(NumberPrompt, self).__init__(dialog_id, validator)
1716
self._default_locale = default_locale
18-
17+
1918
@property
2019
def default_locale(self) -> str:
21-
"""Gets the locale used if `TurnContext.activity.locale` is not specified.
20+
"""Gets the locale used if `TurnContext.activity.locale` is not specified.
2221
"""
2322
return self._default_locale
24-
23+
2524
@default_locale.setter
2625
def default_locale(self, value: str) -> None:
2726
"""Gets the locale used if `TurnContext.activity.locale` is not specified.
2827
2928
:param value: The locale used if `TurnContext.activity.locale` is not specified.
3029
"""
3130
self._default_locale = value
32-
3331

3432
async def on_prompt(self, turn_context: TurnContext, state: Dict[str, object], options: PromptOptions, is_retry: bool):
3533
if not turn_context:
3634
raise TypeError('NumberPrompt.on_prompt(): turn_context cannot be None.')
3735
if not options:
3836
raise TypeError('NumberPrompt.on_prompt(): options cannot be None.')
39-
37+
4038
if is_retry == True and options.retry_prompt != None:
41-
prompt = turn_context.send_activity(options.retry_prompt)
39+
prompt = turn_context.send_activity(options.retry_prompt)
4240
else:
4341
if options.prompt != None:
44-
turn_context.send_activity(options.prompt)
45-
42+
await turn_context.send_activity(options.prompt)
4643

4744
async def on_recognize(self, turn_context: TurnContext, state: Dict[str, object], options: PromptOptions) -> PromptRecognizerResult:
4845
if not turn_context:
4946
raise TypeError('NumberPrompt.on_recognize(): turn_context cannot be None.')
50-
47+
5148
result = PromptRecognizerResult()
5249
if turn_context.activity.type == ActivityTypes.message:
5350
message = turn_context.activity
54-
51+
5552
# TODO: Fix constant English with correct constant from text recognizer
5653
culture = turn_context.activity.locale if turn_context.activity.locale != None else 'English'
57-
# TODO: Port ChoiceRecognizer
58-
results = ChoiceRecognizer.recognize_number(message.text, culture)
59-
if results.Count > 0:
54+
55+
results = recognize_number(message.text, culture)
56+
if len(results) > 0:
6057
result.succeeded = True
6158
result.value = results[0].resolution["value"]
62-
63-
return result
59+
60+
return result

0 commit comments

Comments
 (0)