Dialog Class

  • java.lang.Object
    • com.microsoft.bot.dialogs.Dialog

public abstract class Dialog

Base class for all dialogs.

Field Summary

Modifier and Type Field and Description
static final DialogTurnResult END_OF_TURN

A DialogTurnResult that indicates that the current dialog is still active and waiting for input from the user next turn.

Constructor Summary

Constructor Description
Dialog(String dialogId)

Initializes a new instance of the Dialog class.

Method Summary

Modifier and Type Method and Description
java.util.concurrent.CompletableFuture<DialogTurnResult> beginDialog(DialogContext dc)

Called when the dialog is started and pushed onto the dialog stack.

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

Called when the dialog is started and pushed onto the dialog stack.

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

Called when the dialog is _continued_, where it is the active dialog and the user replies with a new activity.

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

Called when the dialog is ending.

java.lang.String getId()

Gets id for the dialog.

BotTelemetryClient getTelemetryClient()

Gets the BotTelemetryClient to use for logging.

java.lang.String getVersion()

Gets a unique String which represents the version of this dialog.

protected static java.util.concurrent.CompletableFuture<DialogTurnResult> innerRun(TurnContext turnContext, String dialogId, DialogContext dialogContext, DialogStateManagerConfiguration stateConfiguration)

Shared implementation of run with Dialog and DialogManager.

protected java.lang.String onComputeId()

Computes an id for the Dialog.

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

Called when an event has been raised, using `DialogContext.emitEvent()`, by either the current dialog or a dialog that the current dialog started.

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

Called after an event was bubbled to all parents and wasn't handled.

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

Called before an event is bubbled to its parent.

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

Called when the dialog should re-prompt the user for input.

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

Called when a child dialog completed this turn, returning control to this dialog.

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

Called when a child dialog completed this turn, returning control to this dialog.

static java.util.concurrent.CompletableFuture<java.lang.Void> run(Dialog dialog, TurnContext turnContext, StatePropertyAccessor<DialogState> accessor)

Creates a dialog stack and starts a dialog, pushing it onto the stack.

void setId(String withId)

Sets id for the dialog.

void setTelemetryClient(BotTelemetryClient withTelemetryClient)

Sets the BotTelemetryClient to use for logging.

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

END_OF_TURN

public static final DialogTurnResult END_OF_TURN

A DialogTurnResult that indicates that the current dialog is still active and waiting for input from the user next turn.

Constructor Details

Dialog

public Dialog(String dialogId)

Initializes a new instance of the Dialog class.

Parameters:

dialogId - The ID to assign to this dialog.

Method Details

beginDialog

public CompletableFuture beginDialog(DialogContext dc)

Called when the dialog is started and pushed onto the dialog stack.

Parameters:

dc - The DialogContext for the current turn of conversation.

Returns:

If the task is successful, the result indicates whether the dialog is still active after the turn has been processed by the dialog.

beginDialog

public abstract CompletableFuture beginDialog(DialogContext dc, Object options)

Called when the dialog is started and pushed onto the dialog stack.

Parameters:

dc - The DialogContext for the current turn of conversation.
options - Initial information to pass to the dialog.

Returns:

If the task is successful, the result indicates whether the dialog is still active after the turn has been processed by the dialog.

continueDialog

public CompletableFuture continueDialog(DialogContext dc)

Called when the dialog is _continued_, where it is the active dialog and the user replies with a new activity.

If this method is *not* overridden, the dialog automatically ends when the user replies.

Parameters:

dc - The DialogContext for the current turn of conversation.

Returns:

If the task is successful, the result indicates whether the dialog is still active after the turn has been processed by the dialog. The result may also contain a return value.

endDialog

public CompletableFuture endDialog(TurnContext turnContext, DialogInstance instance, DialogReason reason)

Called when the dialog is ending.

Parameters:

turnContext - The context object for this turn.
instance - State information associated with the instance of this dialog on the dialog stack.
reason - Reason why the dialog ended.

Returns:

A CompletableFuture representing the asynchronous operation.

getId

public String getId()

Gets id for the dialog.

Returns:

Id for the dialog.

getTelemetryClient

public BotTelemetryClient getTelemetryClient()

Gets the BotTelemetryClient to use for logging.

Returns:

The BotTelemetryClient to use for logging.

getVersion

public String getVersion()

Gets a unique String which represents the version of this dialog. If the version changes between turns the dialog system will emit a DialogChanged event.

Returns:

Unique String which should only change when dialog has changed in a way that should restart the dialog.

innerRun

protected static CompletableFuture innerRun(TurnContext turnContext, String dialogId, DialogContext dialogContext, DialogStateManagerConfiguration stateConfiguration)

Shared implementation of run with Dialog and DialogManager.

Parameters:

turnContext - The turnContext.
dialogId - The Id of the Dialog.
dialogContext - The DialogContext.
stateConfiguration - The DialogStateManagerConfiguration.

Returns:

A DialogTurnResult.

onComputeId

protected String onComputeId()

Computes an id for the Dialog.

Returns:

The id.

onDialogEvent

public CompletableFuture onDialogEvent(DialogContext dc, DialogEvent e)

Called when an event has been raised, using `DialogContext.emitEvent()`, by either the current dialog or a dialog that the current dialog started.

Parameters:

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

Returns:

True if the event is handled by the current dialog and bubbling should stop.

onPostBubbleEvent

protected CompletableFuture onPostBubbleEvent(DialogContext dc, DialogEvent e)

Called after an event was bubbled to all parents and wasn't handled.

This is a good place to perform default processing logic for an event. Returning `true` will prevent any processing of the event by child dialogs.

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.

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.

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.

repromptDialog

public CompletableFuture repromptDialog(TurnContext turnContext, DialogInstance instance)

Called when the dialog should re-prompt the user for input.

Parameters:

turnContext - The context object for this turn.
instance - State information for this dialog.

Returns:

A CompletableFuture representing the asynchronous operation.

resumeDialog

public CompletableFuture resumeDialog(DialogContext dc, DialogReason reason)

Called when a child dialog completed this turn, returning control to this dialog.

Generally, the child dialog was started with a call to beginDialog(DialogContext dc, Object options) However, if the replaceDialog(String dialogId) method is called, the logical child dialog may be different than the original.

If this method is *not* overridden, the dialog automatically ends when the user replies.

Parameters:

dc - The dialog context for the current turn of the conversation.
reason - Reason why the dialog resumed.

Returns:

If the task is successful, the result indicates whether this dialog is still active after this dialog turn has been processed.

resumeDialog

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

Called when a child dialog completed this turn, returning control to this dialog.

Generally, the child dialog was started with a call to beginDialog(DialogContext dc, Object options) However, if the replaceDialog(String dialogId, Object options) method is called, the logical child dialog may be different than the original.

If this method is *not* overridden, the dialog automatically ends when the user replies.

Parameters:

dc - The dialog context for the current turn of the conversation.
reason - Reason why the dialog resumed.
result - Optional, value returned from the dialog that was called. The type of the value returned is dependent on the child dialog.

Returns:

If the task is successful, the result indicates whether this dialog is still active after this dialog turn has been processed.

run

public static CompletableFuture run(Dialog dialog, TurnContext turnContext, StatePropertyAccessor accessor)

Creates a dialog stack and starts a dialog, pushing it onto the stack.

Parameters:

dialog - The dialog to start.
turnContext - The context for the current turn of the conversation.
accessor - The StatePropertyAccessor accessor with which to manage the state of the dialog stack.

Returns:

A Task representing the asynchronous operation.

setId

public void setId(String withId)

Sets id for the dialog.

Parameters:

withId - Id for the dialog.

setTelemetryClient

public void setTelemetryClient(BotTelemetryClient withTelemetryClient)

Sets the BotTelemetryClient to use for logging.

Parameters:

withTelemetryClient - The BotTelemetryClient to use for logging.

Applies to