This documentation supports the 20.08 version of BMC Helix Chatbot. To view the documentation for the previous version, select 20.02 from the Product version menu.

Exercise 3 - Test the Time off request service from IBM Watson Assistant


With the process definition built for this service, the next step is to see how to create Watson Dialogs to invoke the Request Time Off or the Check Leave Balance process.
Intent:
 From IBM Watson select the HR Chatbot skill and go the Intents section. The following intents, are created for this service:

  • #PTO (this is the Request Time Off intent. PTO stands for Paid Time Off)
  • #checkleavebalance

The Request Time Off intent comes with 20 values or utterances and the Check Leave Balance intent comes with 14 values or utterances.
 For more information about these values please review them using your IBM Watson Assistant instance where this service has been published to, because we have not documented every aspect of the intents here.
Tip: Intents represent the purposes or goals that are expressed in a customer's input, such as answering a question or processing a bill payment. By recognizing the intent expressed in a customer's input, the Watson Assistant service can choose the correct dialog flow for responding to it. For more information about Intents please refer to the following link:
https://cloud.ibm.com/docs/assistant?topic=assistant-intents
Tip: The number of Intent utterances will vary based on the use case. In this use case, the main goal is either to request time off or to check your leave balance. The following are sample intent utterances that can be used to build out the Intent values:

Request Time Off

Check Leave Balance

  • Apply for PTO
  • how many days off I have in total
  • Apply for time off
  • how many days off I have left
  • Go on vacation
  • how many vacation days do I have in total
  • Planning a vacation
  • how many vacation days do I have left
  • Request time off
  • check my leave balance
  • Take a few days off
  • check my paid time off balance
  • Take a week off
  • check my PTO balance
  • Take sick leave
  • check my vacation days balance
  • Take maternity leave
  • how many leave days do I have
  • Take paternity leave
  • what is my leave balance
  • Take bereavement leave
  • what is my time off days balance
  • Take jury duty leave
  • what is my vacation days balance

Entities:
https://docs.bmc.com/docs/plugins/servlet/confluence/placeholder/unknown-attachment?locale=en_GB&version=2Tip: Entities represent information in the user input that is relevant to the user's purpose. If intents represent verbs (the action a user wants to do), entities represent nouns (the object of, or the context for, that action). For example, when the intent is to request time off, the type of paid leave and the dates for the leave entities are required before the chatbot can help with the request.
 For this service we created one new entity and used @sys-date system entity.

  • @vacation-type

Equivalent question for this entity is "Is this paid or unpaid time off?" or its variation.


    • Entity Values:
      • Unpaid Leave; Synonyms: unpaid, Leave of absence
      • Jury Duty; Synonyms: jury
      • Annual Leave; Synonyms: annual, paid time off, paid
      • Maternity/Paternity Leave; Synonyms: maternity, paternity, child bonding, disability
      • Sick Leave; Synonyms: sick, illness

For more information about creating entities, please refer to the following link:
https://cloud.ibm.com/docs/assistant?topic=assistant-entities

  • @sys-date

This is a system entity. For more information about system entities, please refer to the following link:
https://cloud.ibm.com/docs/assistant?topic=assistant-system-entities#system-entities-sys-date-time
Dialog Nodes:
Tip: The dialog uses the intents that are identified in the user's input, plus context from the application, to interact with the user and ultimately provide a useful response. For more information about creating Dialog flows please refer to the following link:
https://cloud.ibm.com/docs/assistant?topic=assistant-dialog-overview
When creating a new service, that was not created using the Chatbot publishing wizard, it is recommended to copy an existing dialog node that is like your service use case, to get the needed JSON content.
(Note: You can use the dialog nodes that come with this starter kit for this purpose, i.e. copy the node and make the necessary edits needed for your use case)
 Note: For the Request Time Off use case we have configured two Dialog nodes,

  • BMC – Time off
  • BMC - Check Leave Balance

From the HR Chatbot skill, go to the Dialog section and look for the BMC – Time off dialog. This is our first parent dialog node for this service. We have added the intent, #PTO in the condition, as shown below, so that when Watson identifies this intent the parent dialog for this service gets triggered. Tip: Within the parent node, in the Then Set Context section, it is good practice to delete / initialize all context variables that will be used by the Dialog flow.
 We have done this in the dialog node as shown below,
worddav0b413c8b3e81e8c2f6f57290f11ecc97.png
worddaveb0754c53c669a6639cfac2846a11016.png
Next we will review the child dialog nodes for the parent BMC – Time off dialog:

  1. After the parent dialog has executed, Watson proceeds to the #BMC - leave balance dialog node. From here, we first check to see if the user has requested their leave balance (i.e. does the $leaveBalance variable have data), if the user has not already checked their leave balance in a session, then Watson triggers the Innovation Studio process "com.bmc.chatbot.chatbotstarterkit-lib:Get Leave Balance" to fetch the user's leave balance. This is the same Get Leave Balance process which we tested earlier. Next we will look at the JSON created for this service. From the dialog node, click on the three vertical dots as seen from the highlighted section in the screenshot below. As we saw earlier, there is no input for this process and just one output. The same can be seen in JSON screenshot below. Note: For more information about updating JSON, please refer to the following link: Customizing the chatbot actions.

worddava683e254f9601fe8b8efb51a0da321aa.png

  1. The next dialog we will configure is the Fill Questions dialog. This dialog will execute if $leavebalance variable is not null. If it's not null, then we will ask the following questions. In the Then Check for section below you will see that we have created three slots for the three different questions. For more information about how to create slots, please refer to the following link: https://cloud.ibm.com/docs/assistant?topic=assistant-tutorial-slots

worddavdf689778e78ab5439a6236126c47d113.png
The following questions are configured for this use case:


    1. First question: Is this paid or unpaid time off?In the first slot, click the worddavccf2d3c26e0d535f5121632ef9d6919c.pngicon to open that slot's configuration as shown in the screenshot below. There you will see the if the @vacation-type entity is not recognized in the user's utterance then this question will be asked. The user's response to the question will get stored in $vacationType variable.In the first slot, click the

worddav00b002183fdf51961d776e7ef4b3c233.png


    1. Second Question: When would you like the time off to start? Once you answer the first question Watson will ask the second question. Open the second slot configuration details (as we did in previous question). If the @sys-date system entity is not recognized within user's utterance and $startDate variable is not null, then the question will be asked, and the user's response will get stored in $startDate variable. In this question, we applied some extra logic (i.e. a workaround), because of an IBM Watson Assistant limitation regarding the available date difference function. For our use case, we want to compare the leave start date and end date which the user has entered and decide if user has enough leave balance for their request. The workaround is as follows: From the slot 2 configuration popup, go to the When user responds, if intent or entity is section as shown below. There you will see the handler that has been configured. 
      worddav8abf11a2d8669833e7af5f219e709c6c.png Open that handler by clicking the worddavccf2d3c26e0d535f5121632ef9d6919c.pngicon. In the handler configuration you will see the following context variable set to; sysDateplusDays = "<? @sys-date.plusDays($leaveBalance.toInt()) ?>" as shown below. Because the @sys-date is already identified in the input, we add the @leavebalance variable value to it. Note, that the @sys-date entity has different functions available, of which we used plusDays to add leave balance to @sys-date. The $sysDateplusDays variable is then used to compare it with end-date in next question. worddav7f84a9b5e5f52f60bd21d521b07cb341.pngOnce you answer the first question Watson will ask the second question. Open the second slot configuration details If the In this question
    2. Third question: When would you like the time off to end? Open the third slot configuration. If no end date is specified in the earlier utterance, then this question will be asked. For example, if the user says "I need paid time off next week" then end date is selected as last day of next week. End date is recognized by the @sys-date entity and stored in the $endDate variable. Since there is no Watson function to convert a string to a date, we apply the following work around within slot 3. Go to the When user responds, if intent or entity is section as shown below. There you will see the handler that has been configured. 
      worddavd65b9c67d6ee83981c3cbe8f34470cf1.png Open that handler by clicking the worddavccf2d3c26e0d535f5121632ef9d6919c.pngicon. In the handler configuration you will see the following context variable set to, isInsufficientLeaveBalance = "<? $sysDateplusDays.before(@sys-date) ?>" as shown below. Here the $sysDateplusDays is same variable which is set in second question. before is the date function used to check if $sysDateplusDays is before the @sys-date. The output of this statement will be either "true" or "false". This value will be stored in the $isInsufficientLeaveBalanceis variable which is then used in the next dialog node. 
      worddav7c45854db73dc7701732580aa7221491.png

      Open the third slot configuration. If no end date is specified in the earlier utterance, then this question will be asked. For example, if the user says "I need paid time off next week" then end date is selected as last day of next week. End date is recognized by the
  1. The next dialog node is the Check if leave balance sufficient dialog. In this dialog we use the $isInsufficientLeaveBalanceis variable to check if user has sufficient leave balance. If the user doesn't have enough leave balance to apply for leave, then a prompt is displayed saying, "Your available leave balance is {actual_value}. You don't have enough paid leave balance. It will be applied as Unpaid leave. Do you want to continue?". The user will be given option to continue or exit from requesting for time off. Those options are evaluated by the option:yes and option:no child dialog nodes.
  2. The next dialog node is the confirm dialog. If the user has enough leave balance or they selected to continue as unpaid leave, then the following confirmation message is displayed, "Great. I will submit {actual_value} to your manager for time off from {actual_value} to {actual_value} out of available leave balance {actual_value}. Can you confirm that this is correct?". The user will be given the option to submit the request, (i.e. "Yes") or to not submit the request, (i.e. "No").
  3. If user selects "Yes", i.e. they submit the request of time off, the Option:yes dialog node is triggered. From there the Innovation Studio process com.bmc.chatbot.chatbotstarterkit-lib:Request Time Off, will be triggered to submit the request. This can be seen from within the JSON shown in the screenshot below. 
    worddav157a616042f300de06f48260e5452754.png
  4.  The numbers starting with 5368709XX, are the process variables IDs which we declared in com.bmc.chatbot.chatbotstarterkit-lib:Request Time Off process.
  5. Next we will review the Prepare Unpaid Leave Message Dialog node. This Dialog will check if any unpaid leave has been applied. If it has been applied, then we configure a message for it and store it in $unpaidLeaveMessage variable.
  6. The final Thank you Dialog node, we display the final message after submitting request. The message displayed is, "Thank You. I have submitted your time off request. Your available leave balance is $leaveBalance $unpaidLeaveMessage" where the $leaveBalanceis the actual value and the $unpaidLeaveMessage set by the previous dialog node is displayed.


From the HR Chatbot skill, go to the Dialog section and look for the Check Leave Balance dialog. This is our second parent dialog node for this service. We have added the intent, #checkleavebalance in the condition, so that when Watson identifies this intent, this parent dialog gets triggered.
The purpose if this dialog is to get and/or show the user's leave balance. This dialog is designed to get the user's leave balance if it hasn't already been retrieved during an active session. To achieve this, the $leaveBalance variable is not initialized in this dialog. If the $leaveBalance variable is null then the leave Balance not initialized dialog node gets executed and Innovation Studio com.bmc.chatbot.chatbotstarterkit-lib:Get Leave Balance process runs and the output is stored into $leaveBalance variable as shown below.
worddav6fae751c3d48236adc3588cc8fbdf828.png
This way we get latest leave balance. As we have seen earlier, the Innovation studio process is just returning a static value. By using BMC Helix Innovation Studio capabilities, you can get the leave details from some other application and return leave balance here.
Most likely, when a user checks their leave balance, they also want to apply for leave as well. So here we have provided an option to apply for leave if the user wants to. From the Show Leave Balance dialog, we display the available balance and ask the question "Do you want to submit time off?" and provide the user with a Yes - No option. If the user selects, "Yes" (as seen from the Jump to Time off Request Dialog node), then control jumps to Time Off service and that service dialog flow starts.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*