编辑:
在查看源代码时,我在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 Framework版本3-这是他们在这里使用的版本。
我遵循瀑布工作原理(https://docs.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,next);
}.bind(this)
]);
};
基本上,一个对话框正在加载另一个对话框(之间还有其他一些代码,例如在数据存储区中设置数据)。 endDialog
无处可调用。但是在MS教程的示例中,每个瀑布都以某种形式的endDialog
(endDialog
或endDialogWithResults
等结尾)。
使用beginDialog
“打开”的每个对话框在完成瀑布之后,即运行在数组中传递给bot.dialog
的函数时是否自动“关闭”自身? (在上面的代码中,瀑布只是一步)。
何时需要明确呼叫endDialog
?
感谢您的帮助!