我不知道为什么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");
}
}
答案 0 :(得分:0)
您需要在回合结束时保存对话状态,否则对话状态将在每回合重新开始。尝试将其添加到onTurn
方法的末端(或附近):
this.conversationState.saveChanges(context);
我还要指出,从dc.beginDialog
方法返回onTurn
调用的结果是没有意义的,因为从技术上讲,onTurn
不会返回任何值。>