Prompt<T> 类

类型参数

T

键入为其创建的提示。

public abstract class Prompt
extends Dialog

定义提示对话的核心行为。 当提示结束时,它应返回一个 Object,表示提示的值。 分别使用 add(Dialog dialog)addDialog(Dialog dialog) 将提示添加到对话集或组件对话。 使用 prompt(String dialogId, PromptOptions options)beginDialog(String dialogId, Object options) 启动提示。 如果从 WaterfallStep 中的 WaterfallDialog启动提示,则提示结果将在瀑布图的下一步中提供。

字段摘要

修饰符和类型 字段和描述
static final java.lang.String ATTEMPTCOUNTKEY

构造函数摘要

构造函数 说明
Prompt(String dialogId, PromptValidator<T> validator)

初始化 {@link Prompt{T}} 类的新实例。

方法摘要

修饰符和类型 方法和描述
protected Activity appendChoices(Activity prompt, String channelId, List<Choice> choices, ListStyle style, ChoiceFactoryOptions options)

在派生类中重写时,当用户被提示输入时,会将选项追加到活动中。

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

在将提示对话框推送到对话堆栈并被激活时调用。

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

当提示对话为活动对话且用户使用新活动进行回复时调用。

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

在事件气泡到其父级之前调用。

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

在派生类中重写时,会提示用户输入。

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

在派生类中重写时,尝试识别用户的输入。

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

请求提示对话框以重新提示用户输入时调用。

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

当提示对话恢复为对话堆栈上的活动对话时调用,例如当堆栈上的上一个活动对话完成时调用。

方法继承自 Dialog

方法继承自 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

字段详细信息

ATTEMPTCOUNTKEY

public static final String ATTEMPTCOUNTKEY

构造函数详细信息

Prompt

public Prompt(String dialogId, PromptValidator validator)

初始化 {@link Prompt{T}} 类的新实例。 从派生类中的构造函数调用以初始化 {@link Prompt{T}} 类。

Parameters:

dialogId - 要分配给此提示的 ID。
validator - 可选的 {@link PromptValidator{T}} ,其中包含对此提示的其他自定义验证。
              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.

方法详细信息

appendChoices

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

在派生类中重写时,当用户被提示输入时,会将选项追加到活动中。

Parameters:

prompt - 要向其追加选项的活动。
channelId - 用户通道的 ID。
choices - 要追加的选项。
style - 指示应如何向用户显示选项。
options - 显示选项时要使用的格式设置选项。

Returns:

表示异步操作的 CompletableFuture
     If the task is successful, the result contains the updated activity.

beginDialog

public CompletableFuture beginDialog(DialogContext dc, Object options)

在将提示对话框推送到对话堆栈并被激活时调用。

Overrides:

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

Parameters:

dc - 当前会话轮次的对话上下文。
options - 可选,要传递给正在启动的提示的其他信息。

Returns:

表示异步操作的 CompletableFuture
     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)

当提示对话为活动对话且用户使用新活动进行回复时调用。

Overrides:

Prompt<T>.continueDialog(DialogContext dc)

Parameters:

dc - 当前会话轮次的对话上下文。

Returns:

表示异步操作的 CompletableFuture
     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)

在事件气泡到其父级之前调用。 这是一个执行事件拦截的好位置,因为返回“true”将防止事件进一步浮升到对话父级,还会阻止任何子对话执行其默认处理。

Overrides:

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

Parameters:

dc - 当前会话轮次的对话上下文。
e - 正在引发的事件。

Returns:

事件是否由当前对话处理,并且应停止进一步处理。

onPrompt

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

在派生类中重写时,会提示用户输入。

Parameters:

turnContext - 与用户当前轮次对话的上下文。
state - 包含对话框堆栈上提示的当前实例的状态。
options - 一个提示选项 对象,该对象是从调用 中最初提供的选项构造的 prompt(String dialogId, PromptOptions options)
isRetry - 如果这是此提示对话框实例首次在堆栈上提示用户输入,则为 true;否则为 false。 getPrompt()确定是否应使用 或 getRetryPrompt()

Returns:

表示异步操作的 CompletableFuture

onRecognize

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

在派生类中重写时,尝试识别用户的输入。

Parameters:

turnContext - 与用户当前轮次对话的上下文。
state - 包含对话框堆栈上提示的当前实例的状态。
options - 一个提示选项 对象,该对象是从调用 中最初提供的选项构造的 prompt(String dialogId, PromptOptions options)

Returns:

表示异步操作的 CompletableFuture
     If the task is successful, the result describes the result of the
     recognition attempt.

repromptDialog

public CompletableFuture repromptDialog(TurnContext turnContext, DialogInstance instance)

请求提示对话框以重新提示用户输入时调用。

Overrides:

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

Parameters:

turnContext - 与用户当前轮次对话的上下文。
instance - 堆栈上对话框的实例。

Returns:

表示异步操作的 CompletableFuture

resumeDialog

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

当提示对话恢复为对话堆栈上的活动对话时调用,例如当堆栈上的上一个活动对话完成时调用。

Overrides:

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

Parameters:

dc - 当前会话轮次的对话上下文。
reason - 一个枚举,指示对话恢复的原因。
result - (可选)从堆栈上一个对话框返回的值。 返回的值的类型取决于上一个对话框。

Returns:

表示异步操作的 CompletableFuture
     If the task is successful, the result indicates whether the dialog is
     still active after the turn has been processed by the dialog.

适用于