In this chapter, we learn how to design Azure chatbots. We start with an introduction to the Microsoft Bot Framework and examine the start-to-finish workings of chatbots and the requirements necessary for creating Azure chatbots. Last, we look at a real implementation of an Azure chatbot.
Introduction to the Microsoft Bot Framework
In 2016, Microsoft released Bot Framework to develop intelligent applications. This framework was designed to be used for customized development and deployment in channels such as Skype, Facebook Messenger, and Telegram. Bot Framework has many advantages and its services communicate easily with different applications. Skype–Cortana integration (the best example) is used to gather information such as news, weather, tips, and tricks. Using the Microsoft Bot Framework, real-time functionalities, such as booking a hotel and ordering food online, and FAQ readers are developed using communication channels such as Skype, Slack, e-mail, and GroupMe. With the help of bots, it is easy to connect across platforms and go serverless.
Let’s now look at some of the benefits of the Microsoft Bot Framework.
Accelerated Development
Using the Microsoft Bot Framework, you can build, connect, deploy, and manage intelligent chatbots that interact with users through web sites, mobile apps, Cortana, Microsoft Teams, Skype, Slack, Facebook Messenger, and more.
Azure Bot Service provides developers with an integrated environment for chatbot development using Microsoft Bot Framework connectors and bot-builder SDKs. With such functionality, developers can use out-of-the-box templates, such as forms, in business scenarios; and language, questions, and answers can be used for user engagement.
Creation of Intelligent Bots with Cognitive Services
You can build a bot that recognizes users in photos, moderates user content, provides smart recommendations, translates languages, and more. Cognitive Services facilitates your bot in seeing, hearing, understanding, and interpreting in a human way.
User Engagement
Chapter 2 described the integration of chatbots with business applications. Our objective behind the integration of chatbots with other applications is to demonstrate the convenience of an Azure chatbot. A high level of coding is not necessary. Using the standard services available in Azure Portal, integration is easy to achieve.
Cognitive Services: Introduction
Because we are focusing on Azure technology, let’s take a look at what Azure Cognitive Services offers. Azure Cognitive Services includes APIs, SDKs, and other services that help developers build intelligent applications without being connected to AI, big data, or background knowledge. Azure Cognitive Services enhances Microsoft machine learning techniques and enables developers to create intelligent applications by adding cognitive features such as emotions, speech and vision recognition, facial interpretation, video detection, and speech and language understanding into their applications. The ultimate goal of Azure Cognitive Services is to help developers build smart applications that can see, speak, hear, understand, interpret, and reason. The following lists the different categories of Azure’s vision, speech, language, search, and knowledge APIs.
Computer vision: Provides access to process images by the system and returns the correct image or information.
Custom vision service : Builds custom image classifiers.
Content moderator: Helps to monitor and track possible offensive, undesirable content and virus attacks.
Face API: Accesses advanced face algorithms and enables functionalities such as facial detection and recognition.
Emotion API: Accepts an image as an input and provides output (such as anger, fear, shame, surprise, and others) across a set of emotions for each face in the image.
Video indexer: Enables developers to pull insights from video.
Speech service : Adds speech-enabled features to applications.
Custom speech service : Creates customized language models and acoustic models compatible with your application and users.
Bing Speech API : Searches content using speech.
Translator speech : Performs language translation.
Speaker recognition : Allows identification and verification of speakers based on algorithms.
Bing Spell Check : Performs contextual grammar and spell checking.
Language understanding service (LUIS) : Allows your application to understand what a person wants in their own words.
Linguistic analysis : Provides NLP tools to identify text structure.
Text analytics : Provides NLP for raw text to perform sentiment analysis, key phrase extraction, and language detection.
Translator text : Provides machine-based text translation in close to real time.
Web language model : Allows for NLP word prediction, sequencing, completion, and breaking strings of word without spaces.
Bing News Search : Returns a list of news articles relevant to a user’s query.
Bing Video Search : Returns a list of videos relevant to a user’s query.
Bing Web Search : Returns a list of search results relevant to a user’s query.
Bing Autosuggest : Allows you to send a partial search query to Bing and prepopulates suggested queries.
Bing Custom Search : Allows you to create custom search experiences.
Bing Entity Search : Returns information about entities relevant to a user’s query.
Bing Image Search : Returns a display of images relevant to a user’s query.
Bing Visual Search : Returns insights about images, such as visually similar images and shopping sources for products found in the image.
Custom decision service : Helps to create intelligent systems for contextual decision making, personalizing and optimizing the user experience.
QnA Maker : Allows you to create a question-and-answer service from your semistructured content.
Chinese
English
French
German
Italian
Japanese
Korean
Portuguese
Spanish
Different Types of Chatbots Using Azure Bot Service
Azure Bot Service provides different types of bot services that help create and deploy chatbots for specific business scenarios. In this section, we examine the background workings of different chatbots, such as commerce, information, knowledge, enterprise, Cortana, and IoT chatbots.
Commerce Chatbots
- 1.
The customer accesses their mobile app.
- 2.
User authentication occurs using the business-to-consumer (B2C) Azure Active Directory.
- 3.
Using the bot, the user requests information.
- 4.
Cognitive Services processes the natural language request.
- 5.
The response is reviewed by the customer, who has the option to refine information.
- 6.
When the user is satisfied, the chatbot pushes the order through for delivery.
- 7.
Azure Application Insights captures personas.
Note
Personas are virtual trends or views of users who have accessed AI-enabled services. They are stored temporarily in the system. For example, a user from India asks a chatbot to provide a list of all United Nations presidents. This view is stored in the system as a persona. If some other user asks a similar question related to the United Nations, then the chatbot first references personas to find a quick answer before querying the database.
Information Chatbots
- 1.
A user accesses their device.
- 2.
The Azure Active Directory authenticates the user.
- 3.
The user posts a query inside the chatbot.
- 4.
Cognitive Services returns a FAQ created using QnA Maker .
- 5.
A user defines a valid search string if the FAQ is irrelevant.
- 6.
The chatbot processes the query and submits the query to Azure Search, which returns information based on available data.
- 7.
Application Insights captures the user personas.
Enterprise Chatbots
- 1.
A user accesses the enterprise’s productivity chatbot.
- 2.
Azure Active Directory authenticates the user’s identity.
- 3.
The chatbot queries Office 365 Calendar using Azure Graph.
- 4.
Using data collected from the calendar, the chatbot accesses information in another system (for example, Microsoft Dynamics CRM ).
- 5.
Information is returned to the user.
- 6.
Application Insights tracks user personas in the organization.
Cortana Chatbot
- 1.
A user access a Cortana chatbot from their device.
- 2.
Using text or voice request, Cortana processes the request.
- 3.
Because of the integration of Cortana with a calendar, conflicts are checked before scheduling an appointment.
- 4.
The chatbot sends a query to the auto service representative regarding available appointment times.
- 5.
The user chooses the appointment time and sends a confirmation.
- 6.
Application Insights analyzes future developments for the Cortana chatbot.
IoT Chatbots
- 1.
A user logs in to Skype and accesses the IoT chatbot.
- 2.
Using voice or text commands, the user requests the IoT chatbot to turn on the lights in their home.
- 3.
The request is transmitted to a third-party service that has access to the IoT device.
- 4.
The request is shared with the user.
- 5.
Application Insights identifies user patterns and generates new ideas for developing IoT chatbots.
IoT chatbots are so simple that users can use channels such as Skype or Slack as chatbots to interact with home devices, as just described.
Designing Chatbots
As we have seen so far in this chapter, the Microsoft Bot Framework allows users to create innovative chatbots to resolve business problems. In the following sections, we look at how to design chatbots that align with best practices and lessons learned.
If you are designing a chatbot, this means you are designing for all people who will be using it. Chatbots can be used over mobile apps, web sites, phone calls, and e-mail, so you need to put in your best effort to make them usable by people over other services they have. The goal of designing a chatbot is to attract users and continue the momentum of its use. To achieve this, it is important to set business goals and identify the precise factors for the chatbot being developed.
Chatbots should resolve user problems with a minimal number of steps (in other words, minimal user interactions between the bot and the user).
Priority should be given to resolve problems better, easier, and faster to produce a good user experience.
Chatbots should be integrated with frequently used applications or platforms.
Chatbots should be easy to find.
None of these factors is linked to the intelligence of the chatbot or the cognitive services with which the chatbot is enabled. From a user perspective, as long as the problem is resolved with a minimal number of steps and it delivers a good user experience, users do not care about the technicalities of a chatbot. A great chatbot user experience does not require users to type too much, talk too much, repeat themselves, or explain things the chatbot should know. The process of designing a successful chatbot can be compared with successful web sites or mobile apps that improve through lessons learned and user feedback; the same applies to chatbots.
Some Factors Do Not Guarantee Bot Success
The intelligence of the bot: Not all chatbots are designed with cognitive services such as sound, text, image, and others, and many bots have little advanced machine learning or natural language capabilities. A chatbot may include these capabilities if it is designed to resolve business problems. However, there is no link between chatbot intelligence and user adoption of the chatbot.
Best vocabulary: The chatbot you design may have the best vocabulary or the ability to engage users in useful conversation or jokes, but unless it addresses business problems, these capabilities have less importance. Some chatbots have no conversational capability but still produce a great user experience.
Cognitive experience: You need to be careful when considering a cognitive experience with, for example, voice recognition. Sometimes this capability is frustrating for users. Therefore, think of business problems, then think twice about whether voice recognition will resolve those problems. Otherwise, a great user experience is not necessarily one that creates a chatbot that produces “noise,” which may disturb users and groups of users.
The First Impression of a Chatbot Really Matters
When we develop a mobile app, the first user interface we think of showing to users is a menu as soon as they open a mobile app. From there, they navigate to different places in the app. Intuitively, looking at the user interface, users understand different areas, such as the About Us page, team details, downloading, privacy policy, and others. When we develop a chatbot, we need to think similarly. Let’s look at a couple chatbot user interfaces.
Thin
Pan
Double
Vegetarian
Chicken
Meat
And so on. Posing specific questions takes users to destinations and produces a better user experience. Another important aspect: If your chatbot collects personal data, the chatbot user interface should have a privacy policy and inform users for what purpose and in what manner their data will be used.
Conversation Flow
In general, web sites or mobile apps have multiple user interfaces that are nothing but multiple screens. These user interfaces are connected with each other and, based on input provided in the user interface, redirection to another user interface takes place. Mostly, web sites or mobile apps have one main screen where all navigation links to other user interfaces are present, or users are asked to enter some other input before being redirected to an alternate screen. User interfaces consist of visually appealing designs and colors. To conclude, web sites and mobile apps contain user interfaces that need to be designed meticulously so that users do not get confused while navigating to different links. In addition, they should be able to reach the home page from any other user interface.
Similarly, chatbots also have multiple user interfaces, with one being the main user interface, similar to web sites and mobile apps. But user interfaces in chatbots contain dialog so the user can interact with the chatbot. Dialog can instruct users to take action before they get their results. The chatbot user interface could be plain text, with dialog to links or images, or it could be an input form where users are forced to enter information to get output.
Dialogs help developers to separate various scenarios and build user interfaces for each corresponding scenario. For example, developers can create a different dialog for users to choose their type of pizza crust and another dialog for users to make a payment after order confirmation.
In Figure 3-9, we see the traditional app’s main screen invokes a New Order user interface, which remains in control until it is either closed or invokes another user interface. When the New Order user interface is closed, the user is redirected to the main screen. The user has to navigate multiple user interfaces.
With a chatbot, everything begins with the root dialog. The root dialog invokes the New Order dialog. The New Order dialog is in control until it invokes other dialog or closes it. If the New Order dialog closes, then control of the conversation is returned to the root dialog. The user interface stays the same even if the flow of information is the same as in the web app.
Dialog Stack
A dialog stack is when one dialog invokes another; the chatbot builder adds new dialog to the stack of dialogs. Dialog set at the top of the stack is in control of the conversation with the user. Every new message sent by the user during a conversation is processed by dialog, which is at the top of the stack until it is closed or redirects to another dialog. After the dialog is closed, it is removed from the stack and returns to the previous dialog in the stack, which takes control. Understanding the concept of how a dialog stack is constructed and deconstructed by the chatbot builder is important.
Dialogs, Stacks, and Humans
Force the user to answer the first question.
Attempt to solve the user’s question and then move back to yes/no question.
Disregard all previous dialog, reset the entire dialog stack, and start from the beginning.
There is no right answer to this question. The best solution to this kind of situation is related to the scenario and the way the user expects the chatbot to respond. As conversation becomes complex, managing dialog stacks becomes complex. For complex branching situations, it is easy to create a logical flow to keep track of user conversations.
Design Bot Navigation
How does the user navigate backward and forward during a conversation?
How can the user cancel the operation (such as a request for nearby hotels, for example) during a conversation?
How you can ensure the user does not “get lost” during the conversation?
How can the user access the main menu (if there is one) during a conversation?
- 1.
The stubborn chatbot
- 2.
The clueless chatbot
- 3.
The mysterious chatbot
- 4.
The Captain Obvious chatbot
- 5.
The unforgetting chatbot
The Stubborn Chatbot
To handle this type of situation, know that users can move out of context at any time. If chatbots ask the same question repeatedly when users move out of context, the chatbot is not called a “smart” bot. There is a good chance the user’s frustration level will increase and lead to a bad user experience.
The Clueless Chatbot
Ideally, we want to design chatbots to cover all possibilities, but this is close to impossible because we cannot predetermine user behavior. In the scenario presented in Figure 3-12, we can make use of middleware functionality, which logs every message and query in external data sources. By defining the logic in the middleware, we make information accessible to every exchange with the user.
The Mysterious Chatbot
The chatbot could be in an outage state or could be compiling the user request. Both situations produce a poor user experience. Therefore, it is important to indicate to the user that the chatbot is processing input. This can be sent in the form of an acknowledgment message or a graphic that indicates user input is being compiled.
The Captain Obvious Chabot
Design your chatbot to provide useful information so that users engage and receive a better user experience.
The Unforgetting Chatbot
It is important to maintain the flow of the current conversation to reduce user confusion and frustration, and to increase the chance of users engaging in conversation with the chatbot.
Summary
With this, we come to the end of this chapter. Before moving to the next one, let’s look at what we learned. We started with a down-to-earth introduction of the Microsoft Bot Framework and Azure Cognitive Services, looked at the beginning-to-end workings of Azure chatbots, saw different types of Azure chatbots (such as commerce, information, enterprise, and IoT chatbots) and, last, studied chatbot design and design challenges