Start building your own chatbot now!

Introduction

In this blog, you’ll learn how to create an HR chatbot using the SAP Conversational AI platform. This chatbot can address two types of questions:

  • Basic employee information (g. first name, last name, current position, and working location)
  • Employee’s phone number 

Pre-requisites

Before going further, you should have basic knowledge of SAP Conversational AI and SAP Cloud Platform Integration process. Here are the blogs and resources that will help you get started:

Process flow in a nutshell

flow-chatbot-sap-cloud-platform-successfactors

  1. A user asks for information about an employee
  2. SAP Conversational AI (SAP CAI) selects the intent @ask-employeeinfo based on the above context
  3. The integration flow Employee Information on SAP Cloud Platform Integration (SAP CPI) is triggered via the webhook
  4. The SuccessFactors OData EmpJob entity is then called to return the employee information in the XML format
  5. SAP CPI converts it into the JSON format and sends it back to SAP CAI
  6. Next, the user enquires about the employee’s phone number
  7. SAP CAI selects the intent @ask-phone based on the above context
  8. The integration flow Employee Phone Information on SAP CPI is triggered via the webhook
  9. The SuccessFactors OData PerPhone entity is then called to return the employee information in the XML format
  10. SAP CPI converts it into the JSON format and sends it back to SAP CAI

Part 1: SAP Cloud Platform Integration

The following section describes the steps to build the integration flows – Employee Information and Employee Phone Information to serve the requirements.

1.1 Integration flow: Employee Information

1.1.1 Overview

1.1.2 Configurations

a) Set the allowed header for employeeid.

b) Set the called address to /empinfo.

c) Configure a SuccessFactors OData connection to retrieve employee information from the entity EmpJob. Also, set the dynamic parameter ${header.employeeid} from the above step.

Then you can choose whatever information you want to send back to SAP CAI.
In the following example, I have chosen “First name”, “Last name”, “Position name”, and “Working location”.

Note: If you prefer, you can use a Groovy script to do it.

d) Set the output from the above step to the message header API_Response.

e) Construct the target output for SAP CAI. Add the output text in the field content.

Your integration flow is ready to be deployed!

1.2 Integration flow: Employee Phone Information

1.2.1 Overview

1.2.2 Configurations

The steps are more or less the same as the integration flow Employee Information explained above.

a) Set allowed header for employeeid

b) Set the called address to /empinfo.

c) Configure a SuccessFactors OData connection to retrieve employee information from the entity EmpJob. Also, we set the dynamic parameter ${header.employeeid} from the above step.

Then you can choose whatever information you want to send back to SAP CAI.

d) Set the output from the above step to the message header API_Response

e) Construct the target output for SAP CAI. Add the output text in the field content.

Your second integration flow is ready to be deployed!

Part 2: Build your chatbot using SAP Conversational AI

2.1 Create your chatbot

Go to your SAP Conversational AI account and create a new chatbot.

  1. Click  “+New bot”.
  2. Select Perform Actions with no predefined skills.
  3. Provide a name for your bot. Mine is sf-employee-information.
  4. Select “Type of data” as Non-personal and “End users” as Non-vulnerable.
  5. Choose your bot visibility as you wish.

Here we go! Your bot is ready to be configured.

2.2. Intent: Basic employee information

Now, let’s create the first intent for employee information.

  1. Under Train > Intents, click CREATE.
  2. Add a name and description of your choice. I created the intent called ask-employeeinfo

Here is the newly created intent:

2.2.1 Entities

Next, I will create a custom entity.

Please note that SAP Conversational AI provides many predefined entities (gold entities) such as #location#datetime#number, etc. These keywords are ready to be used by your bot.

  1. To create a new custom entity, switch to the Entities tab, and click CREATE AN ENTITY.
  2. I have created a Free entity named employee-id. The aim is to detect the keywords, such as “employee ID” or “ID”, as the entity #employee-id and then let the machine learning algorithms automatically extract the actual employee ID to the entity #number.

Let’s go back to the intent @ask-employeeinfo.

Now we are going to add expressions to the intent.

2.2.2 Expressions

You can add as many expressions as you like. We recommend adding 50 expressions per intent for proper training.

After that, we highlight the keyword “employee id” to match with the entity #EMPLOYEE-ID

Do this for all your expressions.

 

You can test if the correct intent is being executed based on the sentence you type.

On the right-hand side, click on the TEST console. The testing window will open.

Then you can type some sentences there. If it’s correct, it should detect the keyword “employee id” as the entity #EMPLOYEE-ID and the ID will automatically be extracted as #NUMBER.

2.3 Intent: Phone number

  1. Create a second intent called ask-phone. This intent is supposed to be detected when the user enquires about an employee’s phone number.
  2. Let’s add the expected questions as expressions that the users might ask.

Please note that there’s no need to create additional custom entity as we don’t want to extract any value from the context.

It’s always a good idea to test every time you create a new intent so you can make sure that the right intent is picked up.

2.4 Add a skill to your SAP Conversational AI chatbot

1. On the Build tab, create a new skill called respond.

Note: technically, both skill types—BUSINESS & FLOATING—have the same behavior. You can select either one of them that suits you the most.

2. Click on the newly created skill respond.

There are 2 conditions for the skill to be triggered.

  • The intent @ask-employeeinfo is found
  • The intent @ask-phone is found

You should also check if there’s enough information prior to executing the action. Therefore, the value of either employee ID or location should exist.

On the right-hand side, the data structure is visible in the black block.

For example, if you want to get the employee ID, then you can get it from this variable {{memory.employeeid.raw}}.

You can also add a reply in case the required information is not received.

3. In the Actions tab, configure the webhook to trigger the integration flow that we developed in the earlier step.

The first one is for the intent @ask-employeeinfo. If requirements are met, then the integration flow Employee Information should be triggered.

Another one is for the intent @ask-phone. If requirements are met, then the integration flow Employee Phone Information should be triggered.

4. Finally, we should reset the memory after the phone number has been asked. The data in the memory that is included with the employee id will be wiped out. Why? In case a user asks for a phone number before asking for a specific employee, an error message will be shown.

2.4 Test your bot

  1. On the bottom-right, click on CHAT WITH YOUR BOT.
  2. You can inquire with the employee information first. And then ask for a phone number.

You can also try to ask for a phone number first. An error message will be displayed.

Conclusion

Congratulations, you’ve built a functional chatbot that can retrieve employee information from SAP SuccessFactors!

The above solution is an example of a basic HR bot, but a lot can be done to have a better and a perfect bot.

For example, the error handling should be covered in case there’s no employee ID found, or some configuration steps can be shortened with the help of coding. Furthermore, the chatbot can be integrated with other messaging platforms like Slack or Facebook Messenger.

Be aware that the SAP Conversational AI team is working in collaboration with SAP SuccessFactors for building a digital assistant completely integrated with the HR software. For more information about this project and how it will revolutionize employee experience, I strongly suggest you to watch this video:

For any questions about this tutorial, please use the comments section below or SAP Answers.

Happy bot building 🙂

Ask your questions on SAP Answers or get started with SAP Conversational AI!

Follow us on