Search code examples
botframework

Botframework catching outgoing and incoming activities


I want to catch some state variables of the conversation using the next code in the MyBot : ActivityHandler class:

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
   var message = turnContext.Activity.Text;
}

But this is happening only when the user makes an action not when the bot sends any message (I´m aware turncontext only process inbound activities). I need to catch both outcoming and incoming activities in order to access something like the turncontext... Which method should I use?

I´ve seen in the emulator right pane and they catch all messages, how do they do that?

This event depend of the channel?

Thanks,


Solution

  • You need middleware for that: Microsoft documentation

    Some code to get you started is in the accepted answer of this SO question