瀑布对话框一次不运行

时间:2019-01-03 21:31:12

标签: botframework

我有以下代码:

this.dialogs.add(new TextPrompt("tp"));
this.dialogs.add(new TextPrompt("tp2"));
this.dialogs.add(new TextPrompt("tp3"));
this.dialogs.add(
    new WaterfallDialog("send_email", [
        this.promptStep.bind(this),
        async step => await step.prompt("tp", "Who do you want to email?"),
        async step => await step.prompt("tp2", "What's the subject line?"),
        async step => await step.prompt("tp3", "And what's the message?"),
        async step => await OAuthHelpers.sendMail(step.context, step.result, step.result)
    ])
);

当我在机器人模拟器中运行此命令时,会立即显示前两个文本提示。它甚至不等待我的回复。如何告诉它等待用户响应才能继续?

enter image description here

1 个答案:

答案 0 :(得分:2)

好的,所以根据您在评论中链接的要点,我认为您的问题很可能是由于the processStep function内部正在进行的一些对话处理所致。具体来说,我围绕如何启动"send_email"瀑布对话框看到了两个问题。

line 98开始,您拥有:

const dc = await this.dialogs.createContext(step.context);
await dc.beginDialog("send_email");

第一件事是,您不应在此处通过调用DialogContext创建一个全新的createContext。该步骤中已经有一个上下文,您只想使用beginDialog将另一个对话框推入堆栈。

第二件事是,当您await时,您没有return,逻辑将一直向下流到line 112,然后endDialog将调用您不想在这种情况下这样做,因为它只会杀死您刚刚放入堆栈中的当前对话框。

最终,应将这两行更改为:

return await step.beginDialog("send_email");

这将开始"send_email"对话框流程,并使其适当地前进。最终,当流程完成时,它将返回您的"graphDialog"以执行下一步,但是由于没有更多步骤,它将自动完成该对话框并将您返回到您的onTurn逻辑的空堆栈已经通过重新开始"graphDialog"处理。现在,如果您想避免这种情况,那么您需要对流程进行其他一些更改,但是希望这可以使您继续前进。

相关问题