Search code examples
c#botframework

Intercepting outgoing activities in Virtual Assistant Template Botframework


I'm looking for a place inside a Microsoft Bot code (created with the Virtual Assistant Template 4.9.1.1) where I can be able to intercept any outgoing activity just before it is sent from the bot to the client.

As I understood one solution could be to override these two methods in DefaultAdapter:

bool CanProcessOutgoingActivity(Activity activity)

Task<ResourceResponse> ProcessOutgoingActivityAsync(ITurnContext turnContext, Activity activity, CancellationToken cancellationToken)

Since I just have to do some changes to the activity, I thought I could do it directly in the CanProcessOutgoingActivity. But I was wrong since I also need some info from the context.

So I had CanProcessOutgoingActivity() just returning true and move the logic in ProcessOutgoingActivityAsync, where all the info are available.

However I don't understand how it is supposed to work and what the method should return in the ResourceResponse parameter.

Is there any example or documentation from which I can understand how does it works?


Solution

  • Middleware would be the recommended and most straightforward (not to mention modular) approach. It is designed for this type of scenario and should accomplish what you need.