44from typing import Dict
55from botbuilder .core .turn_context import TurnContext
66from botbuilder .schema import (ActivityTypes , Activity )
7- from .datetime_resolution import DateTimeResolution
87from .prompt import Prompt
98from .prompt_options import PromptOptions
109from .prompt_recognizer_result import PromptRecognizerResult
11-
10+ from recognizers_number import recognize_number
1211
1312class 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