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

Dialogs, Triggers, Prompts, and State

Start course
Overview
Difficulty
Intermediate
Duration
59m
Students
40
Ratings
5/5
starstarstarstarstar
Description

This course shows you the fundamentals of how to create, test, troubleshoot, and publish chatbots using the Microsoft Bot Framework Composer. You’ll learn about dialogs, triggers, and prompts and how these can be used to model conversational logic in your chatbots. We'll cover how to work with state and variables before moving on to how to control chatbot output by using language generation and how to implement adaptive cards to create rich user experiences.

Then we'll explore how the Bot Framework Emulator, Webchat Window, Watch Window, and Application Insights can be used to debug your chatbot. Finally, we'll show you how to get your chatbot published on Azure and how to test your chatbot using the Azure Portal.

Learning Objectives

  • Use Bot Framework Composer to create chatbots
  • Implement dialogs and maintain state
  • Implement logging for a bot conversation
  • Implement prompts for user input
  • Troubleshoot a conversational bot
  • Add language generation for a response
  • Design and implement adaptive cards
  • Test and publish a chatbot 

Intended Audience

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

Prerequisites

To get the most out of this course, you should have:

  • Intermediate knowledge of coding techniques
  • Familiarity with Azure concepts such as App Service and resources
  • An understanding of JSON
Transcript

Let's look at an overview of dialogues, triggers, prompts, and state. In this lecture, we're going to introduce dialogues and triggers. You'll learn about prompts and how they can be used to capture information in your chat bot. You'll learn about state management features and variables. And finally, we'll see a demo of a chat bot that asks and processes user input.

Let's look at dialogues and triggers. A chat bot consists of several components. You can think of dialogue as being the building blocks of your conversational logic. For example, one dialogue may contain all the questions, responses and answers for the processing of a customer data. Dialogues also control how your chat bot will handle respond to a user. Dialogues are also where you're modeling create your chat core functionality and that also where you place the business logic and decision making for your chat bot.

Some of the main features of dialogues within bot framework composer include, the concept of a main dialogue and related child dialogues, support from multiple dialogues within your chat bot, functionality to let dialogues invoke other dialogues and easy way to add multiple prompts to collect user information or invoke actions, standard entry and exit points. The key features that we've just looked at, mean that dialogues are a great way to encapsulate the conversational logic in your chat bot. All dialogue functionality is hosted in what's known as a trigger.

A dialogue can contain multiple triggers. Triggers define how your chat bot will process incoming requests from a user. You can think of a trigger as an event handler. When the event is raised, one or more actions are executed. Actions are the instructions that your chat bot will process. You can think of actions as the individual steps or lines of code within your dialogue. For example, the begin dialogue event is a type of trigger you can choose to implement. You may add an action to send a greeting message to the user.

Your chat bot can support multiple types of trigger. Intent triggers can be used to handle events admitted by the recognizer you have configured in your chat bot. Use this trigger if you want to identify the underlying intent and associated entities with the natural language process capabilities of your chat box. The best type of trigger is called the dialogue trigger. For example, most of the dialogues you create will be configured to handle the begin dialogue event trigger. The begin dialogue event fires when the dialogue begins. You can use this event to take immediate action, send messages, process data and much more.

Activity triggers are used to handle events such as when a user joins a conversation. You can also use activity triggers to identify events like when a conversation has ended, when a message has been received, or if a typing indicator is being rendered by the chat bot. A useful feature you can implement when building your chat bot is to raise a custom event. Custom event trigger lets you listen for any events that you add to your chat bot logic. After catching the event, you can then run additional business logic. One example of this might be redirecting the conversation to a completely different dialogue based on a defined business rule. 

We can see an example of a dialogue event trigger here. The dialogue get user info has been set up to contain some logic and they begin dialogue event trigger. The begin dialogue event is the very first event that runs for any additional logic you're creating bot framework composer. After the begin dialogue event is run, the user is imprompted for their name, the value is installed in a variable.

Let's take a closer look at prompts and how these can be used in bot framework composer to help you collect information from users. Bot framework composer provides you with different types of input controls to collect information from users, these are known as prompts. 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. This prompt then returns a billion value for you to work with. The number prompt prompts the user for a number. This prompt then returns a number for you to process.

The choice prompt presents the user with a set of options to pick from. The selected option is then made available for you to process. The date time prompt asks the user to specify a date and time. The prompt then returns a date and time for you to process. The attachment prompt lets you ask the user for one or more file attachments. The file attachments are then made available as a collection of attachment objects for you to process.

The main purpose of prompts is to let your chat bot collect information from users. But you can also use prompts to validate user input. For example, by sharing a string is less than a certain number of characters. You can't always guarantee that people will enter that with your chat bot the way that you expect them to. You can use prompts to help disambiguate user intent by asking clarifying questions to better understand the action a person is trying to perform.

Using the right type of prompt at the right time in a conversation can also improve the user experience of your chat bot. Here we can see a text prompt in the designer canvas. This text prompt has been configured to prompt the user for a username to find. The text for this is set in the bot response section of the properties page. That's what we can see here. One thing to call out is that you can add multiple response types. The bot framework run team will randomly select a response. This can give your chat bot more personality. The information that is captured in this prompt is stored in a variable dialogue username.

Here we can see the prompt from the earlier slide. This time however, the other top has been selected and the validation menu has been expanded. We can see a validation rule here. This validation rule, uses the length and strength functions to evaluate if the value supplied in the prompt is less than 10 characters. Prompts are a fundamental feature of the chat bot development process that you can expect to use when building chat bots using bot framework composer.

Let's learn more about state management features in chat bots with bot framework composer. So what does it mean to maintain state in your chat bot? A chat bot is a stateless solution. This means that once your chat bot is deployed it has no concept of saving data from one turn to the next. Fortunately you can access the bot framework SDK state management features directly in composure. Using these lets you create a stateful chat bot.

State management lets your chat bot store information about a conversation. This can include information supplied by the user. It can also include data generated or fetched by your chat bot. The most useful chat bot leverage state data for many reasons. Some of these include, referencing captured data later in a conversation, storing values used as part of a calculation. For example, calculating the total cost of a customer order.

State management features can also be used to store data fetched from a web service of third party system. For example, fetching customer records then performing a search against them, maintaining and storing state data helps you create more intelligent chat bots. State management scopes are split into long-term and short-term categories. Long term categories include settings, user and conversation state. Settings data is read only and contains bot settings data from system config.

User data is associated for the current user. This information does not expire through the context of a conversation. Conversation data is data associated with the current conversation. Data stored in this scope is only available for the lifetime of a conversation. You also have the option of using short term scopes. Use these when you need to store data for a discrete task. For example, performing a calculation within a dialogue. Short term categories include dialogue state, this state and the unturn state.

Dialogue scope associates data for the current active dialogue. When the dialogue ends, the data is gone. This scope associates data for the current action. Data in this scope expires when a turn ends. This scope is useful for input actions such as checking the length of a value. Data stored using turn scope associates data with the current turn. When the turn ends, the data is gone. Bot framework composer makes it simple for you to store multiple data types in memory using the state management features that we've just seen.

Use the long term and short term scopes to store. Integers, strings, arrays or even complex objects represented by JSON or XML. It's important to call out another feature of the bot framework SDK called adaptive expressions. Adaptive expressions are prebuilt functions that you can use in bot framework composer. These are a suite of functions that let you perform common developer tasks and help you manipulate data stored in variables in state.

Some of the categories include string manipulation, processing collections, math operations such as max and min, there are too many to mention here, but you can find out more information about these at the following URL. We can see an example of a dialogue that prompts the user for the name. The data is installed in a user scoped variable called name. The data is then read from state and echoed back to the user in a greeting.

We've covered quite a bit so far in this lecture so it's now time for a demo. In this demo, we'll create a simple chat bot that collects some user details. The information will then be echoed back to us. So here we can see we have bot framework composer open. This is the windows version that's being run in my local machine. First, we'll add a new dialogue to store a logic. The dialogue is added to the navigation window. Next we select the begin dialogue trigger. The designer canvas refreshes.

We can now start to add logic into the dialogue. Clicking on the plus icon, lets you select activities and actions to add. We'll add a prompt to ask the user for name. We'll store this information in a user scoped variable. We can send this information back to the user by clicking on the plus icon again and selecting send the response. Here we read the data back from state and set this as part of the response. We need to tailor a chat bot to invoke this new dialogue. We can do this by calling the begin dialogue event when a chat bot launches. Here we set the dialogue name CollectInfo.

Finally, we can run the chat bot by selecting start bot. With the chat bot running, we can access it in one of two ways. We can open using the inbuilt web chat feature of composer or we can test it using the bot framework emulator. We'll use the inbuilt web chat feature for quickness. We'll restart the conversation, and we're prompted for our name. After supplying our name, it's echoed back to us.

In this demo, we've seen how to create a simple chat bot that collects user information. We've seen how store this in the user scoped variable. And finally we've seen how this information could be echoed back to us. Next, we'll learn about language generation in cards.

About the Author
Avatar
Jamie Maguire
Software Architect, Developer, and Microsoft MVP (AI)
Students
99
Courses
2

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.