小编vij*_*jay的帖子

如何使用 bot builder sdk v4 中的中间件区分 Bot 到用户和用户到 Bot 消息?

我在 sdk V4 Bot 中实现了一个中间件来拦截 bot 和用户之间的每条消息并记录该自定义 mongo Db。我正在尝试为使用 SDK v4 构建的 Bot 实现类似的概念。看起来我可以使用以下代码添加中间件,但是不确定如何区分机器人到用户和用户到机器人之间的消息。

V3 机器人代码

bot.use({
    botbuilder: function (session, next) {
        logUserConversation(session)
        next()
    },
    send: function (event, next) {
        logBotsConversation(event)
        next()
    }
})
Run Code Online (Sandbox Code Playgroud)

中间件的 V4 bot 代码

botAdapter.use(async (turnContext, next) => {
    // How to find which messages/activity object is from user to bot

    await next();
    // How to find which messages/activity object is from bot to user.
});
Run Code Online (Sandbox Code Playgroud)

middleware node.js microsoft-cognitive botframework

3
推荐指数
1
解决办法
810
查看次数