Skip to content

Commit 8bf73cc

Browse files
authored
Merge pull request #628 from microsoft/emolsh/api-ref-docs-activityprompt
emolsh/api-ref-docs-activityprompt
2 parents f6f69b7 + 63ff981 commit 8bf73cc

File tree

1 file changed

+68
-25
lines changed

1 file changed

+68
-25
lines changed

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

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@
1919
from .prompt_recognizer_result import PromptRecognizerResult
2020
from .prompt_validator_context import PromptValidatorContext
2121

22-
2322
class ActivityPrompt(Dialog, ABC):
2423
"""
2524
Waits for an activity to be received.
2625
27-
This prompt requires a validator be passed in and is useful when waiting for non-message
28-
activities like an event to be received. The validator can ignore received events until the
29-
expected activity is received.
26+
.. remarks:
27+
This prompt requires a validator be passed in and is useful when waiting for non-message
28+
activities like an event to be received. The validator can ignore received events until the
29+
expected activity is received.
30+
31+
:var persisted_options:
32+
:typevar persisted_options: str
33+
:var persisted_state:
34+
:vartype persisted_state: str
3035
"""
3136

3237
persisted_options = "options"
@@ -36,13 +41,12 @@ def __init__(
3641
self, dialog_id: str, validator: Callable[[PromptValidatorContext], bool]
3742
):
3843
"""
39-
Initializes a new instance of the ActivityPrompt class.
40-
41-
Parameters:
42-
----------
43-
dialog_id (str): Unique ID of the dialog within its parent DialogSet or ComponentDialog.
44+
Initializes a new instance of the :class:`ActivityPrompt` class.
4445
45-
validator: Validator that will be called each time a new activity is received.
46+
:param dialog_id: Unique ID of the dialog within its parent :class:`DialogSet` or :class:`ComponentDialog`.
47+
:type dialog_id: str
48+
:param validator: Validator that will be called each time a new activity is received.
49+
:type validator: Callable[[PromptValidatorContext], bool]
4650
"""
4751
Dialog.__init__(self, dialog_id)
4852

@@ -53,6 +57,16 @@ def __init__(
5357
async def begin_dialog(
5458
self, dialog_context: DialogContext, options: PromptOptions = None
5559
) -> DialogTurnResult:
60+
"""
61+
Called when a prompt dialog is pushed onto the dialog stack and is being activated.
62+
63+
:param dialog_context: The dialog context for the current turn of the conversation.
64+
:type dialog_context: :class:`DialogContext`
65+
:param options: Optional, additional information to pass to the prompt being started.
66+
:type options: :class:`PromptOptions`
67+
:return Dialog.end_of_turn:
68+
:rtype Dialog.end_of_turn: :class:`Dialog.DialogTurnResult`
69+
"""
5670
if not dialog_context:
5771
raise TypeError("ActivityPrompt.begin_dialog(): dc cannot be None.")
5872
if not isinstance(options, PromptOptions):
@@ -84,6 +98,14 @@ async def begin_dialog(
8498

8599
async def continue_dialog(self, dialog_context: DialogContext) -> DialogTurnResult:
86100
if not dialog_context:
101+
"""
102+
Called when a prompt dialog is the active dialog and the user replied with a new activity.
103+
104+
:param dialog_context: The dialog context for the current turn of the conversation.
105+
:type dialog_context: :class:`DialogContext`
106+
:return Dialog.end_of_turn:
107+
:rtype Dialog.end_of_turn: :class:`Dialog.DialogTurnResult`
108+
"""
87109
raise TypeError(
88110
"ActivityPrompt.continue_dialog(): DialogContext cannot be None."
89111
)
@@ -130,11 +152,22 @@ async def resume_dialog( # pylint: disable=unused-argument
130152
self, dialog_context: DialogContext, reason: DialogReason, result: object = None
131153
):
132154
"""
133-
Prompts are typically leaf nodes on the stack but the dev is free to push other dialogs
134-
on top of the stack which will result in the prompt receiving an unexpected call to
135-
resume_dialog() when the pushed on dialog ends.
136-
To avoid the prompt prematurely ending, we need to implement this method and
137-
simply re-prompt the user
155+
Called when a prompt dialog resumes being the active dialog on the dialog stack, such
156+
as when the previous active dialog on the stack completes.
157+
158+
.. note:
159+
Prompts are typically leaf nodes on the stack but the dev is free to push other dialogs
160+
on top of the stack which will result in the prompt receiving an unexpected call to
161+
:meth:resume_dialog() when the pushed on dialog ends.
162+
To avoid the prompt prematurely ending, we need to implement this method and
163+
simply re-prompt the user.
164+
165+
:param dialog_context: The dialog context for the current turn of the conversation
166+
:type dialog_context: :class:`DialogContext`
167+
:param reason: An enum indicating why the dialog resumed.
168+
:type reason: :class:`DialogReason`
169+
:param result: Optional, value returned from the previous dialog on the stack.
170+
:type result: object
138171
"""
139172
await self.reprompt_dialog(dialog_context.context, dialog_context.active_dialog)
140173

@@ -155,15 +188,14 @@ async def on_prompt(
155188
"""
156189
Called anytime the derived class should send the user a prompt.
157190
158-
Parameters:
159-
----------
160-
context: Context for the current turn of conversation with the user.
161-
162-
state: Additional state being persisted for the prompt.
163-
164-
options: Options that the prompt started with in the call to `DialogContext.prompt()`.
165-
166-
isRetry: If `true` the users response wasn't recognized and the re-prompt should be sent.
191+
:param dialog_context: The dialog context for the current turn of the conversation
192+
:type dialog_context: :class:`DialogContext`
193+
:param state: Additional state being persisted for the prompt.
194+
:type state: Dict[str, dict]
195+
:param options: Options that the prompt started with in the call to `DialogContext.prompt()`.
196+
:type options: :class:`PromptOptions`
197+
:param isRetry: If `true` the users response wasn't recognized and the re-prompt should be sent.
198+
:type isRetry: bool
167199
"""
168200
if is_retry and options.retry_prompt:
169201
options.retry_prompt.input_hint = InputHints.expecting_input
@@ -175,7 +207,18 @@ async def on_prompt(
175207
async def on_recognize( # pylint: disable=unused-argument
176208
self, context: TurnContext, state: Dict[str, object], options: PromptOptions
177209
) -> PromptRecognizerResult:
178-
210+
"""
211+
When overridden in a derived class, attempts to recognize the incoming activity.
212+
213+
:param context: Context for the current turn of conversation with the user.
214+
:type context: :class:`TurnContext`
215+
:param state: Contains state for the current instance of the prompt on the dialog stack.
216+
:type state: Dict[str, object]
217+
:param options: A prompt options object
218+
:type options: :class:`PromptOptions`
219+
:return result: constructed from the options initially provided in the call to `async def on_prompt()`
220+
:rtype result: :class:`PromptRecognizerResult`
221+
"""
179222
result = PromptRecognizerResult()
180223
result.succeeded = (True,)
181224
result.value = context.activity

0 commit comments

Comments
 (0)