Skip to Content
Technical Articles
Author's profile photo Noorulain Khurshid

Building an SAP Conversational AI Chatbot that Integrates with Qualtrics and SAP Customer Experience (2/4)

Hello again and welcome to part 2/4 of the blog series “Building an SAP Conversational AI chatbot that integrates with Qualtrics and SAP Customer Experience“.

Building the SAP Conversational AI Chatbot

 

In this part, we are going to create and train our chatbot. In addition to that, you will find useful tips in the appendices, e.g. on debugging the chatbot and creating custom entities.

So, without further ado, let’s dive right into it. First, let’s log on to the SAP Conversational AI platform at cai.tools.sap and click on the button, +NEW BOT.

We are presented with a 5-step wizard. We are going to create a chatbot that performs actions using conversational flows as opposed to an FAQ bot.  Next, we will choose to create some predefined skills like greetings or small talk. This will save us time and let us focus on creating custom skills for the bot. A skill, simply put, is a conversation that leads the bot in achieving a set goal.

2.1%20SAP%20Conversational%20AI%20chatbot%20creation%20wizard

2.1 SAP Conversational AI bot creation wizard, Step 1-2

In step 3, we are going to give our chatbot a unique name along with a description. This step also allows you to further categorize the chatbot into topics that will help with training the bot. The default language selected for the chatbot is ‘English’. Let’s leave it as is.

SAP%20Conversational%20AI%20bot%20creation%20wizard%2C%20Step%203

2.2 SAP Conversational AI bot creation wizard, Step 3

In step 4, we will choose the data type option as ‘Personal’ since the end users would be sharing email ids as well as order details in the chat. Hero bot would not be used by children or adults-at-risk so we can choose the end-user type as ‘Non-vulnerable’. Finally, in step 5, we can set the visibility of the bot to ‘Private’, making sure it is not visible to everyone on the SAP Conversational AI platform.

All these options could be easily modified later on, if the need be.

SAP%20Conversational%20AI%20chatbot%20creation%20wizard%2C%20Step%204-5

2.3 SAP Conversational AI bot creation wizard, Step 4-5

Click ‘Create a bot’ to complete the wizard. The bot will get created with the selected skills redirecting us to the ‘Train’ tab. We will see a notification stating the chatbot training is currently running.

2.4%20Train%20Tab

2.4 Chatbot Train Tab

Once the training is finished, we will see a notification along with a timestamp.

On the Train tab, we can see a list of intents, automatically created by the bot creation wizard. An intent, from Natural Language Processing (NLP), is an idea that is understandable by the bot. In SAP Conversational AI, it is represented by the name of the intent preceded with an @ sign. If we navigate to the intent @greetings, we will see a list of expressions that could be regarded as a greeting.

2.5 Chatbot skill @greetings

 

We are now going to add a custom intent, specific to our use-case.  Staying on the Train tab, navigate to the sub-tab Intent and click on the button + CREATE to add a new intent, @orderinquiry and navigate to the intent.

Click inside the input field Add an Expression and create an expression ‘I did not receive my order yet’ and press enter to add it to the list of expressions. A similar expression that we can add to the list could be ‘My order is not here yet’ and/or ‘where is my order?’ and so on.

You can also use a CSV file to import a list of expressions to be included inside an intent. Once done, press the Train button on the top of the screen to update the chatbot to understand the latest intent/expressions. Intents could be forked from other bots or intents. Based on the entered expressions, similar expressions are automatically suggested for you to add to the list.

Subsequently, we are going to add the following intents: @createticket, @yessurvey, @nosurveyorticket.

@createticket @yessurvey @nosurveyorticket
Yes, please! Sure! No, that is fine
Yes, create the ticket Why Not No, thanks!
Ok, let’s create the ticket Yes, I can respond to the survey Some other time

Expressions include keywords called entities. There are gold entities that are automatically determined by the SAP Conversational AI platform when a certain keyword qualifies for the description of that entity. For example, any email address is automatically classified as an email gold entity.

Like gold entities, it is also possible to create custom entities for special keywords. For example, product names in SAP Commerce Cloud site could be imported into a custom entity (let’s call it CCB2BProduct) and whenever the product name is found to be part of a conversation the entity is recognized and could be used to trigger a specific action (skill). We are going to create a custom entity in a later step. First, let’s add a skill to our chatbot.

Adding New Skills

 

When we created our chatbot, some of the skills were automatically created by the SAP Conversational AI platform. Navigating to the Build tab, we can already see greetings, small-talk and a fallback skill. Let’s now add a skill (+ Create skill button) that would get triggered whenever the chatbot receives an expression matching the @orderinquiry intent.

Order%20Inquiry

2.6 Create a new skill

The very first step in getting an order status would be to confirm the end-user’s email id. Let’s name our skill verifyemail. Create%20a%20new%20skill%20dialog

Once created, navigate to the skill and go to the Triggers tab. For this skill to trigger, an order inquiry needs to be present in the conversation. We already created the orderinquiry intent for this purpose in a previous step. Click the input field next to If to get autosuggested lists of values that can possibly go into the operand part of the condition.

Trigger

2.7 Skill Trigger Tab

Under the User says, we will choose @orderinquiry and press Save. Once done, we would need to choose an operator (is-present) from the autosuggest list.

2.8%20Skill%20Condition

2.8 Skill Trigger Condition – Operators

Once the trigger is defined, the next step would be to perform an action. (We will come back to the Requirements tab in a later step). There are multiple possibilities when it comes to creating actions inside a skill. You can send a message, make an API call, redirect to another skill and even update a memory variable inside the chatbot. In addition to that, these actions could be repeated based on how you would want to drive the conversation. Messages could be grouped and depending on the evaluated condition, a specific message group is triggered.

For our scenario, the first action would be to determine if the user is already logged in, based on which, the user’s email address in the linked profile could be retrieved and used to get a list of recent orders from the Commerce Cloud site.

Let’s navigate to the Actions tab and click on ADD NEW MESSAGE GROUP.

Adding API Calls

 

Click CONNECT EXTERNAL SERVICE to define the API call followed by CONSUME API SERVICE. In the API Service Configuration section, we are going to define a GET request with URL https://{url}/rest/v2/powertools/users/current?fields=DEFAULT

Here {url} would refer to your Commerce Cloud site base URL.

Furthermore, in order to access the Commerce Cloud REST API, you need to define OAuth2 credentials and URL.

API%20Config

2.9 API Service Configuration

Leave the Headers section as is for now and navigate to Response where the API response structure is defined. The response would be saved inside the variable api_service_response and we can create a namespace to store/retrieve the actual value.

2.10%20API%20Response

2.10 API Service Response

Great! Let’s add a new message group where we would be adding a condition for the trigger.

Click ADD CONDITION. Next to If we need to include the operand, which in this case would be the current user’s email address. We will make use of the api response received from the API call we had defined earlier.

2.11%20api_service_response%20in%20Memory

2.11 Using _api_service_response in a condition

2.12%20Email%20from%20api_service_response

2.12 Email from _api_service_response

You can easily traverse the structure of User entity by going to the API documentation / Swagger UI (and if you want to try out the API).

2.13%20API%20Documentation%20-%20Commerce%20Cloud%20User%20Entity

2.13 API Documentation – Commerce Cloud User Entity

Chatbot Memory Fields

 

For the ease of maintainability and usability, we can store the path inside a memory variable which we can then easily refer to instead of having to traverse the complete response structure for use inside the chatbot. Go to the API call we had created earlier and click on UPDATE CONVERSATION > EDIT MEMORY.

2.14%20Edit%20Memory

2.14 Edit Memory

Memory%20Field We will add a memory variable ‘profileEmail’ that refers to the email address coming from the API response.

In order to access the memory variables, it is necessary to enclose the reference with curly brackets.

Going back to the condition we were trying to define; we can now refer to the variable ‘profileEmail’ from the memory construct.

If the condition evaluates to true, we are going to trigger sending a message in the chat.

Click SEND MESSAGE followed by selecting message type as Button and then create the message that we want to send.

Notice how we can easily refer to the email address we saved in the memory variable ‘profileEmail’. The email address is presented as a link with a postback being the actual email address.

 

Once done, we will add another skill (orderlist) that handles the part of the conversation where a list of orders is presented to the end-user based on the email address. Follow the next few screenshots for details.

 

API%20Call

2.15 API Call for retrieving the order list using the email address

Response%20Object

2.16 Response Object Structure

Display%20order%20list%20in%20the%20chat

2.17 Display order list in the chat using the response object

 

Finally, we will add the skill that would handle the actions around presenting the end-user with the order status information.

 

For this skill, we are also going to add a requirement. In SAP Conversational AI terminology, Requirement is information that needs to be present in the memory before actions for the skill could be executed.

Basically, we would be defining the #ordernumber entity with a name orderID and default structure. To access the value entered in a chat that qualifies to be an order number, we would be referring to the raw value stored in memory variable orderID. Follow the next few screenshots for details.

API%20call

2.18 API call to retrieve order details using Order ID from the chatbot memory

 

Order%20details%20in%20the%20memory

2.19 Set memory fields to hold order details

Product%20API%20Call

2.20 API Call to retrieve product details

Product%20response%20Object

2.21 Product response Object

Status%20from%20memory

2.22 Retrieve Order Status details from memory

 

Conclusion: At this point, our chatbot is functional enough to handle a conversation that involves providing the end user with an order status. The next step would be to discuss in detail, the Qualtrics integration piece where the chatbot presents the end-user with a Qualtrics survey and would update the survey responses received inside the chat. More of this in part 3. Later!

 

Part 1: Introduction and Getting Started

Part 3: Building the Qualtrics Survey and App

Part 4: Additional API Calls and Tips

———————————————————————–

For more information about SAP Conversational AI:

 

Appendix.

 

A. Testing the bot using the Debug mode

 

One of the amazing features of the SAP Conversational AI platform is the ability to test/debug the chatbot as you build it. Click on the blue button in the lower-right corner of your screen and set the Debug to ON.

 

As the chat progresses, the bot log details the triggered skills and the subsequent actions. We can see the verifyemail skill getting triggered and the quick reply with current user’s email address is displayed.

If we click on the  icon, we can see the current state of the conversation as well as memory and other variables’ values.

We will continue to add skills to progress the conversation past the email verification. For example, this would include creating a skill for order status retrieval using API calls to Commerce Cloud webservices. We would be able to use memory variables to store the API responses for use inside the chatbot text messages.

B. Custom Entity for Order Number

 

SAP Conversational AI platform can detect gold entities. In case of numbers, it would mean a number with a semantic. (For instance, Volume, Temperature, Speed, Money and Number). But an order number is usually specific and needs a custom entity of its own.

For the purpose of this scenario, we are going to create a custom entity OrderNumber based on the order number format from the Commerce Cloud site. We will adjust the matching strictness to 50, this would allow us to enter any order number starting with the pattern.

 

Navigate to the Entities section in the Train tab and click CREATE AN ENTITY.

Custom%20Entity%20Dialog

Custom Entity Dialog

Custom%20Entity%20Created

Custom Entity OrderNumber Created

Once done, navigate to the entity to create a list of example order number(s) that would enable our chatbot to recognize and differentiate the Commerce Cloud site’s (B2C Automotive Site) order number from any other number.

In our case, the order number series begins with ‘00250’.

Value%20list%20for%20entity%20OrderNumber

 

In the chatbot log, we can see how the order number (saved as orderID in the memory) has the raw value ‘0025021035’ matching with our custom entity (OrderNumber) value ‘00250’ with an 83% confidence.

Amazing!

If the custom entity #ordernumber is detected, skill orderstatus is triggered and we get the order details.

 

Assigned tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Rolf Hoven
      Rolf Hoven

      What is the different between these memory variables?

      {{memory.ordernumber.raw}}

      {{memory.ordernumber.value}}

      {{nlp.source}}

      {{#ordernumber.raw}}