[英]How to get a hold of dialog stack on v4 node SDK BOT
我已经习惯了v3节点botbuilder sdk,所以我有一个中间件,我在那里查看对话框堆栈,并按照以下方式进行操作。
知道对话框堆栈的V3中间件: -
bot.use({
botbuilder: function (session, next) {
if (session.dialogStack()&& session.dialogStack().length <= 0 ) {
// Do something is dialog stack is empty.
}
},
send: function (event, next) {
if (event.type != "typing" && event.type != "endOfConversation") {
logUserConversation("Botoutput", event);
}
next();
}
});
V4中间件,我需要使用对话框堆栈来执行一些操作。
adapter.use(async (turnContext, next) => {
// pre-processing of the current incoming activity
turnContext.onSendActivities(async (sendContext, activities, nextSend) => {
// console.log(`pre-processing of outgoing activities`);
await nextSend();
***//Need to know the dialog stack here.***
});
await next();
});
我查看了turnContext对象,但没有迹象表明是否有对话框堆栈。 我可以看到DialogContext对象有一个'stack'属性,但不知道如何在我的中间件中使用。
您只需要添加activities.filter方法来检索传递的直通数据,就可以了。
const conversationState = new ConversationState(memoryStorage);
const userState = new UserState(memoryStorage);
adapter.use(async (turnContext, next) => {
const userActivity = turnContext.activity;
if (userActivity.from.role === 'user' && turnContext.activity.text.length > 0) {
console.log('From user: ', userActivity);
}
turnContext.onSendActivities(async (sendContext, activities, nextSend) => {
await nextSend();
activities.filter(a => a.type !== 'typing' && a.type !== 'endOfConversation').forEach(a => console.log('From bot: ', a));
});
await next();
});
希望有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.