WaterfallDialog class
瀑布图是一个经过优化的对话框,用于提示用户出现一系列问题。
- 扩展
-
Dialog<O>
注解
瀑布图接受将按顺序执行的函数堆栈。 每个瀑布步骤都可以询问用户的问题,用户的响应将通过 step.result
传递到瀑布中的下一步。 特殊 step.value
对象可用于在步骤之间保留值:
const { ComponentDialog, WaterfallDialog, TextPrompt, NumberPrompt } = require('botbuilder-dialogs);
class FillProfileDialog extends ComponentDialog {
constructor(dialogId) {
super(dialogId);
// Add control flow dialogs
this.addDialog(new WaterfallDialog('start', [
async (step) => {
// Ask user their name
return await step.prompt('namePrompt', `What's your name?`);
},
async (step) => {
// Remember the users answer
step.values['name'] = step.result;
// Ask user their age.
return await step.prompt('agePrompt', `Hi ${step.values['name']}. How old are you?`);
},
async (step) => {
// Remember the users answer
step.values['age'] = step.result;
// End the component and return the completed profile.
return await step.endDialog(step.values);
}
]));
// Add prompts
this.addDialog(new TextPrompt('namePrompt'));
this.addDialog(new NumberPrompt('agePrompt'))
}
}
module.exports.FillProfileDialog = FillProfileDialog;
构造函数
Waterfall |
创建包含给定步骤数组的新瀑布对话。 |
属性
id | 对话框的唯一 ID。 设置对话框的唯一 ID。 |
telemetry |
获取此对话框的遥测客户端。 设置此对话框的遥测客户端。 |
继承属性
End |
获取默认的轮次结束结果。 |
方法
add |
向瀑布添加一个新步骤。 |
begin |
当 WaterfallDialog 启动并推送到对话堆栈时调用。 |
continue |
当 WaterfallDialog继续时调用,该对话是活动对话,用户使用新的 活动进行答复。 |
end |
对话框结束时调用。 |
get |
获取由 ID 和步骤数组成的对话框版本。 |
resume |
当子 WaterfallDialog 完成轮次时调用,将控件返回到此对话框。 |
继承的方法
configure(Record<string, unknown>) | 用于配置对象的 Fluent 方法。 |
get |
|
on |
通过使用当前对话或当前对话启动的对话,使用 |
reprompt |
在派生类中重写时,将用户重新分配输入。 |
构造函数详细信息
WaterfallDialog(string, WaterfallStep<O>[])
创建包含给定步骤数组的新瀑布对话。
new WaterfallDialog(dialogId: string, steps?: WaterfallStep<O>[])
参数
- dialogId
-
string
组件中对话框的唯一 ID 或将其添加到其中。
- steps
-
WaterfallStep<O>[]
(可选)异步瀑布步骤函数的数组。
注解
有关创建有效步骤函数的详细信息,请参阅 addStep() 函数。
属性详细信息
id
对话框的唯一 ID。 设置对话框的唯一 ID。
string id
属性值
string
对话框的 ID。
注解
如果未指定,则会自动生成此代码。
telemetryClient
获取此对话框的遥测客户端。 设置此对话框的遥测客户端。
BotTelemetryClient telemetryClient
属性值
BotTelemetryClient
要用于日志记录的 BotTelemetryClient。
继承属性详细信息
EndOfTurn
获取默认的轮次结束结果。
static EndOfTurn: DialogTurnResult
属性值
注解
此结果指示对话(或对话中的逻辑步骤)已完成当前轮次的处理,仍然处于活动状态,并且正在等待更多输入。
方法详细信息
addStep(WaterfallStep<O>)
向瀑布添加一个新步骤。
function addStep(step: WaterfallStep<O>): this
参数
- step
要调用的异步步骤函数。
返回
this
用于流利调用 addStep()
的瀑布对话。
注解
所有步骤函数都应是异步的,并返回 DialogTurnResult
。 传入函数的 WaterfallStepContext
派生自 DialogContext
,并包含许多返回 DialogTurnResult
的堆栈操作方法,因此通常只需从调用的 DialogContext 方法返回结果。
步骤函数本身可以是异步关闭:
const helloDialog = new WaterfallDialog('hello');
helloDialog.addStep(async (step) => {
await step.context.sendActivity(`Hello World!`);
return await step.endDialog();
});
命名异步函数:
async function helloWorldStep(step) {
await step.context.sendActivity(`Hello World!`);
return await step.endDialog();
}
helloDialog.addStep(helloWorldStep);
或者绑定到其 this
指针的类方法:
helloDialog.addStep(this.helloWorldStep.bind(this));
beginDialog(DialogContext, O)
当 WaterfallDialog 启动并推送到对话堆栈时调用。
function beginDialog(dc: DialogContext, options?: O): Promise<DialogTurnResult>
参数
当前会话轮次的 DialogContext。
- options
-
O
可选,要传递给 对话框的初始信息。
返回
Promise<DialogTurnResult>
表示异步操作的 Promise。
注解
如果任务成功,则结果指示在对话框处理轮次后,对话框 是否仍然处于活动状态。
continueDialog(DialogContext)
当 WaterfallDialog继续时调用,该对话是活动对话,用户使用新的 活动进行答复。
function continueDialog(dc: DialogContext): Promise<DialogTurnResult>
参数
当前会话轮次的 DialogContext。
返回
Promise<DialogTurnResult>
表示异步操作的 Promise。
注解
如果任务成功,则结果指示对话在对话框处理轮次后是否仍然处于活动状态。 结果还可能包含返回值。
endDialog(TurnContext, DialogInstance, DialogReason)
对话框结束时调用。
function endDialog(context: TurnContext, instance: DialogInstance, reason: DialogReason): Promise<void>
参数
- context
-
TurnContext
当前会话轮次的上下文。
- instance
- DialogInstance
当前对话框的实例。
- reason
- DialogReason
对话结束的原因。
返回
Promise<void>
getVersion()
获取由 ID 和步骤数组成的对话框版本。
function getVersion(): string
返回
string
对话框版本,由 ID 和步骤数组成。
resumeDialog(DialogContext, DialogReason, any)
当子 WaterfallDialog 完成轮次时调用,将控件返回到此对话框。
function resumeDialog(dc: DialogContext, reason: DialogReason, result?: any): Promise<DialogTurnResult>
参数
对话当前轮次的 DialogContext。
- reason
- DialogReason
(xref:botbuilder-dialogs.DialogReason) 对话恢复的原因。
- result
-
any
可选,从调用的对话框返回的值。 返回的值的类型取决于子对话。
返回
Promise<DialogTurnResult>
表示异步操作的 Promise。
继承的方法详细信息
configure(Record<string, unknown>)
用于配置对象的 Fluent 方法。
function configure(config: Record<string, unknown>): this
参数
- config
-
Record<string, unknown>
要应用的配置设置。
返回
this
操作完成后 可配置。
getConverter(string)
function getConverter(_property: string): Converter | ConverterFactory
参数
- _property
-
string
条件选择器配置的键。
返回
选择器配置的转换器。
onDialogEvent(DialogContext, DialogEvent)
通过使用当前对话或当前对话启动的对话,使用 DialogContext.emitEvent()
引发事件时调用。
function onDialogEvent(dc: DialogContext, e: DialogEvent): Promise<boolean>
参数
当前对话轮次的对话上下文。
正在引发的事件。
返回
Promise<boolean>
如此 如果事件由当前对话框处理,并且冒泡应停止。
repromptDialog(TurnContext, DialogInstance)
在派生类中重写时,将用户重新分配输入。
function repromptDialog(_context: TurnContext, _instance: DialogInstance): Promise<void>
参数
- _context
-
TurnContext
轮次的上下文对象。
- _instance
- DialogInstance
此对话框的当前状态信息。
返回
Promise<void>
注解
支持验证和重新提示逻辑的派生对话应重写此方法。 默认情况下,此方法不起作用。
DialogContext 在当前对话应从用户重新请求输入时调用此方法。 此方法是针对提示对话实现的。
另请参阅