Making a Smarter Bot
Many people consider chatbots to be the fourth application platform.
Originally, there were desktop applications where people interacted with heavy mainframes or databases on-premise. Web 2.0 changed the development paradigm. Everything was turned into a web application, so users were able to access applications without needing to install more than a browser. With the evolution of cell phones and tablets, people now have the ability to access their applications everywhere. Today, we’re developing bots that can understand people intuitively, and all on their own.
Bots can automate tasks, perform complex calculations, or suggest what movie is best to watch based on our logs or advice based on previous interactions with similar users. Bots can do more than chat - they can expand their capabilities to understand our voice and feelings and act based on that.
The Microsoft Bot Framework provides exactly what you need to build and connect intelligent bots that naturally interact with your users on a website, app, Cortana, Microsoft Teams, Skype, Slack, Facebook Messenger, and more.
Some common classes Bot Framework provides are:
Dialog: A dialog is a similar concept to a form. We can include it to reuse them across our code project or bots. For example, a dialog can ask to use a person’s full name, date of birth, address, etc. The bot validates the data and returns with a specific result.
WaterFall Dialog: This is a dialogue that’s optimized to ask the user a series of questions. The first step prompts the user to enter one's information, the second step keeps it and ask the next one, and so on. When the user finishes all the steps, the dialog will return to the calling point.
RichCards: As its name can tell us, we might use these classes to send the user rich media. For example — thumbnails, hero, carousel, video, audio, etc.
Adaptive Cards: This is an external library used to represent complex information cards. For example, a receipt or an n-columns’ card.
Build the Bot
We develop bots to help people in pre or post-sale moments. For example, providing more accurate suggestions based on that person’s previous purchases or interests. Let’s suppose a person makes an online appointment at a pet store. When they get to the “appointment confirmed” page, there are product suggestions like toys, treats, and food for their animal. These products are curated based on the person’s shopping habits both on the site itself and on the rest of the internet.
Planning
To get started on the right path, we might make a map for our bot with the same sections as the website and diagram how the user will navigate it. Let’s say that we start with a welcome message showing the user a menu prompt to choose what they want to do:
Search products and categories. Place an order. Pay the order.
Search for an article.
Check pet studies status (3rd party web app).
Check the doctor date (3rd party web service that requires authentication).
Developing
Each bullet item above is a level of dialog for our Bot. We can use WaterFall dialogs to ensure our code reusability and testability and to guide users in a series of task prompting to enter some information or make a decision.
Product Dialog
This dialog might ask the user whether they want to search by product or browse categories. To make sure the user experience is simple, we must present information pages with no more than 10 items per page in a carousel. Each item can be an AdaptiveCard showing product information, photos, price, and a button to add to their cart.
Once the user wants to place an order, we can ask them to login or create an account using a SignInCard. The user should be redirected to a web page in their browser to enter their credentials for our commerce site, then they will go back to bot with an authentication token we can use to interact with our Commerce Site. We then store that token in the user state so the user doesn’t have to enter their credentials every time we need to interact with an external service.
Articles Dialog
Similar to the product dialog, we might ask the user to search for a specific article or browse a category. We can present the articles using an HeroCard with a link to see the full article on our site.
Check Pet Studies Status
Once again, we may redirect our user to a web app, but we can’t control when they come back to our bot. We can assume they won’t continue using our bot and end our dialog stack. However, when the user returns to our bot it will start again from the main menu.
Appointment with a Veterinarian
Let’s suppose we already have an external service that allows us to interact with our veterinarian schedulers. We can query that 3rd party service to know when our user has an appointment, and confirm or decline this appointment to avoid our doctor's downtime. To do that, we must ask our users to log in to that service. Either through an external site, using a single sign-on solution, or with a custom login mechanism. We have to lead the user to the service to authenticate. Once authenticated, we can retrieve all of their appointments and store locally to remind them when their next appointment is.
Testing
To test our bot while we are developing it, we won’t need to deploy it to an external server. We can use the Bot Framework Emulator to locally test and debug whenever necessary. The emulator can be used to test bots running either locally on our machine or connect to bots running remotely through a tunnel.
Publishing
When our bot is done we can deploy it in our favorite web hosting environment. After that, we should connect to each channel we want to be present for our users. We can register it in Facebook Message, Cortana, and Skype to start with a wide audience and continue adding channels as we see fit.
Make Our Bot Smarter
We can improve our user’s experience by interpreting their needs. One way to do this is by replacing our old menu flow with a simple question to prompt our user.
Natural Language Processing
Knowing what a user wants with only one sentence is not easy. There is an infinite variety of possible sentences and structures. The framework makes our life much easier by providing a rich set of language services called Language Understanding or LUIS. We can use LUIS.AI to add powerful natural language processing without needing to make major changes in our bot’s code.
We can configure our bots dialog to send user input (which are referred to as “utterances”) to LUIS endpoints. LUIS analyzes the text and returns the user’s intent. For example, if a user enters “I want to see dog leashes.” LUIS will return “Browse Products” as the user’s intent. It will also tell us the product category entity the user wants to see is “leash” and the animal entity is “dog”. The same will occur if the user enters a variety of utterances:
Want to see a leash for my little dog.
Do you have any leash? For dogs.
Show me some doggy leash.
What are the prices for dog leashes?
LUIS is constantly learning from what users are entering. If a new sentence comes and it doesn’t know how to map the utterance to intent or an entity value, we can teach it to resolve this as we keep improving and training our bot to continue learning.
In the image below you can see how LUIS interprets our sample sentences, extracting the intent and the entity’s values.
Furthermore, we might have an intent for when a user wants to make an appointment with the doctor. LUIS has an excellent value recognizer for many common data types like date, time, places, and numbers. In this example it can use those recognizers to extract date and time values from the next sample sentences and return to our bot users intent and entity value:
Do you have any availability next Friday?
I need to see a veterinarian next week after lunch.
Is Dr. Stephens free tomorrow at 3.15?
I want to cancel my appointment on 3/15 at 4.30.
Image Recognition
We can integrate different types of image recognition to get more information about what happens with our user's pet. We can integrate our bot with Microsoft CustomVision services, allowing us to create a project with several images to train our model and publish it to use from our bot.
Given that veterinarians’ schedules are full, our user can’t make medical consultation as fast as their pet needs. They can take a picture of the pet’s illness, and we can try to identify it. To do this, we can ask our user to send an image to our bot and internally send to CustomVision and identify any illness. Based on what was detected, we can suggest articles to take special care of or, in critical cases, make an urgent appointment with the veterinarian.
Conclusion
As you can see in this article, bots can add value to our existing commerce and lead our products and services everywhere in a user-friendly manner. We can think of simple solutions like a call center level 1 attendee telling the user standard procedures to solve the user issue, and when needed transfer the call to a human being to resolve a more complex problem. Another example can be an appointment registration and reminder where we can speak to our bot assistance and it processes our speech and transforms that into text. Moreover, we can design a bot to talk to the user when she leaves the shopping cart checkout — asking whether needs help or any opinion, to try to convert a user into a sell.
Bots can efficiently integrate with other services to join efforts, make life easier, and help commerce grow. No matter what technology or platform they use, they are gaining commerce spaces where other applications were present in the past. Bots provide a rich user experience that users can afford.