在路由之前捕获对话框名称 - 中间件

问题描述 投票:0回答:2

我有一个使用MS bot框架构建的机器人,使用库结构。

我正在尝试捕获消息的对话框名称+库,然后将其路由到对话框。 (用于分析目的)

是否有可以帮助我做到这一点的中间件?

我尝试了routingUniversalBot中间件,但它似乎在选择对话框之前运行。

node.js botframework
2个回答
0
投票

这里有一个可能的选择是使用ISessionMiddleware

 botbuilder: function (session, next) {
       console.log(session.message.text);
       next();
   }

这将允许您访问会话。这将在消息绑定到特定会话后执行,并提供查看消息和会话状态(用户在可用对话框中等)的选项,然后决定如何继续。


0
投票

似乎bot.onDisambiguateRoute是解决方案。

在这种情况下,var route包含路由名称/库,除此之外还有对话框参数。 see the docs for more info

示例代码:

bot.onDisambiguateRoute(function (session, routes) { // Route message as normal var route = builder.Library.bestRouteResult(routes, session.dialogStack(), bot.name); // *** log route if (route) { bot.library(route.libraryName).selectRoute(session, route); } else { // Just let the active dialog process the message session.routeToActiveDialog(); } } });

© www.soinside.com 2019 - 2024. All rights reserved.