How to Integrate IBM Watson Assistant with Salesforce’s Einstein Bot to enhance your conversational solution

Marc Nehme
IBM watsonx Assistant
6 min readOct 31, 2019

--

Salesforce Einstein & IBM Watson

There are many reasons why you would want to leverage Watson Assistant to make your Einstein Bot “better”. In a previous blog, I spoke to just some of the key reasons why you would need to do so. I will provide additional detail here but first, let’s look at how you integrate Watson into your Einstein Bot.

The obvious table stakes, you need a Watson Assistant service to integrate with Bots. If you don’t already have one, you can get a free IBM Cloud account to deploy a Watson Assistant service, which you can do in about a minute, also for free. Once you deploy the service, you would need to configure it for your use case, see documentation here.

On the Salesforce side, you need to create 2 apex classes: one to instantiate a Watson Assistant Session and the other is to send the user messages back and forth to Watson. You should leverage the Watson Salesforce SDK for Apex which allows you to call Watson in as little as 5 lines of code! Be sure to use the latest version of the SDK and Watson Assistant API, currently v2. Below is an example apex class to instantiate a Watson Assistant session which returns a session ID:

public class CreateWatsonAssistantSessionAction {

public static final String ASSISTANT_ID = '<YOUR_ASSISTANT_ID>';
public static final String ENDPOINT_URL = '<YOUR_ENDPOINT>';
public static final String API_KEY = '<YOUR_API_KEY>';

@InvocableMethod(label='Create Watson Assistant Session' description='Returns the session ID of the created session.')
public static List<String> createAssistantSession() {
List<String> returnList = new List<String>();
IBMWatsonIAMOptions iamOptions = new IBMWatsonIAMOptions.Builder()
.apiKey(API_KEY)
.build();
IBMAssistantV2 service = new IBMAssistantV2('2019-05-13', iamOptions);
service.setEndpoint(ENDPOINT_URL);
IBMAssistantV2Models.CreateSessionOptions options = new IBMAssistantV2Models.CreateSessionOptionsBuilder(ASSISTANT_ID).build();
IBMAssistantV2Models.SessionResponse response = service.createSession(options);
String sessionId = response.getSessionId();
returnList.add(sessionId);
return returnList;
}
}

In Einstein Bot Builder, you’ll need to create two new dialog nodes in the “Dialogs” section that will each call your apex classes. The example “Create WA Session” dialog below is straight forward — it calls your apex class (code above) and returns the Watson session ID and stores it into a variable (that you create in Bot Builder).

Create Watson Assistant Session

The second dialog node you must create is to send messages from Einstein to Watson. This calls the “Message Watson Assistant” apex class that you would have already created. It passes the session ID generated from the first apex class above and the message that the end user had sent through Einstein. This call-out retrieves a response from Watson and stores it in the “Last Assistant Response” variable (that you create in Bot Builder).

Send messages from Einstein Bots to Watson Assistant

Once you have this set up, the next step is to implement when Watson Assistant is invoked. There are several different possibilities. In this example, I have setup the call-out to Watson when Einstein is not confident with a matching intent of its own. This leverages the “Confused” dialog node, which comes out of the box in Einstein Bots.

In my example, I first create a message to tell the end user that the answer is coming from Watson (“Watson says..”) in the chat interface. This is optional and is for illustration purposes.

Next, you must configure a rule in the “Confused” node to first check if the session ID variable is currently set or not. If that variable is not set, then Einstein calls the “Create WA session” dialog node, which executes the apex class to create a session ID in Watson Assistant. This is required to proceed.

The “Confused” dialog node

Next in the “Confused” node, you create an action that calls the second apex class to send the user message (“Last Customer Input”) to Watson, along with the session ID (“Session ID”). In this action, you store the response from Watson into a variable that you create in Bot Builder (“Last Assistant Response”).

Finally, you must create a message in the “Confused” node to share Watson’s response with the end user, which is stored in your “Last Assistant Response” variable.

The “Confused” dialog node

Done! Now here is an example what the results can look like (I’m showing the Bot Builder chat window)…

In this first use case, a customer is asking about the status of their claim, however Einstein was not confident on identifying this intent, so it handed off to Watson who provided the appropriate response..

Einstein hands off to Watson

In this next scenario, the user asks an ambiguous question regarding claims. Einstein hands off to Watson who automatically provides helpful options to help the user, with no additional dialog training (this is the “disambiguation” feature)..

Disambiguation

Next, the user is in the middle of a dialog but digresses away from the current conversation (about claim status) to ask about the weather. Watson is able to address that “off topic” intent and then bring the user back on track in the original dialog (this is the “digressions” feature)..

Digressions

Finally, in this use case, the user is asking a question about how they can view their policy. Einstein hands off to Watson Assistant who responds with a knowledge base article as the answer to guide the user, courtesy of the Watson Discovery service (this is the “search skill” feature)..

Search Skill

Below, I have summarized some of the scenarios where you should leverage Watson Assistant with your Salesforce Einstein Bot…

Multilingual support — as Einstein Bots supports the English language, you can use Watson Assistant to extend support for many other languages such as Japanese, Arabic or Spanish to name a few.

Search Skill — Enhance your conversational solution to provide answers to questions through your content (knowledge articles, training documents, etc) across your enterprise, leveraging Watson Assistant’s native integration with Watson Discovery.

Intent Classification — IBM Watson has the world’s most robust and mature intent classification service, which provides better understanding of your customer questions, with less training data. Einstein requires a minimum of 20 examples, but recommends at least 150 whereas Watson requires significantly less intent examples to train a model (as few as 5 examples).

Disambiguation — Watson will automatically provide the end user with options if more than one trained intent closely resembles the question being asked. You do not need to explicitly set up individual dialogs to handle this. Once enabled, it’s automatic!

Digressions — To better manage your conversational flow, you can leverage Watson to address questions/intents that may require deviating from intended dialog flows. Watson will keep the conversation on track providing a better client experience.

Webhooks to external applications — Watson has the ability to make call-outs to external systems to perform actions. For example, if a customer needs to file a support case, Watson Assistant can make a programmatic call to the Salesforce platform to create a case record.

These are just some of the key differentiating capabilities of Watson that provide customers with a much more seamless experience.

Get started with Watson Assistant for free on IBM Cloud and check out IBM Watson Assistant’s documentation to learn more!

Marc is the CTO for IBM Watson AI Strategic Partnerships. When not leading the technology vision and strategy for IBM Partnerships, Marc enjoys DJing, playing video games and wrestling.

--

--

Marc Nehme
IBM watsonx Assistant

Tech guy living the dream, AI enthusiast, helping scale AI across the globe, making things real - MarcNehme.com