Freigeben über


An introduction to the Microsoft Bot Framework

This article was originally published on the Microsoft UK Developers website.  

By Gary Pretty, Technical Strategist, Mando Group

It seems like bots are everywhere these days, with more and more popping up every day. From bots that help us tag people on Facebook to simple Twitter bots that respond to our tweets.

Essentially, a bot is an application that can automate repetitive tasks or serve information to a user and, more and more, can interact with a user using natural language. As these bots get more intelligent and better at understanding us, this is providing a wide spectrum of use cases for bots to be used by and assist almost everyone.

Microsoft is betting big on the chat bot revolution, with Satya Nadella once saying that bots would “fundamentally revolutionise” how we interact with machines, adding, “pretty much everyone today who is building applications, whether they be mobile apps or desktop apps or websites, will build bots as the new interface, where you have a human dialogue interface versus menus of the past”.

Sounds like something you might want to get in on the ground floor of right? To help with that Microsoft has the Bot Framework, a suite of tools and services that allow you to easily build bots yourself.

Bot Framework

The Bot Framework allows you to create bot applications which can respond to natural language input from end users, in the places where they are already having conversations. This can be places like Facebook, Skype, Slack and even SMS/text. Once you have a bot added to one of these services (or you have the phone number for the bot in the case of SMS), it is always online and you can send a message anytime and get an instant response.

There are 3 keys parts to the Bot Framework;

Bot Builder SDK

The SDK portion of the framework gives you what you need to make your bot application itself, with the choice of using C#, Node.js or a REST API. Independent of your choice of approach, the SDK provides various types of objects that you can use to construct and model your bot’s conversation with a user. For example, the Dialog object maps to some common conversational models that we use every day;

  • Asking the user a question and expecting a Yes/No response.
  • Asking the user a question and taking a simple string back.
  • Giving the user a choice from a pre-defined list of options, which can even take advantage of things like presenting a button for each choice on supported channels such as Facebook.
  • FormFlow – a type of Dialog that lets you create rich multi-stage and branched conversations, which can be used to achieve things like ordering a pizza. E.g. You might say “I would like a pizza”, to which the bot might respond, “No problem, what toppings would you like?”. You then say “ham and pepperoni” and the conversation continues until you have completed all of the required fields on the FormFlow dialog.

There is plenty of documentation and step by step instructions, along with the related downloads, over on the Microsoft Bot Framework site to get you started on your bot development journey, and the Bot Framework Channel Emulator is also available for you to test your bot locally or remotely.

Bot Framework Portal

The Portal is where you can register your bot and define which channels it is going to be made available through. By default, when you register a bot, the Skype and Web Chat channels are setup for you out of the box. Setting up additional channels like Slack or Facebook is super simple and the portal contains really good step by step instructions specific to each channel.

Bot Directory

The bot directory is where, if you wish, you can submit your bot and make it available to the world for people to install on available channels. Right now the directory is accepting submissions, but only some featured Microsoft bots are available to see publicly. They are nice examples of the sort of thing that can be achieved, so I would recommend checking them out.

A real world example

At Mando, we always love seeing how we can use emerging technology to make great user experiences. A couple of years ago when IoT was seeing wider adoption, we created a connected fridge to help us solve the problem of people not completing their timesheets on time. We took a fridge, put an Internet-connected magnet on the door and then integrated it with our timesheets system, meaning that if everyone completed their timesheets by 4pm on a Friday, the fridge unlocked and we all got a beer. It will come as no surprise that this was a huge success and the fridge opens like clockwork every Friday!

One problem we were left with was how people could check their own blocker status (someone who hasn’t completed their timesheets) and also see the list of other blockers so they could give them a nudge. Sure, we had built a great interface which was displayed on a screen above the fridge, but that didn’t help those people who were out of the office. When the Bot Framework was announced, we saw a great opportunity to solve this problem and make the whole system even more engaging.

We have now created a bot built on the Bot Framework which allows a user to ask questions related to the timesheet fridge, such as, “am I a blocker?” or “how many blockers are there right now?”. The bot will then query our existing timesheet system and present you with an answer. We chose to surface our bot in Slack, a collaboration tool we use internally, which as you can see from the screenshot below has allowed us to take advantage of things like buttons on that platform.

One of the things that we needed to ensure was that the bot responded to different queries and could understand the user’s intent. For example, if a user says “is Matt a blocker?” or “has Matt completed his timesheets?”, they are trying to get the same information – the timesheet completion status for Matt. This is where Microsoft’s Cognitive Services came in, namely the LUIS (Language Understanding Intelligence Service).

The LUIS service allows you to train a model so that you can take input from our bot and have it interpret the user’s likely intent and pass it back to you to take action on. This is all encapsulated into a special dialog called LUISDialog (or intentDialog in the case of Node.js) within which you can use attributes to trigger specific methods when a particular intent is detected. I won’t go into any more detail about that in this post but, again, there’s lots of documentation about this over at the Bot Framework website.

Summary

Hopefully you can see the potential with the Bot Framework, and after reading this article you are inspired to go and try out building a bot for yourself. Our Fridge Bot is just one example of many real world scenarios where you might want to create a bot. What about;

  • For businesses like hairdressing, allow users to book an appointment with a start time/finish time
  • Checking someone’s diary for availability and if they are free, book a meeting!
  • Allowing a customer to ask common questions about products on your web site

Have fun creating bots!

---

Gary is a Technical Strategist and Senior Developer at Mando in the UK. As part of his role, Gary is constantly looking at how emerging technologies can simplify complexity, build momentum and create business change for Mando’s customers. Gary is currently focused on the Bot Framework, Cognitive Services and Office 365. Gary blogs over at www.garypretty.co.uk and can be found @garypretty on Twitter.

Resources