Conversational UI

I’ve been thinking a lot about simplification lately; how can I get my growing list of tasks done in less time, yet with the same level of accuracy and quality?

When I first heard about the Bot Framework and Conversations as a Platform at the //Build conference earlier this year I was curious – could natural language help me get more done in less time?

Reducing Clicks

Here’s an example task I perform with some frequency during my evenings and weekends managing billing at my Wife’s business:

  1. Receive payment from customer
  2. Search for that customer in our web or mobile interface
  3. Click a button to start entering the transaction
  4. Click ok to persist the transaction
  5. Dismiss the payment alert

With a bot I can instead simply type in:

John Smith paid cash for classes

This is a meaningful time saver and makes me feel like I’ve built something futuristic 🙂

Bot Framework + LUIS

Conceptually, I think of the Bot Framework as managing communication state between different channels – this might be Skype, Slack, Web Chat or any other conversational canvas. The developer creates dialogs that manage the interaction flow.

The problem is that as humans, we don’t always use the exact same words or combination of words to express ourselves, which is where the intent matching needs to be a little fuzzy and tools like LUIS are an excellent complement.

With LUIS, I simply define my intents (I think of these as actions my bot will support). These intents then map directly to methods in my dialog.

Here’s an example, in the LUIS dialog I add an intent:

Then in my Bot I create a method that maps to that intent in my dialog class:

//TODO: Put AppKey and Subscription key from http://luis.ai into this attribute
[LuisModel("", "")]
[Serializable]
public class MyDialog : LuisDialog<object>
{
    [LuisIntent("ReleaseTheHounds")]
    public async Task ReleaseTheHounds(IDialogContext context, LuisResult result)
    {
        //TODO: Release the hounds!
    }
}

Intents by themselves limit your bot to commands with one outcome. When paired with Entities they become more powerful and allow you to pass in variables to these commands to alter the outcome.

Let’s say that I have animals to release other than hounds. In LUIS I could create an Animal entity:

And then train my model by teaching it some entities that are animals:

After entering a few different types of utterances for this intent you’ll end up with something like this:

The dialog can then be modified to release the appropriate type of animal on command:

[LuisIntent("ReleaseTheHounds")]
public async Task ReleaseTheHounds(IDialogContext context, LuisResult result)
{
    EntityRecommendation thingRecommendation;

    if (result.TryFindEntity("Animal", out thingRecommendation))
    {
        switch (thingRecommendation.Entity)
        {
            case "hounds":
            {
                //TODO: Release the hounds!
                break;
            }
            case "cats":
            {
                //TODO: Release the cats!
                break;
            }
            case "giraffes":
            {
                //TODO: Release the giraffes!
                break;
            }
            default:
            {
                break;
            }
       }
    }
}

The last thing that every dialog should have is a catch all method to do something with the commands it didn’t understand. It should look something like this:

[LuisIntent("")]
public async Task None(IDialogContext context, LuisResult result)
{
    string message = $"Sorry I did not understand. I know how to handle the following intents: " + string.Join(", ", result.Intents.Select(i => i.Intent));
    await context.PostAsync(message);
    context.Wait(MessageReceived);
}

That’s pretty much all that’s needed to get a basic bot up and running!

If you’re a C# dev you’ll want the Visual Studio Project Template and the Bot Framework Emulator to start building bots of your own.

On platforms other than Windows, or for Node devs, there’s an SDK for that also.