2323
2424
2525class Prompt (Dialog ):
26- """ Base class for all prompts."""
27-
26+ """ Prompts base class
27+ Defines the core behavior of prompt dialogs. Extends `Dialog` base class.
28+
29+ .. remarks::
30+ When the prompt ends, it should return an object that represents the
31+ value that was prompted for.
32+ Use `DialogSet.Add(Dialog)` or `ComponentDialog.AddDialog(Dialog)` to add a prompt
33+ to a dialog set or component dialog, respectively.
34+ Use `DialogContext.PromptAsync(string, PromptOptions, CancellationToken)` or
35+ `DialogContext.BeginDialogAsync(string, object, CancellationToken)` to start the prompt.
36+ If you start a prompt from a `WaterfallStep` in a `WaterfallDialog`, then the prompt
37+ result will be available in the next step of the waterfall.
38+ """
2839 ATTEMPT_COUNT_KEY = "AttemptCount"
2940 persisted_options = "options"
3041 persisted_state = "state"
3142
3243 def __init__ (self , dialog_id : str , validator : object = None ):
33- """Creates a new Prompt instance.
34- Parameters
35- ----------
36- dialog_id
37- Unique ID of the prompt within its parent `DialogSet` or
38- `ComponentDialog`.
39- validator
40- (Optional) custom validator used to provide additional validation and
41- re-prompting logic for the prompt.
44+ """Creates a new Prompt instance
45+ :param dialog_id: Unique ID of the prompt within its parent :class:DialogSet or
46+ :class:ComponentDialog.
47+ :type dialog_id: str
48+ :param validator: Optional custom validator used to provide additional validation and re-prompting logic for the prompt.
49+ :type validator: object
4250 """
4351 super (Prompt , self ).__init__ (dialog_id )
4452
@@ -47,6 +55,20 @@ def __init__(self, dialog_id: str, validator: object = None):
4755 async def begin_dialog (
4856 self , dialog_context : DialogContext , options : object = None
4957 ) -> DialogTurnResult :
58+ """ Starts a prompt dialog.
59+ Called when a prompt dialog is pushed onto the dialog stack and is being activated.
60+
61+ :param dialog_context: The dialog context for the current turn of the conversation.
62+ :type dialog_context: :class:DialogContext
63+ :param options: Optional, additional information to pass to the prompt being started.
64+ :type options: object
65+ :return: A :class:Task representing the asynchronous operation.
66+ :rtype: :class:Task
67+
68+ .. remarks::
69+ If the task is successful, the result indicates whether the prompt is still active
70+ after the turn has been processed by the prompt.
71+ """
5072 if not dialog_context :
5173 raise TypeError ("Prompt(): dc cannot be None." )
5274 if not isinstance (options , PromptOptions ):
@@ -74,6 +96,21 @@ async def begin_dialog(
7496 return Dialog .end_of_turn
7597
7698 async def continue_dialog (self , dialog_context : DialogContext ):
99+ """ Continues a dialog.
100+ Called when a prompt dialog is the active dialog and the user replied with a new activity.
101+
102+ :param dialog_context: The dialog context for the current turn of the conversation.
103+ :type dialog_context: :class:DialogContext
104+
105+ :return: A :class:Task representing the asynchronous operation.
106+ :rtype: :class:Task
107+
108+ .. remarks::
109+ If the task is successful, the result indicates whether the dialog is still
110+ active after the turn has been processed by the dialog.
111+ The prompt generally continues to receive the user's replies until it accepts the
112+ user's reply as valid input for the prompt.
113+ """
77114 if not dialog_context :
78115 raise TypeError ("Prompt(): dc cannot be None." )
79116
@@ -111,15 +148,42 @@ async def continue_dialog(self, dialog_context: DialogContext):
111148 async def resume_dialog (
112149 self , dialog_context : DialogContext , reason : DialogReason , result : object
113150 ) -> DialogTurnResult :
114- # Prompts are typically leaf nodes on the stack but the dev is free to push other dialogs
115- # on top of the stack which will result in the prompt receiving an unexpected call to
116- # dialog_resume() when the pushed on dialog ends.
117- # To avoid the prompt prematurely ending we need to implement this method and
118- # simply re-prompt the user.
151+ """ Resumes a dialog.
152+ Called when a prompt dialog resumes being the active dialog on the dialog stack, such as
153+ when the previous active dialog on the stack completes.
154+
155+ :param dialog_context: The dialog context for the current turn of the conversation.
156+ :type dialog_context: :class:DialogContext
157+ :param reason: An enum indicating why the dialog resumed.
158+ :type reason: :class:DialogReason
159+ :param result: Optional, value returned from the previous dialog on the stack.
160+ The type of the value returned is dependent on the previous dialog.
161+ :type result: object
162+ :return: A :class:Task representing the asynchronous operation.
163+ :rtype: :class:Task
164+
165+ .. remarks::
166+ If the task is successful, the result indicates whether the dialog is still
167+ active after the turn has been processed by the dialog.
168+ Prompts are typically leaf nodes on the stack but the dev is free to push other dialogs
169+ on top of the stack which will result in the prompt receiving an unexpected call to
170+ :meth:resume_dialog() when the pushed on dialog ends.
171+ To avoid the prompt prematurely ending we need to simply re-prompt the user.
172+ """
119173 await self .reprompt_dialog (dialog_context .context , dialog_context .active_dialog )
120174 return Dialog .end_of_turn
121175
122176 async def reprompt_dialog (self , context : TurnContext , instance : DialogInstance ):
177+ """ Reprompts user for input.
178+ Called when a prompt dialog has been requested to reprompt the user for input.
179+
180+ :param context: Context for the current turn of conversation with the user.
181+ :type context: :class:TurnContext
182+ :param instance: The instance of the dialog on the stack.
183+ :type instance: :class:DialogInstance
184+ :return: A :class:Task representing the asynchronous operation.
185+ :rtype: :class:Task
186+ """
123187 state = instance .state [self .persisted_state ]
124188 options = instance .state [self .persisted_options ]
125189 await self .on_prompt (context , state , options , False )
@@ -132,6 +196,23 @@ async def on_prompt(
132196 options : PromptOptions ,
133197 is_retry : bool ,
134198 ):
199+ """ Prompts user for input.
200+ When overridden in a derived class, prompts the user for input.
201+
202+ :param turn_context: Context for the current turn of conversation with the user.
203+ :type turn_context: :class:TurnContext
204+ :param state: Contains state for the current instance of the prompt on the dialog stack.
205+ :type state: :class:Dict
206+ :param options: A prompt options object constructed from the options initially provided
207+ in the call :meth:DialogContext.PromptAsync(string, PromptOptions, CancellationToken).
208+ :type options: :class:PromptOptions
209+ :param is_retry: true if this is the first time this prompt dialog instance on the stack is prompting
210+ the user for input; otherwise, false.
211+ :type is_retry: bool
212+
213+ :return: A :class:Task representing the asynchronous operation.
214+ :rtype: :class:Task
215+ """
135216 pass
136217
137218 @abstractmethod
@@ -141,6 +222,20 @@ async def on_recognize(
141222 state : Dict [str , object ],
142223 options : PromptOptions ,
143224 ):
225+ """ Recognizes the user's input.
226+ When overridden in a derived class, attempts to recognize the user's input.
227+
228+ :param turn_context: Context for the current turn of conversation with the user.
229+ :type turn_context: :class:TurnContext
230+ :param state: Contains state for the current instance of the prompt on the dialog stack.
231+ :type state: :class:Dict
232+ :param options: A prompt options object constructed from the options initially provided
233+ in the call :meth:DialogContext.PromptAsync(string, PromptOptions, CancellationToken).
234+ :type options: :class:PromptOptions
235+
236+ :return: A :class:Task representing the asynchronous operation.
237+ :rtype: :class:Task
238+ """
144239 pass
145240
146241 def append_choices (
@@ -151,20 +246,25 @@ def append_choices(
151246 style : ListStyle ,
152247 options : ChoiceFactoryOptions = None ,
153248 ) -> Activity :
154- """
249+ """ Composes an output activity containing a set of choices.
250+ When overridden in a derived class, appends choices to the activity when the user is prompted for input.
155251 Helper function to compose an output activity containing a set of choices.
156252
157- Parameters:
158- -----------
159- prompt: The prompt to append the user's choice to.
160-
161- channel_id: ID of the channel the prompt is being sent to.
162-
163- choices: List of choices to append.
164-
165- style: Configured style for the list of choices.
166-
167- options: (Optional) options to configure the underlying `ChoiceFactory` call.
253+ :param prompt: The prompt to append the user's choice to.
254+ :type prompt:
255+ :param channel_id: ID of the channel the prompt is being sent to.
256+ :type channel_id: str
257+ :param: choices: List of choices to append.
258+ :type choices: :class:List
259+ :param: style: Configured style for the list of choices.
260+ :type style: :class:ListStyle
261+ :param: options: Optional formatting options to use when presenting the choices.
262+ :type style: :class:ChoiceFactoryOptions
263+ :return: A :class:Task representing the asynchronous operation.
264+ :rtype: :class:Task
265+
266+ .. remarks::
267+ If the task is successful, the result contains the updated activity.
168268 """
169269 # Get base prompt text (if any)
170270 text = prompt .text if prompt is not None and prompt .text else ""
0 commit comments