Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Noorulain1
Advisor
Advisor
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 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.


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.


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 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.


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.

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.


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 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.


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 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 Using _api_service_response in a condition



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 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 Edit Memory










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.

 


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



2.16 Response Object Structure



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.


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


 


2.19 Set memory fields to hold order details



2.20 API Call to retrieve product details



2.21 Product response Object



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 Entity Dialog



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’.

 









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.

 
1 Comment