我试图在系统中的任何其他对话框完成后启动反馈对话框。我发现这个答案上面说要使用onEndDialog
,但这不是 ActivityHandler 中的有效函数,只是onDialog
。我的“主对话框”位于扩展 ActivityHandler 的 bot.js 中,这就是我不扩展 ComponentDialog 的原因。鉴于这是如何设置的,有没有办法确定对话何时结束?我尝试检查对话框堆栈onDialog
,但它读取为没有来自用户的欢迎消息和初始消息的对话框,之后始终读取为正在运行的对话框。有没有办法修改我的函数/机器人处理程序来检测对话事件的结束?这是我尝试过的 onDialog 函数。
this.onDialog(async (context, next) => {
const currentDialog = await this.dialogState.get(context, {});
if (currentDialog.dialogStack) {
console.log('Dialog is running');
} else {
console.log('Dialog is not running');
}
// By calling next() you ensure that the next BotHandler is run.
await next();
});
我考虑过在每个对话框的末尾添加一个额外的步骤来调用反馈对话框(可能通过replaceDialog),但我不确定这是否是最佳实践。
这不能完全做到,因为endDialog
不会冒泡到任何可以访问的东西ActivityHandler
(据我所知)。
但对于解决方法来说,你已经很接近了!将其更改为如下所示:
this.onDialog(async (context, next) => {
const currentDialog = await this.dialogState.get(context);
if (currentDialog === undefined) {
console.log('No dialogs started');
} else if (currentDialog.dialogStack && currentDialog.dialogStack.length > 0) {
console.log('Dialog is running');
} else {
console.log('Dialog is not running');
}
// By calling next() you ensure that the next BotHandler is run.
await next();
});
你的不太有效只是因为currentDialog
被设置为{}
如果它不存在,这是真的,所以我们需要检查dialogStack中是否有任何东西currentDialog.dialogStack.length > 0
.
currentDialog
is undefined
如果还没有开始对话,那么currentDialog === undefined
or !currentDialog
允许初始消息和欢迎消息。拥有这三个独立的分支应该可以让您处理每种情况。
关于“最佳实践”,我想说的是right如果您想在结束时获得反馈,请接近every对话。如果有any如果您不需要反馈,最好在相应对话框结束时调用反馈对话框。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)