Sitecore Chat Bot: Ole

August 24, 2017

As a follow up to my work on Sitecore Cognitive Services where I demonstrated an image search driven by Microsoft Cognitive Services, I've developed another interesting utility that builds off of LUIS, and enables a chatbot natively in Sitecore. I've named it Ole.

A lot has changed in the source code in the last few months. I've been working to conform to Helix, integrate Gulp and separate independent features from the core libraries. Another key focus was to decouple a lot of the dependencies like newer versions of Newtonsoft.Json or Microsoft's ProjectOxford which made it more complicated to get up and running. The steps now should be much simpler and are moving me much closer to having a true set of modules ready for the Marketplace.

The Meta

Ole (Oh-La) is named after one of the founders of Sitecore who, due to his relative obscurity, is a bit of a mythical figure. I've never met him (and most likely never will) but I was told he shaped a lot of what you know as Sitecore, which is why I thought a chatbot would be a perfect spiritual successor. Luckily there was an icon available that I feel represents him pretty well (from the pictures I could find on google). I demoed this at SUGCON EU this year in Amsterdam and received a lot of positive feedback about it.

Without further adieu, meet Ole. ole 

Getting Started

  • Setup an Azure Resource (you will need to have an azure account)
  • Get the source code on GitHub
  • Setup LUIS account
    • browse to https://www.luis.ai, login or create an account
    • go to https://www.luis.ai/keys and click on 'Add a new key'. Copy the Azure Subscription ID (remove the dashes) from the new Azure resource and give it a name. 
    • on the 'Keys' page copy the 'Programmatic API Key' (generate one if needed)
    • go to https://www.luis.ai/applications and click 'Import App' and browse to the file /<SourceRoot>/Serialization/ole-chat.json and click 'Import'
    • Select the Ole Chat application and browse to 'Publish App' section and click the 'Train' and then 'Publish' buttons (this is where the machine learning part happens and the files are deployed to Azure)
  • Sim Install some version of Sitecore 8.2
  • Setup Solution
    • open the solution in Visual Studio and go to the Task Runner Explorer and run 'Create-Local-Properties'
    • go to /configuration/properties/local.properties. update any relevant domains, paths and set the subscription key value for 'ConitiveService.ApiKey.Luis' to the 'Programmatic API Key' from LUIS
    • open the Task Runner Explorer and run the 'Nant' task then the 'Publish-OleChat' (may need to run it twice)
  • Test it out
    • log into Sitecore and select the 'Ole' app on the launchpad
    • say 'hi' and ask 'what can you do?'

Here's what you'll be seeing:

ole chat window

Operational Overview

Since it can be a bit difficult to understand all the moving parts I've got a diagram that should help you get your head around it a high level. 

OleChat diagram

Extending Ole

To add new functionality there's only a few steps: 

1. Go to LUIS and open the Ole application. Under 'Intents', add an intent. You'll likely need to read the documentation to add enough language for it to understand how to parse user text. (utterances are phrases and tokens are variables)

2. From within LUIS, train and publish your application.

2. In the solution, you'll need to add an intent class to represent the intent from LUIS. For a simple response, you'll just need to implement the IIntent interface. If you want something more complex with a conversational dialog to retrieve multiple variables, you'll want to extend the BaseIntent abstract class and implement the IIntent interface. 

3. You'll need to create a factory class that builds the intent. (this is just proper form) Since this is all open source you can copy any of the existing factories. 

4. The last step is to register the intent and factory classes with the Dependency Injection framework. Again here you can copy the existing definitions from the IocConfig class.

In case you're wondering, if you're looking to use this in production and not build from source, you can add your intents into your own library. The way that Ole finds the intents is through the service provider so anything that's registered as a specific type will be found. 

Postscript 

Immediately you should know that having a chatbot native to Sitecore opens up all kinds of doors that otherwise wouldn't be available. First is that a lot of administrative tasks can now be accomplished through a text dialog as opposed to navigating through the Sitecore UI. For certain tasks this is much quicker and a whole lot more accessible. Since it's available from the launchpad, you can open it in a whole window and it's responsive. Imagine now how much you can do straight from your phone over a much slower connection (like when you're commuting to and from work). You can still be stuck in traffic and be able to publish content, unlock items and kick users (if you're an admin).

This also represents a model of how you can setup a chatbot. My hope is that in the future we will see search boxes extended to be chat-like. Imagine being able to ask a search box for something specific and having it return more than just search results. Suddenly a search field is much more meaningful and opens up users to a lot more of your site with the right language. 

Just take a minute and let that sink in.