Javascript 你需要打电话给';endDialog';每';beginDialog';在MicrosoftBot框架中?什么时候打电话';endDialog';?

Javascript 你需要打电话给';endDialog';每';beginDialog';在MicrosoftBot框架中?什么时候打电话';endDialog';?,javascript,node.js,botframework,Javascript,Node.js,Botframework,编辑: 在浏览源代码时,我在botbuilder.d.ts中发现了以下内容。在瀑布中似乎不需要显式调用endDialog /* You can terminate a waterfall early by either falling through every step of the waterfall using * calls to `skip()` or simply not starting another prompt or dialog. * * __note:__ Wate

编辑:

在浏览源代码时,我在
botbuilder.d.ts
中发现了以下内容。在瀑布中似乎不需要显式调用
endDialog

/* You can terminate a waterfall early by either falling through every step of the waterfall using
 * calls to `skip()` or simply not starting another prompt or dialog.
 *
 * __note:__ Waterfalls have a hidden last step which will automatically end the current dialog if
 * if you call a prompt or dialog from the last step. This is useful where you have a deep stack of
 * dialogs and want a call to [session.endDialog()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session.html#enddialog)
 * from the last child on the stack to end the entire stack. The close of the last child will trigger
 * all of its parents to move to this hidden step which will cascade the close all the way up the stack.
 * This is typically a desired behavior but if you want to avoid it or stop it somewhere in the
 * middle you'll need to add a step to the end of your waterfall that either does nothing or calls
 * something like [session.send()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session.html#send)
 * which isn't going to advance the waterfall forward.
 * @example
 * <pre><code>
 * var bot = new builder.BotConnectorBot();
 * bot.add('/', [
 *     function (session) {
 *         builder.Prompts.text(session, "Hi! What's your name?");
 *     },
 *     function (session, results) {
 *         if (results && results.response) {
 *             // User answered question.
 *             session.send("Hello %s.", results.response);
 *         } else {
 *             // User said never mind.
 *             session.send("OK. Goodbye.");
 *         }
 *     }
 * ]);
 * </code></pre>
 */
*/ 我正在学习MS Bot框架版本3——这就是他们正在使用的版本

我遵循瀑布如何工作的概念(),但有一件事我不明白,
endDialog
扮演什么角色

例如,在我们正在使用的代码中,有一堆单独的对话框,它们都具有

this.bot.dialog('/showAllTickets', [
    async function showAllTicketsFn(session, args, next) {
        this.beginDialog.bind(this, '/showTickets')(session, args, next);
        session.endConversation();
    }.bind(this)
]);
基本上是一个对话框加载另一个对话框(中间有一些其他代码,比如在数据存储中设置数据)。无处调用
endDialog
。但在MS教程的示例中,每个瀑布都以某种形式的
endDialog
endDialog
endDialogWithResults
等)结束

使用
beginDialog
打开的每个对话框是否在其瀑布完成时自动“关闭”自己,也就是说,当数组中传递给
bot.dialog
的函数运行完毕时?(在上面的代码中,瀑布只是一个步骤)

什么时候需要显式调用
endDialog

/* You can terminate a waterfall early by either falling through every step of the waterfall using
 * calls to `skip()` or simply not starting another prompt or dialog.
 *
 * __note:__ Waterfalls have a hidden last step which will automatically end the current dialog if
 * if you call a prompt or dialog from the last step. This is useful where you have a deep stack of
 * dialogs and want a call to [session.endDialog()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session.html#enddialog)
 * from the last child on the stack to end the entire stack. The close of the last child will trigger
 * all of its parents to move to this hidden step which will cascade the close all the way up the stack.
 * This is typically a desired behavior but if you want to avoid it or stop it somewhere in the
 * middle you'll need to add a step to the end of your waterfall that either does nothing or calls
 * something like [session.send()](/en-us/node/builder/chat-reference/classes/_botbuilder_d_.session.html#send)
 * which isn't going to advance the waterfall forward.
 * @example
 * <pre><code>
 * var bot = new builder.BotConnectorBot();
 * bot.add('/', [
 *     function (session) {
 *         builder.Prompts.text(session, "Hi! What's your name?");
 *     },
 *     function (session, results) {
 *         if (results && results.response) {
 *             // User answered question.
 *             session.send("Hello %s.", results.response);
 *         } else {
 *             // User said never mind.
 *             session.send("OK. Goodbye.");
 *         }
 *     }
 * ]);
 * </code></pre>
 */

谢谢你的帮助

嘿,我自己也在想这件事,是从MS

使用瀑布创建的对话框必须显式结束,否则bot将无限期地重复瀑布。您可以使用以下方法之一结束瀑布:

session.endDialog:如果没有数据返回调用对话框,则使用此方法结束瀑布

session.endDialogWithResult:如果有数据返回调用对话框,则使用此方法结束瀑布。返回的响应参数可以是JSON对象或任何JavaScript基元数据类型

如果要结束所有对话框并停止对话,可以使用带有可选消息/对象的
endConversationAction
触发器


嘿,我自己也在想这个,从MS

使用瀑布创建的对话框必须显式结束,否则bot将无限期地重复瀑布。您可以使用以下方法之一结束瀑布:

session.endDialog:如果没有数据返回调用对话框,则使用此方法结束瀑布

session.endDialogWithResult:如果有数据返回调用对话框,则使用此方法结束瀑布。返回的响应参数可以是JSON对象或任何JavaScript基元数据类型

如果要结束所有对话框并停止对话,可以使用带有可选消息/对象的
endConversationAction
触发器


实际上,文档应该说您应该结束对话框,而不是说您必须结束对话框。如果不显式调用
EndDialog
,瀑布将自动结束。它更像是一个内置的安全机制,帮助用户避免陷入困境,在得到结果后忘记调用enddialog。但在某些情况下,不添加显式的
EndDialog
调用是可以的。你可以在瀑布中找到更多

一个有效的用例是,对话框调用是一个瀑布,它只决定要分支到哪个对话框。一旦它分支到给定的对话框,就没有理由添加在该对话框结束后结束的步骤


但是,即使在这种情况下,使用
ReplaceDialog
将自己替换为分支到的对话框也可能更有效。

实际上,文档应该说您应该结束对话框,而不是说您必须结束对话框。如果不显式调用
EndDialog
,瀑布将自动结束。它更像是一个内置的安全机制,帮助用户避免陷入困境,在得到结果后忘记调用enddialog。但在某些情况下,不添加显式的
EndDialog
调用是可以的。你可以在瀑布中找到更多

一个有效的用例是,对话框调用是一个瀑布,它只决定要分支到哪个对话框。一旦它分支到给定的对话框,就没有理由添加在该对话框结束后结束的步骤


但很可能,即使在这种情况下,使用
ReplaceDialog
将自己替换为分支到的对话框也更有效。

我不确定这是不是真的……请参阅上面我对原始帖子的编辑。我在这一点上感到困惑,由于您引用的内容似乎与上面源代码中的注释不同。嗯,这似乎与MS.Will女士的官方指导相矛盾。Will女士将对此进行调查,也许我们可以从从事框架工作的人那里得到明确的答案。我不确定这是否属实……请参阅我对上面原始帖子的编辑。我在这一点上感到困惑,因为您所引用的内容似乎与上面源代码中的注释不同。嗯,这似乎与Will女士的官方指导相矛盾。Will女士将对此进行调查,也许我们可以从该框架的工作人员那里得到明确的答案