Bot Framework (C#) Running on Mac using Visual Studio

In this post, I’ll be walking threw my steps I took to develop and run the Bot Framework locally on my Mac. Now my first decision was which text editor/IDE to use. VS Code would have been a fine choice, but since I’ve been doing a fair amount of Xamarin development lately, I thought I would try to VS of Mac since it supports .Net Core.

As you would expect with creating a project in Visual Studio, it all starts with New Project …

Selected .Net Core 2.0 …

And gave it a name…

Next I had to add some Nuget packages provided by Microsoft. I installed the following packages…

Next I needed to add the AppId and AppPassword which you receive from Microsoft and is how your bot is registered. I’ve created a post that shows this process in Azure. Once you have the AppId and AppPassword, open the appsettings.json, which should have been generate when creating the project, and app the following settings…

Next, open the startup.cs file and within the ConfigureServices method remove services.AddMvc(); and add the following code…

And within the Configure method in the same file, add the following two lines…

app.UseStaticFiles();
app.UseAuthentication();

Should look something like this…

Now that we have the startup code set, we now need to add a WebApi Controller. Within the controller folder I removed the one that’s generated with the project and added my own which I called MassagesController. I then added the following code..

As you can see above, the controller simply replies back with “This is a test”. Which this controller in place, we can now run the code to see if we can test the bot. Now in order to test the bot, we need to download a utility Microsoft has provided call the Bot Framework Enulator, which can be download from GitHub here. Once that is install, simply run the app by clicking the play button…

As the app runs, look at the Application Output to see the url and port number the bot is being run on. Plug that url in into the Bot Framework Emulator, along with the App ID and App Password…

Now let take this on a test run. Once running, type in anything and lets see if our bot responses…

Success!!! But wait, what about debugging? We’ll we are using Visual Studio, so let put a break point in the MessagesController.cs within the Post method and see if you can debug this puppy…

Apparently debugging is not a problem and we can easily see all of the activity properties as we would expect.

So in conclusion, not only can I build and run the bot framwork on a mac, but using Visual Studio for Mac, I also have a rich debugging experience. What more can you ask for? Well… how about running this in a Docker container? I’ll save that for my next post. Cheers!

Archives

Categories

Related Posts

This is a quick reference for registering a bot in Azure. First, log into the Azure portal and in the search type in “Bot Channels Registrations”… The next page (blade) will have you enter a Read more…