如何使用C#Core 3.1在Bot Framework v4中拦截消息以进行日志记录 [英] How to intercept messages in Bot Framework v4 for logging, using C# Core 3.1
问题描述
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
我们只想在bot框架的v4中做到这一点.
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
有没有办法在bot框架v4中拦截消息,以便我们可以记录它们?
Is there a way to intercept the messages in bot framework v4, so we can log them?
我们已经将用户消息记录在 OnMessageActivityAsync
方法中.因此,我们只需要记录从漫游器发送给用户的消息即可.
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.
提前谢谢.
推荐答案
首先,我们尝试创建自己的中间件,但无法使其正常工作.
First we tried creating our own middleware, but we could not get it to work.
经过更多研究,我们决定在 MyBot.OnTurnAsync
方法中使用 turnContext.OnSendActivities
.像这样:
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.
这篇关于如何使用C#Core 3.1在Bot Framework v4中拦截消息以进行日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!