dialogContext.activeDialog 使用瀑布对话框时始终未定义
dialogContext.activeDialog always undefined when using waterfall dialog
我不知道为什么 dialogContext 的 activeDialog
字段总是未定义。我需要用它来查看用户是否在瀑布对话框的中间。这是我的机器人代码的样子(打字稿):
export class MyBot{
constructor(){
this.dialogState = this.conversationState.createProperty("dialog-state");
this.dialogs = new DialogSet(this.dialogState);
this.dialogs.add(new ChoicePrompt("choice-prompt"));
const steps = [
step => step.prompt("choice-prompt", "What browser are you currently using?", ["!", "1"]),
step => step.prompt("choice-prompt", "And what device are you using?", "!", "1")
];
this.dialogs.add(new WaterfallDialog("something", steps));
}
public async onTurn(context: TurnContext) {
const dc = await this.dialogs.createContext(context);
console.log(dc.activeDialog); // always logs undefined
return dc.beginDialog("something");
}
}
你需要在回合结束时保存对话状态,否则对话状态将在每一回合重新开始。尝试将其添加到 onTurn
方法的末尾(或接近末尾):
this.conversationState.saveChanges(context);
此外,我要指出 return 从 onTurn
方法调用 dc.beginDialog
的结果没有意义,因为 onTurn
在技术上不期望return 任意值。
我不知道为什么 dialogContext 的 activeDialog
字段总是未定义。我需要用它来查看用户是否在瀑布对话框的中间。这是我的机器人代码的样子(打字稿):
export class MyBot{
constructor(){
this.dialogState = this.conversationState.createProperty("dialog-state");
this.dialogs = new DialogSet(this.dialogState);
this.dialogs.add(new ChoicePrompt("choice-prompt"));
const steps = [
step => step.prompt("choice-prompt", "What browser are you currently using?", ["!", "1"]),
step => step.prompt("choice-prompt", "And what device are you using?", "!", "1")
];
this.dialogs.add(new WaterfallDialog("something", steps));
}
public async onTurn(context: TurnContext) {
const dc = await this.dialogs.createContext(context);
console.log(dc.activeDialog); // always logs undefined
return dc.beginDialog("something");
}
}
你需要在回合结束时保存对话状态,否则对话状态将在每一回合重新开始。尝试将其添加到 onTurn
方法的末尾(或接近末尾):
this.conversationState.saveChanges(context);
此外,我要指出 return 从 onTurn
方法调用 dc.beginDialog
的结果没有意义,因为 onTurn
在技术上不期望return 任意值。