How to intercept messages in Bot Framework v4 for logging, using C# Core 3.1

£可爱£侵袭症+ 提交于 2021-01-29 06:04:48

问题


We found this documentation explaining how to intercept messages in bot framework v3: https://docs.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-middleware?view=azure-bot-service-3.0

We want to do exactly that, only in v4 of the bot framework.

We could not find documentation for intercepting messages for bot framework v4 here: https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0

Is there a way to intercept the messages in bot framework v4, so we can log them?

We do already log the user messages in the OnMessageActivityAsync method. So we only need to log the messages that are sent from the bot to the user.

Thanks in advance.


回答1:


First we tried creating our own middleware, but we could not get it to work.

After some more research we decided to use turnContext.OnSendActivities in the MyBot.OnTurnAsync method. Like this:

turnContext.OnSendActivities(async (sendContext, activities, nextSend) =>
{
  // Log activities here
  return await nextSend();
});

For us this solution is perfect and way easier to implement then creating custom middleware. Thanks anyway.



来源:https://stackoverflow.com/questions/64390431/how-to-intercept-messages-in-bot-framework-v4-for-logging-using-c-sharp-core-3

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