Prompt<T> Class

Type Parameters

T

Type the prompt is created for.

public abstract class Prompt<T>
extends Dialog

Defines the core behavior of prompt dialogs. When the prompt ends, it should return a Object that represents the value that was prompted for. Use add(Dialog dialog) or addDialog(Dialog dialog) to add a prompt to a dialog set or component dialog, respectively. Use prompt(String dialogId, PromptOptions options) or beginDialog(String dialogId, Object options) to start the prompt. If you start a prompt from a WaterfallStep in a WaterfallDialog, then the prompt result will be available in the next step of the waterfall.

Field Summary

Modifier and Type Field and Description
static final java.lang.String ATTEMPTCOUNTKEY

Constructor Summary

Constructor Description
Prompt(String dialogId, PromptValidator<T> validator)

Initializes a new instance of the {@link Prompt{T}} class.

Method Summary

Modifier and Type Method and Description
protected Activity appendChoices(Activity prompt, String channelId, List<Choice> choices, ListStyle style, ChoiceFactoryOptions options)

When overridden in a derived class, appends choices to the activity when the user is prompted for input.

java.util.concurrent.CompletableFuture<DialogTurnResult> beginDialog(DialogContext dc, Object options)

Called when a prompt dialog is pushed onto the dialog stack and is being activated.

java.util.concurrent.CompletableFuture<DialogTurnResult> continueDialog(DialogContext dc)

Called when a prompt dialog is the active dialog and the user replied with a new activity.

protected java.util.concurrent.CompletableFuture<java.lang.Boolean> onPreBubbleEvent(DialogContext dc, DialogEvent e)

Called before an event is bubbled to its parent.

protected abstract java.util.concurrent.CompletableFuture<java.lang.Void> onPrompt(TurnContext turnContext, Map<String,Object> state, PromptOptions options, Boolean isRetry)

When overridden in a derived class, prompts the user for input.

protected abstract java.util.concurrent.CompletableFuture<PromptRecognizerResult<T>> onRecognize(TurnContext turnContext, Map<String,Object> state, PromptOptions options)

When overridden in a derived class, attempts to recognize the user's input.

java.util.concurrent.CompletableFuture<java.lang.Void> repromptDialog(TurnContext turnContext, DialogInstance instance)

Called when a prompt dialog has been requested to re-prompt the user for input.

java.util.concurrent.CompletableFuture<DialogTurnResult> resumeDialog(DialogContext dc, DialogReason reason, Object result)

Called when a prompt dialog resumes being the active dialog on the dialog stack, such as when the previous active dialog on the stack completes.

Methods inherited from Dialog

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

ATTEMPTCOUNTKEY

public static final String ATTEMPTCOUNTKEY

Constructor Details

Prompt

public Prompt(String dialogId, PromptValidator validator)

Initializes a new instance of the {@link Prompt{T}} class. Called from constructors in derived classes to initialize the {@link Prompt{T}} class.

Parameters:

dialogId - The ID to assign to this prompt.
validator - Optional, a {@link PromptValidator{T}} that contains additional, custom validation for this prompt.
              The value of dialogId must be unique within the
              <xref uid="com.microsoft.bot.dialogs.DialogSet" data-throw-if-not-resolved="false" data-raw-source="com.microsoft.bot.dialogs.DialogSet"></xref> or
              <xref uid="com.microsoft.bot.dialogs.ComponentDialog" data-throw-if-not-resolved="false" data-raw-source="com.microsoft.bot.dialogs.ComponentDialog"></xref> to which
              the prompt is added.

Method Details

appendChoices

protected Activity appendChoices(Activity prompt, String channelId, List choices, ListStyle style, ChoiceFactoryOptions options)

When overridden in a derived class, appends choices to the activity when the user is prompted for input.

Parameters:

prompt - The activity to append the choices to.
channelId - The ID of the user's channel.
choices - The choices to append.
style - Indicates how the choices should be presented to the user.
options - The formatting options to use when presenting the choices.

Returns:

A CompletableFuture representing the asynchronous operation.
     If the task is successful, the result contains the updated activity.

beginDialog

public CompletableFuture beginDialog(DialogContext dc, Object options)

Called when a prompt dialog is pushed onto the dialog stack and is being activated.

Overrides:

Prompt<T>.beginDialog(DialogContext dc, Object options)

Parameters:

dc - The dialog context for the current turn of the conversation.
options - Optional, additional information to pass to the prompt being started.

Returns:

A CompletableFuture representing the asynchronous operation.
     If the task is successful, the result indicates whether the prompt is
     still active after the turn has been processed by the prompt.

continueDialog

public CompletableFuture continueDialog(DialogContext dc)

Called when a prompt dialog is the active dialog and the user replied with a new activity.

Overrides:

Prompt<T>.continueDialog(DialogContext dc)

Parameters:

dc - The dialog context for the current turn of conversation.

Returns:

A CompletableFuture representing the asynchronous operation.
     If the task is successful, the result indicates whether the dialog is
     still active after the turn has been processed by the dialog. The
     prompt generally continues to receive the user's replies until it
     accepts the user's reply as valid input for the prompt.

onPreBubbleEvent

protected CompletableFuture onPreBubbleEvent(DialogContext dc, DialogEvent e)

Called before an event is bubbled to its parent. This is a good place to perform interception of an event as returning `true` will prevent any further bubbling of the event to the dialogs parents and will also prevent any child dialogs from performing their default processing.

Overrides:

Prompt<T>.onPreBubbleEvent(DialogContext dc, DialogEvent e)

Parameters:

dc - The dialog context for the current turn of conversation.
e - The event being raised.

Returns:

Whether the event is handled by the current dialog and further processing should stop.

onPrompt

protected abstract CompletableFuture onPrompt(TurnContext turnContext, Map state, PromptOptions options, Boolean isRetry)

When overridden in a derived class, prompts the user for input.

Parameters:

turnContext - Context for the current turn of conversation with the user.
state - Contains state for the current instance of the prompt on the dialog stack.
options - A prompt options Object constructed from the options initially provided in the call to prompt(String dialogId, PromptOptions options) .
isRetry - true if this is the first time this prompt dialog instance is on the stack is prompting the user for input; otherwise, false. Determines whether getPrompt() or getRetryPrompt() should be used.

Returns:

A CompletableFuture representing the asynchronous operation.

onRecognize

protected abstract CompletableFuture> onRecognize(TurnContext turnContext, Map state, PromptOptions options)

When overridden in a derived class, attempts to recognize the user's input.

Parameters:

turnContext - Context for the current turn of conversation with the user.
state - Contains state for the current instance of the prompt on the dialog stack.
options - A prompt options Object constructed from the options initially provided in the call to prompt(String dialogId, PromptOptions options) .

Returns:

A CompletableFuture representing the asynchronous operation.
     If the task is successful, the result describes the result of the
     recognition attempt.

repromptDialog

public CompletableFuture repromptDialog(TurnContext turnContext, DialogInstance instance)

Called when a prompt dialog has been requested to re-prompt the user for input.

Overrides:

Prompt<T>.repromptDialog(TurnContext turnContext, DialogInstance instance)

Parameters:

turnContext - Context for the current turn of conversation with the user.
instance - The instance of the dialog on the stack.

Returns:

A CompletableFuture representing the asynchronous operation.

resumeDialog

public CompletableFuture resumeDialog(DialogContext dc, DialogReason reason, Object result)

Called when a prompt dialog resumes being the active dialog on the dialog stack, such as when the previous active dialog on the stack completes.

Overrides:

Prompt<T>.resumeDialog(DialogContext dc, DialogReason reason, Object result)

Parameters:

dc - The dialog context for the current turn of the conversation.
reason - An enum indicating why the dialog resumed.
result - Optional, value returned from the previous dialog on the stack. The type of the value returned is dependent on the previous dialog.

Returns:

A CompletableFuture representing the asynchronous operation.
     If the task is successful, the result indicates whether the dialog is
     still active after the turn has been processed by the dialog.

Applies to