Using the streamlined On handlers in Bot Framework v4.3

Bot Framework v4.3 has introduced a series of ‘On’ activity handlers to make you code more modular and easier to understand. Once you updated your project reference to use 4.3 you need to change you main bot to use the new activity handler class;

public class MayBotBot : IBot
To
 public class MayBotBot : ActivityHandler

You’ll then be able to use override to discover the options, e.g.


protected virtual Task OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

The other nice new feature that might slide under the radar is when the framework looks for a dialog Id it will now search up the stack to look for one. I.e. you could, if you wanted to, AddDialog all your possible dialogs in the root dialog and remove all AddDialog from everywhere else. Don’t do that, but in theory you could. The advantage here is that you can declare your common dialogs once and not have to keep adding them everywhere else.

Enjoy the chocolatey goodness of 4.3.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s