In this post – I will show how I have set up an Einstein Bot using both AI and Apex together with minimal apex coding!

In my Bot – I use Einstein Intent Detection to determine what the customer is asking about, I then use Einstein variables and regex to determine an entity from a sentence that the customer has entered and finally call some Invocable apex to get some additional information from an external system to display to the customer.

Step 1. Create an Einstein Bot

Step 2. Create the Bot Dialogs

Step 3. Add Intents to the Dialogs

Step 4. Train the AI Model and Deploy the Bot

Step 1. Create an Einstein Bot

I already have Live Agent, Service Cloud and a Customer Community set up in this org. I will take you through the steps to add an Einstein Bot to this. Go to the Einstein Bots section in the Salesforce setup menu (this option is only visible in Lightning). Enable the Einstein Bot for Live Chat and then choose to create a new bot.

Step 2. Create the Bot Dialogs

For my first dialog – I use the standard Welcome dialog and simply display a message to the customer. After this, I then wait for the customer to respond with another input.

For my second dialog, I will ask the customer for their order number and then try to find the order number in the text that they respond with. I choose the option to ask a question and then save my order number as shown below – I use a regex to detect the pattern AB1234 which can detect that format if the customer uses it within a sentence.

I then add an action to this dialog to do a callout to an external system to get the status of the order that has just been entered. This is an apex invocable method that does an http callout to an external system to get this information.

I then add an Action to my dialog to call the invocable apex, pass it the order id and then get the order status back from the external system.

Now that I have the order status data – I want to display it to my customer. I simply add a message to my dialog which adds some text and display the value that I have stored in my variable.

 

Step 3. Add Intents to the Dialogs

In the first two steps, we have created the customer journey for our bot. If we wanted to give the user options or script the journey – we could just link these up via some menu options but instead of doing this, I will leverage the power of Einstein AI instead. To do this – I will add some Intent Analysis to my order dialog. This enabled via the button on the top right of the dialog. After doing this, you will then see a Dialog Intent tab.

In here, I will manually add the data for Einstein AI to train on. You can also use Data Loader to add this but as I am using a basic example with just 20 inputs – I will manually add it in (Salesforce recommend at least 150 inputs).

 

Step 4. Train the AI Model and Deploy the Bot

After adding all of my Intent data – I then go to the overview where I will have an option to train an AI model in the Intent section. Clicking on Build Model will train the AI model and display the status of the training. Note – you need to have add Intents for at least two Dialogs before doing this. An example would be adding a different Dialog for cancelling or changing an order.

Once the AI Model is trained – you should then Activate your Einstein Bot. You can test it in preview model in the Bot Builder or add it to your Live Agent setup to test via an actual Live Chat.

 

The Result!!!

Whats does this all do – we have an Einstein Bot which determines what the customer is asking using Intent detection. It then asks for the order number if the Intent is querying an order. It then examines the next sentence written by the customer and find the order number in the sentence. It then stores this in a variable, passes it to an apex order status method and stores the order status in a variable. It then displays the order status to the customer.

All of this has happened automatically based on the customers original query.

You could enhance this by adding multiple options, adding more dialogs to support use cases but this gives you the basic idea of the capability of an Einstein Bot using a very small amount of apex.

Leave a Reply