Tuesday 14 February 2017

An introduction to the Microsoft Bot Framework



Today was Day One of the Microsoft Ignite Australia event held in sunny Gold Coast that 2 of my colleagues & I got the chance to attend.

I loved the sessions around the Microsoft Cognitive Services & the Microsoft Bot Framework which inspired me to write my first bot.

What are bots?

Bots are simply applications that perform automated tasks. A simple example is a chatbot. An interesting example of such a bot is "Dom the pizza bot". Instead of calling up or ordering online, customers will be able to simply message Dom, the Domino’s pizza bot, and request food with a single world or emoji.


Even Cortana or Siri are example of such bots. Clearly showing how bots are the way of the future!

How do these bots communicate you ask?

Most use-cases for bots include instances where bots are communicating with users & providing insights without any specific human intervention. 

The medium through which these bots communicate are called "Channel(s)". 

At the time of writing this article, the following channels are supported by the Microsoft Bot Framework:
  1. Skype (auto-configured)
  2. Microsoft Teams
  3. Web Chat (auto-configured, embeddable)
  4. Direct Line (API to host your bot in your app)
  5. Office 365 mail
  6. Facebook Messenger
  7. GroupMe
  8. Kik
  9. Slack
  10. SMS via Twilio
  11. Telegram

Make sure to look at the live list here.

What can I do with these bots?

When you combine the power of using the Microsoft Bot Framework via the aforementioned channels AND Microsoft's Cognitive Services APIs, you can make some really kick a$$ bots.

FYI, if you haven't heard of Microsoft's Cognitive Services, they're some super funky APIs and services available to developers to make their applications more intelligent, engaging and discoverable. 

Microsoft Cognitive Services expands on Microsoft’s evolving portfolio of machine learning APIs and enables developers to easily add intelligent features – such as emotion and video detection; facial, speech and vision recognition; and speech and language understanding – into their applications. Check this out for more info. https://www.microsoft.com/cognitive-services/en-us/documentation.


Your first bot

So to begin with, you can build a super simple greeting bot. You say hello, and it greets you back. Begin by logging into azure and creating a new Bot Service.

Click the + icon & search for "Bot Service"

Click "Create"

Add an "App name" & select or add a "Resource Group" and click "Create"
Now remember, unless you selected the option to "Pin to dashboard" your bot will not appear on your dashboard. As you can see that I forgot to pin it, I should be able to view my bot in my notifications. Click the notifications icon (highlighted in red) & then click the relevant notification.


In order to authenticate your bot with the Bot Framework, you'll need to register your application and generate an App ID and password. 

Click the button to "Create Microsoft App ID and password"
This should open up a new window that helps you generate an App ID and password.
Click the "Generate an app password to continue" button

A new popup with your password will now appear. REMEMBER TO COPY THIS PASSWORD SOMEWHERE.

You can now click the "Finish and go back to Bot Framework" button
When you go back, your App ID will be pre-filled & you will need to paste your password in the relevant slot.

Remember to paste your password in


You now get to choose a language for your bot. My C#'s a tad better than my node but to show you show simple this really is, I'm choosing NodeJS. Use the "Basic" template to create a bot. Remember to click the "Create Bot" button at the bottom of the page.

Choose "NodeJS" and select the "Basic" template and click "Create Bot" at the bottom of the page

Your bot will be created in a few .. (ok quick, 1 min dance party https://youtu.be/ULC2C3VjO-o)





Once your bot is created, it should spit out the templated code. You should already be able to play with the templated code in the chat window. I have highlighted a key method here. 



You can be as silly and creative as you'd like.


Select channels to add it to one of the available channels. I'm going to add it to my Microsoft Teams.

Check out the available channels and add the ones you want by clicking "Add"

Add it to teams if you want



When you're ready, you can go to public with your bot, by navigating to settings and adding your bot details.


You can then navigate to publish and add the necessary details if you'd like to publish your bot.


Your bot

You can also navigate to the Microsoft Bot Framework dev site & view your bots here:

Log in with your standard credentials & click "My Bots"







My bot in action

By clicking the "Add to Skype" button this should open your Skype. Here's the bot in action on skype.





Easy-peasy huh? If you'd like to know more I've to some more useful links for you here:
https://app.pluralsight.com/library/courses/microsoft-bot-framework-getting-started/table-of-contents