Azure Bot Framework SDK
The course is part of this learning path
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.
- 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
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.
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.
Let's look at using dialogs to capture user data. In this lecture, we'll take a closer look at the underlying dialog infrastructure. You'll get a deeper understanding of prompt dialogs. And finally, you'll see how to use a waterfall dialog to collect user data. So let's take a closer look at the dialog infrastructure within the Bot Framework SDK. Whilst you want to work directly with the dialog stack, it's important to understand this fundamental concept within the Bot Framework SDK.
The dialog stack contains information about all active dialogs. You could think of the dialog stack as a call stack for each dialogue to be run. When working with dialogs and manipulating the dialogs stack, you can perform several operations to let you construct logic that models the conversations that you wish to create. You can add dialogs, start a dialog, end a dialog, continue a dialog or even repeat a dialog. Under the hood, the following objects make this possible, dialog set, dialog context, dialog instance and dialog turn result.
A dialog set defines a collection of dialogs that reference in working unison. The dialog context contains information about all active dialogs. The dialog instance contains information about one active dialog. The dialog turn result contains information from an active or recently active dialog. After dialog has ended, this class contains a return value. You don't typically need to work directly with this objects, but it's good to have an awareness of them and their purpose when building chart boards.
Let's dig deeper and see some of the key types of dialog that'll form the Bot Framework SDK in dialog library. The Bot Framework SDK dialog library provides you with several types of dialog to make conversations easier to build and maintain. Setting at the top of the hierarchy is the dialog class. This is the base class for all dialogs, a level below the dialog class is the container dialog. This is the base class for all container dialogs. This class allows you to treat a collection of dialogs as a single entity.
Component dialog is a general purpose tape of container dialog. This is one of the most useful as you can use this to create your own custom dialog, which inherit it from this class. For example, in green, we can see a custom dialog called user profile dialog. This inherits from the tape, component dialog. We've touched on the waterfall dialog earlier as well. This is a dialog that lets you guide the user through a linear process with multiple steps.
In general, waterfall dialogs are often used in conjunction within the context of a component dialog. So we've just touched on prompt dialogs. Prompts are another tool with a dialog library that you can use to help you create prompts and messages to capture user information, use the text prompt to ask for general text input. The confirmation prompt, lets you ask the user to confirm a choice such as yes or no that's prompt will then return boolean value if you get to work with.
The number prompt lets you prompt the user for a number, as prompt returns a number for you at the end process. The choice prompt presents the user with a set of options to pick from, the data returned from this prompt or container selection for you to work with. Here's the data time prompt to ask the user for a date time, the prompt then returns the data time for you to process. The attachment prompt, lets you ask the user to supply one or more file attachments.
Data captured from this prompt is in the form of a collection of file attachments, you can control how prompt dialog will be presented to a user by setting properties in their prompt options parameter. The prompt property contains the text that will initially be displayed in the prompt. The retry prompt defines the texts to send to the user at the initial input did not pass validation. The choices property contains a list of choices for the user to select from. This property is only used with the choice prompt.
Additional prompt options include validations. These contain a list of the parameters you can configure to set up custom validation rules against the prompt. The style property lets you define how choices within a choice prompt both confirmed prompt will be displayed. Use this property to display a list of choices in a numbered list or a collection of buttons, for example.
So it's time to look at a demo. And this demo we'll see how to implement some of the concepts in a custom dialog that can capture user information. This information will be captured as part of a sequence of waterfall steps. The chat bot will then echo by each part of information that was captured as part of the waterfall steps. So we're embarked in visual studio, let's chart what we'll collect the person's name, address, and phone number. To capture and represent this information, we have a class here called user details state data this information will then be output in the summaries step.
The first thing that we do is we define an array of waterfall steps. So if we jump out into the user profile dialog, that's what we can see here, accustomed dialog, user profile dialog inherits from the component dialog that's gives us access to some other methods. One of these methods is add dialog method. We use this to add the waterfall dialog with the associated steps. A custom dialog will be captured in text and integer values. So we add a text prompt and a number prompt to the collection of dialogs.
Finally, we set the initial dialog to run, which is our waterfall dialog. So we've just looked at the set of these involved. But what about the chord in each of the waterfall steps? The first waterfall step captures the person's name. Last, what we can see here name step async. Here we can reassemble text prompt asking the user what their name is, not the prompt options property and the prompt text, please enter your name.
The next step to run captures the person's address, that's what we can see here, in the step address, step async and the important thing to point out first is that we take the value that was emperor from the previous step and assign it to a variable that's what we can see here. We then send a text prompt to the user, asking them for their address. The process is similar when capturing the user's phone number. Here, we take the value that was supplied in the previous step, address and assign it to a variable. We then send a number prompt asking the person for their phone number.
The final step is the summary step, first we take the input from the previous step, phone number. We create up a user profile object in state to store the data. We then take all previous values from each of the steps in the waterfall dialog and assign them to properties and the user object. We then send this information in a text prompt back to the user. And finally, we end the dialog. We can run this chat bot by clicking run in visual studio.
With the welcome screen at the chat bot available we can now run the emulator and connect to it. Will supply greeting message, along with each piece of required information for each step, we can see that the information supplied in each waterfall step has been captured and sent back to us here. In this demo, we've seen how to create a custom dialog that inherits from the component dialog. We've seen how to create a waterfall dialog that contains a number of steps that help either user through a linear conversation. We've also seen how to reference data from each of the previous steps.
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.