如何使用中间件拦截botbuilder sdk v4中的消息? [英] how to intercept messages in botbuilder sdk v4 using middleware?

查看:70
本文介绍了如何使用中间件拦截botbuilder sdk v4中的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Bot在botbuilder V3上运行,我在其中使用中间件解释

I have a Bot running on botbuilder V3 where I am using a middleware explained here to intercept the messages.

bot.use({
    botbuilder: function (session, next) {
        myMiddleware.logIncomingMessage(session, next);
    },
    send: function (event, next) {
        myMiddleware.logOutgoingMessage(event, next);
    }
})

我们计划在sdk v4上进行迁移,以便在sdk v4中寻找类似的功能.有吗?

We are planning to migrate on sdk v4 so looking for similar capabilities in sdk v4. Are there any ?

我在此推荐答案

BotAdapter 基类公开了 use 方法来注册中间件.因此,在启动逻辑中,您将创建 BotAdapter 的特定实现,通常是 BotFrameworkAdapter ,然后向其中添加中间件.像这样:

The BotAdapter base class exposes the use method to register middleware. So in your startup logic you'll create a specific implementation of a BotAdapter, typically BotFrameworkAdapter, and then add the middleware to it. Like so:

const botAdapter = new BotFrameworkAdapter( { /* credential stuff here*/ });

// Simple handler based
botAdapter.use(async (turnContext, next) => {
    // pre logic

    await next();

    // post logic
});

// Or class based
botAdapter.use(new MyMiddleware());

这篇关于如何使用中间件拦截botbuilder sdk v4中的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆