how to intercept messages in botbuilder sdk v4 using middleware?

徘徊边缘 提交于 2019-12-12 23:05:48

问题


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);
    }
})

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

I didn't find example on this page.


回答1:


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());


来源:https://stackoverflow.com/questions/54225716/how-to-intercept-messages-in-botbuilder-sdk-v4-using-middleware

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!