Using Chatbots to Improve User Engagement (Part 2 of 2)

This is part two of a two-part series that takes an in-depth look at how Progress Labs is innovating with Chatbots. You may read part one here.

Necessary Components to Create Your Bot

In the first part of this series, we ended with an introduction to the Microsoft Bot Framework. Here we will start looking at how you go about creating a bot using that framework. Here are the components you need to consider when creating your own bot:

  • The Bot Registry: This is a publicly available registry from where people can install your bot. In case of a Skype bot, it is the Skype bot registry. When you log in to Skype and search the bot by name, you can easily add it to your contacts.
  • The Client: In case of an SMS bot, the client is the SMS application on your phone. If you are using a Skype bot, the Skype application on your system is the client. The client varies depending on the channel of communication.
  • Microsoft Bot Framework: The infrastructure laid by Microsoft to facilitate building bots. It provides us with easy integration with the bot, various messaging channels, conversational infrastructure, and integration with the natural language engine.
  • LUIS: The Language Understanding Intelligent Service which currently supports five spoken languages. You can create an application in LUIS and host it on a public cloud. In our case, it is hosted on Microsoft Azure.

It is easy to use LUIS for language comprehension because it identifies and breaks down a sentence into intents and entities. Intents translate the purpose of the sentence and entities can be considered as the subject of the intent. For example, time, date, place, and name are considered entities. You can also define custom entities. The application does need training and it requires the definitions of intents and entities for given sample utterances. For example, you can have intents for Greeting, Farewell, ProcessOrder and many more. The more you train, the better it understands. Here is a sample training screenshot:

bot-luis

  • The Bot Brain: This is the only piece where you need to write some code. You need to write intent handlers, which means once LUIS decodes the intent of a given utterance, then you must define the action on that intent. The action can just be a prompt or a call to a database or invocation of a web service. You can write the bot in Node.js or C# if you are using Microsoft Bot Framework. We wrote it in Node.js and hosted it on Modulus. Here is the sample code:
    
    var dialog = new builder.LuisDialog('https://api.projectoxford.ai/luis/v1/application?id=769f6dc0');
    var bot = new builder.BotConnectorBot({appId: 'notfbot', appSecret: ‘XXXXX’ });
    bot.add('/', dialog);
    // Handling the Greeting intent. 
    dialog.on('Greeting', function (session, args) {
    	console.log ('in greeting ');
    	session.send('Hello there! I am the notification bot. I can notify about the urgent orders');		
    });
    // Handling unrecognized conversations.
    dialog.on('None', function (session, args) {
    	console.log ('in none intent');	
    	session.send("I am sorry! I am a bot, perhaps not programmed to understand this command");			
    });
    dialog.on('Notify', function (session, args) {
    	console.log ('in notify ');
    	session.send('we just got an urgent order. Want to review it?');		
    });
    
  • System of Record: This is where you store your data, possibly in the form of a web service or database. In our case it is an Progress OpenEdge (OE) application hosted on the Progress Arcade Cloud.

Architecture of the OpenEdge Chatbot

Below is an architectural representation of all the components and their interactions. The arrows show how data flows from the software client at the user end to the bot and vice-versa. The purple box is the user client, for example Phone, Outlook, or Skype. The blue box is the Azure cloud which hosts the natural language engine (LUIS) and the bot framework. The green box contains the Progress-specific pieces which consists of the OpenEdge application (which exposes the REST endpoint and serves as the data store), it also consists of the actual bot application which contains the business logic/intent handlers.

bot-arch

For instance, if a user types an English sentence on Skype addressing our bot, the message is sent to the bot framework, which knows the public URL of the bot deployed on Modulus. The bot knows the URL for LUIS and requests it to resolve the message. LUIS returns a structured JSON where it breaks down the message into intents and entities and ranks the intents with scores as shown below.

{
  "query": "get me the phone number of Hoops",
  "intents": [
    {
      "intent": "GetPhoneNumber",
      "score": 0.999897
    },
    {
      "intent": "None",
      "score": 0.0602122322
    }    
  ],
  "entities": [
    {
      "entity": "hoops",
      "type": "Identity::Name",
      "startIndex": 27,
      "endIndex": 31,
      "score": 0.8812587
    }
  ]
}

Once the bot knows about the intent and entities of the message, an action can be performed. The action can be as complex as establishing a nested conversation with multiple rounds of question and answers or as trivial as invoking a REST endpoint and serving processed results.

bot-framework

The Microsoft bot framework portal looks as above, the messaging endpoint is the public URL of the bot hosted on Modulus. Enabling a bot is as easy as clicking on the “Add” link in the “Add another channel” section. The bot is running on the channels marked with a “Running” status. Each channel has a specific set of instructions on how to enable the bot on the channel. Once you add a bot, in most cases you will get a bot URL which can be directly used by users to add the bot to their local clients (Skype, Slack, Outlook, etc). In case of an SMS bot, you will get a phone number to use. In case of Slack or Skype, it appears in the appropriate bot registry as well.

Opinion on the Chatbot Development Experience

Most of what you are seeing are in beta mode, so you can expect some changes ahead. The good part is that you can provide feedback and request interesting features for free.

Initially we hit few bumps, but the community was really active and helpful. We suggest you pay extra attention on the LUIS training. Defining clear intents is the key and getting enough sample utterances (around 20-30 per intent).

If possible get subject matter experts to write sample utterances for you. There are infinite variations of a question and there can be many responses to the same question. Templating the responses is a good idea.

It is also important to define thresholds for intent resolution. For example, LUIS resolves the utterances and assigns a score for each intent. The intent with the highest score is chosen. However, it is possible that the highest score is too small to be considered for an action. In such cases, you can define minimum thresholds and let the intents resolve to “None” if it doesn’t suit you.

One of the powerful features of LUIS is active learning where it can critique its own work and ask you to re-label things if they don’t seem right to you.

Where Should I Look for Help?

The documentation for Microsoft Bot Framework is illustrative and nearly complete. If you want to start interacting with the bot, try adding the notification bot to your Skype using the link.

If you want to look at the code samples we created during this Progress Labs activity, they are available on Github.

Comments