问题
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