编辑:
在查看源代码时,我在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>
*/我正在学习微软的版本3 --这是他们正在使用的版本。
我遵循瀑布工作原理(https://learn.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-dialog-manage-conversation-flow?view=azure-bot-service-3.0)的概念,但我不明白的是endDialog扮演了什么角色。
例如,在我们使用的代码中,有一组单独的对话框,它们都具有以下形式
module.exports = function showTickets() {
this.bot.dialog('/showAllTickets', [
async function showAllTicketsFn(session, args, next) {
this.beginDialog.bind(this, '/showTickets')(session, args, next);
}.bind(this)
]);
};基本上,一个对话框加载另一个对话框(中间有一些其他代码,比如在数据存储区中设置数据)。endDialog在哪儿都不叫。但是在MS教程的示例中,每个瀑布都以某种形式的endDialog (endDialog或endDialogWithResults等)结束。
当beginDialog瀑布完成时,是否每个对话框都会自动“关闭”自己,也就是说,当传递给bot.dialog的数组中的函数经过时?(在上面的代码中,瀑布只是一个步骤)。
何时需要显式调用endDialog?
谢谢你的帮助!
发布于 2019-11-07 23:19:22
实际上,文档应该说您的应该结束对话框,而不是必须。如果不显式调用EndDialog,瀑布将自动结束。它意味着更多的是一个内置的安全机制,以帮助避免用户陷入困境,忘记在获得结果后调用end对话框。但是,在某些情况下,不添加显式EndDialog调用是可以的。你可以在瀑布这里找到更多。
一个有效的用例是,一个对话框调用是一个瀑布,它简单地决定它想要分支到哪个对话框。一旦它分支到给定的对话框,就没有理由添加一个在该对话框结束后结束的步骤。
但是很可能,即使在这种情况下,使用ReplaceDialog来用分支到的对话框替换自己也更有效。
发布于 2019-11-04 11:47:07
嘿,我自己也在想这个,是从MS那里找到的。
必须显式结束使用瀑布创建的对话框,否则机器人将无限期地重复该瀑布。您可以使用下列方法之一结束瀑布: session.endDialog:如果没有数据返回到调用对话框,则使用此方法结束瀑布。 session.endDialogWithResult:如果有数据返回到调用对话框,则使用此方法结束瀑布。返回的响应参数可以是JSON对象或任何JavaScript原始数据类型。
如果要结束所有对话框并停止会话,可以使用带有可选消息/对象的endConversationAction触发器
this.bot.dialog('/showAllTickets', [
async function showAllTicketsFn(session, args, next) {
this.beginDialog.bind(this, '/showTickets')(session, args, next);
session.endConversation();
}.bind(this)
]);https://stackoverflow.com/questions/58690001
复制相似问题