1. Introduction

“Chatbot is everywhere”, that’s how present day is. Chatbot technology is applied to different domain to do different tasks. Chatbot works on social network, communication tool, or collaboration tool. But have you ever think about creating a chatbot for yourself?

“Chatbot is difficult” may be the impression that prevent you from taking the first step. You may imagine that, to create chatbot, a great effort to research is mandatory, a large amount of code is required.

Then, let Bot Framework Composer give you a different perspective. Bot Framework Composer is a tool to create chatbot visually using various built-in components to design conversation flow, integrate with 3rd party services, manage states and properties… without coding. Moreover, Bot Framework Composer can work directly with LUIS, an NLP service, to embed AI into chatbot even if you are inexperienced with AI.

Through this article, you will understand Bot Framework Composer by creating a simple chatbot with AI.

2. Setup

To setup Bot Framework Composer (or Composer in short), please follow document https://docs.microsoft.com/en-us/composer/setup-yarn

In short, you will need to install:

  • .NET Core SDK 3.1
  • Composer application (for Windows, macOS or Linux)
  • Bot Framework Emulator (for testing)
  • Node.js (12.13.0 or later)

Above required list may be updated when Composer update, so make sure to check on official document.

3. Create a simple chatbot

For demonstration, we are going to build a chatbot which help us view number of COVID cases in a certain country. Through this tutorial, you will understand how to construct a conversation, as well as using 3rd party API in Composer to create chatbot.

For COVID data source, we are going to use API from https://documenter.getpostman.com/view/10808728/SzS8rjbc

Let’s build the chatbot by creating a bot from scratch.

Next, create a new trigger for Bot.

Choose “Unknown intent” in trigger type box. Chatbot will route all conversation to this trigger since there is no other intent yet.

In first step of conversation, chatbot wants to introduce itself, so create “Send a response” component with an introduction message.

Next, chatbot asks for which country users want to view the number of cases. So create “Ask a question > Multi-choice” component.

In the prompt box, ask for country information and provide some choices for user to choose.

In “User Input” configuration:

  • In “Property” part, type in “conversation.country”. The result of user input will be saved in this variable.
  • In “List style” part, choose “suggestedAction” to view options as boxes.
  • In “Array of choices” part, choose “simple choices” and provide country options.

Next, to call 3rd API to get information, create “Access external resources > Send an HTTP request” component.

Configuration of HTTP component as below:

Now response is saved in conversation.result variable. Next chatbot will display the result.

Chatbot wants to display result as “There are {number of cases} in {name of country} country”. Name of country is already defined in conversation.country variable. Number of cases can be taken from the “Cases” attribute of last object in conversation.result (to understand response structure, you can view https://api.covid19api.com/total/dayone/country/vietnam/status/confirmed).

Create “Send a response” component with content as below:

“conversation.result.content” is the content of response. Wrap it with json() method to convert it to json. Then wrap it with last() method to take the last object. Finally, get the Cases attribute.At this time, chatbot has a fairly completed conversation. We can try to run the bot with Bot Emulator using “Start Bot” button. The conversation should be as below:

4. Integration with LUIS

(To do this part, you need to have an Azure account and LUIS service. To create LUIS service, please follow guideline in https://www.luis.ai/

After registered with LUIS, you will have an authoring key. We will need this key for later.)

Now we want to add more features to chatbot. So we need chatbot to distinguish between “view COVID cases” with other features. For that purpose, we will update chatbot with ability to detect “view COVID cases” intent, together with “country” entity.

4.1 Create intent and entities

Go to “User Input” menu, the enable Edit mode for dialog. Define a “country” entity and “View COVID cases” intent as below:

  • Define entity using @ keyword, in this sample, country entity is defined as a list with various patterns for chatbot to recognize each value of country.
  • Define intent using # keyword and provide different sample messages for bot to recognize intent. Entity can also be used inside message to improve flexibility. In this sample, there are 3 messages. In reality, each intent should have around 25 messages to adapt to user’s natural language.

4.2 Change trigger type

After intent and entity are created, we need to change trigger type of dialog from “Unknown Intent” to defined intent (View-COVID-cases).

Since trigger type of a dialog cannot be changed, create a new trigger as below:

Next, come back to old (previous) dialog, select all create component, then choose Edit > Copy.

Then in new dialog, paste the conversation:

4.3 Update conversation with intent and entities

After integrated with LUIS, user’s messages will be analyzed by LUIS automatically, and result (intent, entities) will be saved in variables. For instances, country value will be saved in turn.recognized.entities.country.

Since turn.recognized.entities.country is an array (LUIS format), we will update our conversation as below:

The conversation is updated with LUIS. When we start the bot, LUIS key will be asked as below:

Now the conversation will be updated as below:

5. Other features

5.1 Improve response using template

Currently, bot response is defined in “Send a response” component as below:

This time, we will improve how bot reply to user by display country name instead of country code (which we used to call API). Besides that, we will update response method to be more dynamic and reusable using message template.

First, define 2 message template “DisplayResult” and “DisplayCountry” in Bot Responses menu as below:

  • DisplayCountry template receive country code, then return country name based on input code
  • DisplayResult template receive number of cases and country name to construct and return message

Next, update the “Send a response” component to use these templates:

Bot conversation will be updated:

5.2 Deployment

Composer support different deployment method for chatbot.

1. Deploy on Azure WebApp/ Azure Functions

This deployment type requires to have an Azure account.

Access to Publish menu, then create a publish profile with suitable destination type (WebApp or Functions). Some configuration will be asked for setting up external services in chatbot. After configured, save publish project and click “Publish to selected profile” to publish chatbot on Azure.

For more information, please access to document https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-deploy-az-cli.

2. Deploy on local server/ Deploy using Docker

Bot can be started on a local server directly using Composer (as we already did). As Composer can run on various OS, you can host chatbot in any machine you want.

At present, Composer support 2 types of runtime: C# and JS. This can be configured in Setting menu.

For example, when you choose JS as custom runtime, a “runtime” folder will be downloaded in your bot project folder. This folder contain a Node project to start chatbot. You can start this runtime project to start bot server manually, or setup CI/CD for project. You can also create Docker image for bot server.

6. Experiences

In my opinion, Bot Composer have various good points:

  • Easy to setup. Easy to use. Low-code.
  • Lots of documents for reference and guideline
  • Frequently update with improvements and new features

And I had a hard time dealing with various problems, too:

  • Deployment on Azure may require Azure troubleshooting skill to make it work
  • Too many advance features to learn (and to choose which is suitable to solve your need)

But once I get used to using Composer, create conversation flow becomes an easy task. I can focus on developing other components in chatbot system.

7. Conclusion

Through this article, I hope creating chatbot becomes easier for you to get started. There are still lots of features of Bot Composer that haven’t been introduced to you. Those interesting things will wait for you on the way to create your “virtual assistant”.

Tran Gia Quoc Hung – Solution & Technology Unit, FPT Software

Related posts: