Wednesday, 19 October 2016

Talking about Bots – Setting it up

Have you thought about using the Microsoft Bot Framework?  I have!  If you’ve ever wondered, I’m going to try and give you a hand up by pointing you in the right direction.  Maybe give you a few tips along the way and help clarify a few things along the path.

Getting Started

connector-getstarted-create-projectYour first step is to install the Bot Framework Template into your Visual Studio (I’m assuming you have Visual Studio installed already).  I guess the first step is to decide what language you are going to build in.  Because I am a Windows Platform sort of guy, I’m going to use C#, if you are too then it will make this a lot easier to follow along.  You can find the “Getting Started” page with the links at https://docs.botframework.com/en-us/csharp/builder/sdkreference/gettingstarted.html but you can directly download the template from here.  When you look at the getting started document, it does give you most of what you need to get going but ultimately you are going to have to connect a few dots and turn on a few lightbulbs on to get to where you want to go.  Once you have downloaded the template and created your first project, come back here for next steps (not in the above doc)

Creating Your Bot App

Your next step requires you to create a Bot in the Bot Framework.  You are going to have to modify a couple of things in your just created Bot Framework app in Visual Studio based on what you do here.  First, go to http://dev.botframework.com.  You will need to have a Microsoft Id to successful complete this next task.  Click on “Register a bot” to get started.  Don’t worry if you don’t know everything, you can fake it a little bit until you do some other stuff later.  You need to know your bot name and bot handle.  You can makeup stuff here.  You will need to create a BotWebConfigMicrosoft App ID and password, but they nicely give you a button you can press to do that.  Make a note of the App ID and password because you’ll need those in the Web.config file of your bot application.  For the publisher profile, you can fill in most of the URLs with placeholders, but you will need to provide those before going live in any way.  In your Web.config, put the id and password as you see in this picture.  There are security issues with putting ids and passwords in your Web.config but for just playing around locally on your system, its not a problem and security is not part of this post.

Testing Your Bot Locally

Bot EmulatorYou need to install the Microsoft Bot Framework Channel Emulator.  It won’t look as pretty but it will let you see what is going on.  Once you have installed this little emulator, go ahead and start the app in Visual Studio.  This should launch a browser (you can choose which one), make note of the port # in the URL that is loaded.  Now open the emulator and change the “Bot Url” to match the port number above.  Don’t change anything else.  Lastly, paste in the App Id and App Password and you should be good to go.
In Visual Studio, open the “MessagesController.cs” file and put a breakpoint on line 22 (inside the “Post” method.  Now go back to the emulator and Type “Hello” into the message space and hit enter.  You can now step through how the bot responds to the question (it just parrots back what you said with a char count).  Now you can start seriously thinking about what smarts you want to add to your bot using whatever AI you can think of.

Ready for More?

Now that you have a (somewhat) stupid bot, what do you do?  Well, you’ll need to deploy it to an Azure App Service or some other web site if you want the public to get access to it.  You’ll also need to add some brains to it.  Like what happens when somebody says hello.  You know, add a little personality to the game.  More on that in future blogs.