使用瀑布对话框时,dialogContext.activeDialog始终未定义

时间:2019-02-04 20:07:15

标签: typescript dialog botframework state-management

我不知道为什么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");
    }
}

1 个答案:

答案 0 :(得分:0)

您需要在回合结束时保存对话状态,否则对话状态将在每回合重新开始。尝试将其添加到onTurn方法的末端(或附近):

this.conversationState.saveChanges(context);

我还要指出,从dc.beginDialog方法返回onTurn调用的结果是没有意义的,因为从技术上讲,onTurn不会返回任何值。