1. Home
  2. Training Library
  3. Microsoft Azure
  4. Courses
  5. Creating a Chatbot Using the Azure Bot Framework SDK

Overview of Chatbots and the Bot Framework SDK

Overview of Chatbots and the Bot Framework SDK
Overview
Difficulty
Intermediate
Duration
52m
Students
80
Ratings
4.2/5
starstarstarstarstar-border
Description

This course shows you the fundamentals of how to design, create, and test chatbots using the Azure Bot Framework SDK. You’ll learn about the Bot Framework SDK, the key components that form a chatbot, and how to use templates in Visual Studio to create chatbots.

We'll help you understand the importance of Turn Context and State Management and how these are used in chatbots with the Bot Framework SDK. We'll also cover the dialog library, different types of dialogs, and how you can use these to model conversational logic in your chatbots.

The course wraps up by showing you how to get your chatbot published in Azure and test your chatbot using the Azure Portal.

Learning Objectives

  • Using the Bot Framework SDK to create a chatbot
  • Implementing Dialogs and State Management
  • Testing chatbots using the Bot Framework Emulator
  • Deploying a chatbot to Azure
  • Testing a chatbot in Azure

Intended Audience

This course is intended for developers and software architects who want to learn more about the Bot Framework SDK and how it can be used to create conversational AI solutions in Microsoft Azure.

Prerequisites

Intermediate knowledge of C# is required for this course. You’ll also need to be familiar with Azure concepts such as App Service and Azure Key Vault, and be comfortable using Microsoft Visual Studio Community edition.

Transcript

Let's look at an overview of Chatbots and the Bot Framework SDK. In this lecture, we're going to discuss what chatbots are and how they work. We'll look at what the Bot Framework SDK is. We'll look at some of the key components that form a chatbot. We'll also introduce the Bot Framework Emulator and how this can be used to test and debug your chatbots. And finally, we'll see a Demo of a chatbot in action.

A chatbot is an application that you can interact with in a conversational fashion. Interacting with a chatbot can include different types of media, such as text, images, speech, and much more. Chatbots are made available in what are known as Channels. A Channel can be a website, apps such as Facebook messenger, Slack, or even the Telephony. Azure Bot Service is a cloud platform with a supporting Rest API that lets you host chatbots. It features support for many channels that include, but are not limited to websites, Microsoft Teams, Facebook messenger, and WhatsApp.

The Bot Framework Service is a component of the Azure Bot Service. It's responsible for sending data back and forth between a bot-connected app and the chatbot. Data sent between a bot-connected app and a chatbot is contained in an object known as an Activity. A conversation will result in many activities being sent. Channels within the Bot Framework Service can contain specific data unique to that channel. For example, data specific to the Facebook channel can include sending a Facebook notification.

Another example might be Microsoft Teams by mentioning a specific user name. We can see an example of how this hangs together here. In this example, we can see the website channel has been activated. The Azure Bot service accepts an incoming request from a website that contains a connection to the chatbot. After receiving a connection from the web chat channel, the Bot Framework Service release the request to the chatbot. The chatbot then responds back to the web chat on the website. So let's look at the Bot Framework SDK.

The Bot Framework SDK lets you build chatbots that can be hosted on Azure Bot Service. The SDK makes it simpler for you to enter that with the Rest API contained within the Azure Bot Service. It does this by creating a layer of obstruction between you and the Azure Bot Service Rest API. You don't really need to know too much about how the Rest API hangs together. An understanding of some of the concepts however, will make it simpler for you to work with the Bot Framework SDK.

One thing to be aware of is the features pervaded by the SDK and the Rest API vary by channel. Because of this, I strongly recommend testing your chatbot on any of the channels that you want to surface your chatbot on. Let's look at the main components that form a chatbot. Interactions between the user and the chatbot are represented an object known as an activity. These can represent text, speech, or reactions to other messages, and much more.

In conversations, people generally speak one at a time with each person taking their turn. This is no different when building chatbots. A user will send a message and then the bot will reply. Within the context of the Bot Framework SDK, a turn represents the user's incoming activity to the chatbot or any activity that the chatbot sends back to the user. For example, a user may ask a chatbot what the world is going to be like. The chatbot may respond with, "It's going to be sunny." It's at this point the turn would end.

The Adapter is responsible for handling connectivity and authentication with channels for your chatbot. It's also responsible for processing and directing incoming activities to your bot logic and back out again. The Activity Handler provides you with an Event-Driven Model to help you manage your chatbot logic. For example, you can override event handlers to automatically greet users when they first join a conversation.

Here, we can see a chatbot that implements the default activity handler. This chatbot is overriding two of the methods from the activity handler, On Message Activity Async and On Members Added Async. We can see in this override that a welcome message is being set. The welcome message is then sent to any new members that have joined the conversation. In this override, we can see that any activity sent by the user is echoed back to them.

Other important components that form the Bot Framework SDK includes State Accessors, Dialogs and the Bot Class itself. Chatbots often need to save and load State Data during each interaction. This is achieved by using Storage and Property Access or Classes. The SDK doesn't provide built-in storage of the bots, however, but it does provide you mechanisms to save and load state data into Memory Storage, Blob Storage, and Cosmos DB Partition Storage.

Memory storage is useful for testing and debugging purposes, but you shouldn't really use this for a production chatbot, however, as this data is cleared each time the chatbot is restarted. If you need to move your chatbot into production, I'd recommend leveraging Azure Blob Storage or Azure Cosmos DB Partition Storage. We'll cover State Management in-depth in the future lecture. Dialogs are one of the most important features and concepts in the Bot Framework SDK.

You can think of Dialogs as being the building blocks of your conversational logic. For example, one dialog may contain all the questions, responses, and answers for the processing of a customer order. The Bot Framework SDK contains a library with different types of dialog that make it easier for you to create a chatbot and manage conversations. One of the most important dialog types is the Waterfall Dialog. The Waterfall Dialog gets its name from the fact that a sequence of steps is defined that runs sequentially from top to bottom. This is a useful dialog as it allows your bot to walk a user through a linear process. You can think that more about all the other available dialogs by visiting docs.microsoft.com and searching for the term, Bot Framework SDK dialogs library.

Well, it's technically not a component of the Bot Framework SDK. When building a chatbot, you need a class to handle logic for each turn being processed. This is where implementing your custom chatbot class comes into play. You'll see an example of this in the next lecture. Let's look at the Bot Framework Emulator. So what is the Bot Framework Emulator? The Bot Framework Emulator is a desktop application that lets you test and debug your chatbots.

You can use the Bot Framework Emulator to debug chatbots on your local machine or a chatbot that may have been published to make yourself Azure. One thing to point out is that if you wish to debug a chatbot in production, you'll need to download a free tool called, Ngrok. Ngrok will forward messages from external bot framework channels on the internet directly to your local machine to allow you to debug it. When running the Bot Framework Emulator, you can enter that with your chatbot as if it were being hosted on the web chat channel.

Any messages that you send and receive are locked in JSON format for you to examine. We can see a screenshot of the Bot Framework Emulator in action here. Here, we can see the user responding to the chatbot greeting message. And over here, we can see the time that this message was sent. Selecting a message in the log opens up further in size in the inspector window. We can see that here.

Some of the key information in the inspector window includes the channel ID, emulator. We can also see who sent the message, user. And we can also see the recipient, but we've covered quite a bit so far in this lecture. So it's now time for a demo. In this demo, we'll see a sample chatbot in action. This example highlights some of the concepts that we've just been discussing, such as Activities, Turns, Waterfall Dialogs, Waterfall Steps, and Channels.

We'll use the Bot Framework Emulator to test this chatbot. We'll greet the chatbot and we'll then be asked for our name, age, and profile picture. The information will then be echoed back in the chat window. So here we can see what a Microsoft Visual Studio and we have the user profile dialog opened. Now this is a dialog that's responsible for collecting the name, age, and picture, from the person who's interacting with the chatbot. And these are the number of steps that form the Waterfall Dialog. And they collect the data from the user, one step at a time.

So right now, this chatbot is running and we can connect to it if we bring up the Bot Framework Emulator, which we have here. And we can restart a conversation with this chatbot. Now, it's expecting us to say "Hi." So now we're being asked for our name and then we're prompted with the confirmation prompt asking us, "Would we like to give an age?" We'd send "yes", please enter the age. And then we have the option of attaching a profile picture.

We can click on the paperclip here and we can then select the profile picture, so we will do that here. We can see the profile picture, it gets uploaded. We get a confirmation prompt that asks us if this image is okay and we can say, "Yes". And now, the chatbot has taken all that information through the activities that we've sent over. It's processed it and it's echoed back the content that we supplied here. So we can see here, we have three activities. The first one is, "I have your name as Jamie and your age is 41." The second activity says, "This is your profile picture." And then finally the chatbot has outputted the profile picture.

About the Author

Jamie Maguire is a Software Architect, Developer, Microsoft MVP (AI), and lifelong tech enthusiast with over 20 years of professional experience.

Jamie is passionate about using AI technologies to help advance systems in a wide range of organizations. 

He has collaborated on many projects including working with Twitter, National Geographic, and the University of Michigan. Jamie is a keen contributor to the technology community and has gained global recognition for articles he has written and software he has built. 

He is a STEM Ambassador and Code Club volunteer, inspiring interest at grassroots level. Jamie shares his story and expertise at speaking events, on social media, and through podcast interviews. 

He has co-authored a book with 16 fellow MVPs demonstrating how Microsoft AI can be used in the real world and regularly publishes material to encourage and promote the use of AI and .NET technologies.