By Frank Nimphius
“At the third stroke, the time from BT will be [hour] [minute] and [second] seconds.” Almost forgotten, but still in use, is the speaking clock. A speaking clock is a service provided by telephone businesses and other organizations that announces the correct time in intervals of 10 seconds.
If, from time to time, it could say, “My goodness, time goes by really fast today. At the third stroke, the time from BT will be [hour] [minute] and [second] seconds,” the clock would not only be more engaging but also feel more natural, because humans use different phrases when saying things repeatedly.
Unlike a speaking clock that is designed for a short consumer interaction and that does not need to be engaging, chatbots are supposed to have longer interactions with users while assisting them to complete a task on the conversational channel.
Chatbots are not humans and should not pretend they are, but conversations between bots and humans must be designed to be vivid, natural, and appealing to humans. Alternating bot responses is one technique to apply to your chatbots to improve user experience.
Following the hands-on instructions in this article, you will implement alternating bot responses for a skill in Oracle Digital Assistant. For this you will be using resource bundles referenced from the dialog flow and from items in a composite bag entity.
Below are the prerequisites for following along with the hands-on steps in this article:
Follow these initial hands-on steps to start the service and import and test the bot.
https://<your cloud URL>/botsui/
into the URL field.starter
folder.OraMagTravel(1.0).zip
starter bot file and click Open.Note: If you don’t see the imported bot because other bots fill your screen, type Ora
into the Filter field above the + New Skill tile.
What you just did: By importing the OraMagTravel(1.0).zip
file, you installed the travel bot sample skill. The sample bot does not use natural language processing (NLP) or machine learning (ML), so there is no need to train the skill.
Before you implement alternating bot messages, first experience the bot from a user perspective.
Hi
into the Message field and press the Enter key.Miami
into the Message field and press the Enter key again.Lisbon
into the Message field and press the Enter key.August 20 2019
.never
.What happened: The travel bot validated your input against a custom entity for destinations and the DATE
system entity. When you provided an invalid user input, the dialog box asked for a valid entry using the same message displayed before. In a human conversation, this would not be the case. Also in a human conversation, the response of the person you talk to would not be the same each time you say, “Hi.”
Note: A previous Oracle Magazine article explained how to handle input validation errors gracefully. The focus of this article is on alternating prompts.
Using references to resource bundles is common practice in software development for displaying labels, prompts, and similar messages. Resource bundles not only make it easy for you to maintain strings but they also allow you to build translatable user interfaces.
The starter skill that you imported includes a resource bundle created for English. Before you can start building alternating bot responses, take a look at the strings and their keys.
welcome_prompt4
.Hello {0}, I am ''Up-n-Away'' your speedy travel assistant
(as shown in Figure 1). The “{0}” reference is a parameter that allows bot designers to inject data into the resource bundle message.Figure 1: Creating a new resource string key and message
welcome_prompt
keys use parameters in their messages.What you’ve seen: In this section, you’ve seen part of the solution for implementing alternating bot responses in Oracle Digital Assistant. For each message, label, or prompt to be displayed in a conversation, you create multiple resource bundle entries. The resource bundle keys defined for a dialog flow state differ by a consecutive number. The other part of the solution is the generation of a random number that determines the prompt, label, or message to display at runtime.
In this section, you are going to implement an alternating bot message for the welcome message. Ensure that you have the dialog flow builder open by selecting the Flows icon (), as instructed in step 30.
returnDate
variable (in line 13). If needed, use blank spaces to align the cursor.rb
of type resourcebundle
. To do this, type rb: "resourcebundle"
."Hi ${profile.firstName}, I am 'Up-n-Away', your travel
booking assistant. Let's get your booking rolling."
${rb('welcome_prompt${(.now?long %
4)+1}','${profile.firstName}')}
welcome_prompt.txt
file located in the strings
folder of the extracted resources for this article.Hi
into the Message field and press the Enter key.Hi
into the Message field and press the Enter key. This should display a different welcome message.Note: This example uses four possible messages to greet users. There is a possibility that two consecutive runs will display the same message, but the likelihood that alternative messages will be displayed increases with the number of message keys added for a prompt or bot response.
How it works: For the welcome message, there are four keys defined in the message bundle. An Apache FreeMarker expression is used to generate a number between 1 and 4. There is no dynamic way to determine the number of keys defined for a message, so the number of available welcome messages needs to be provided using % 4
. To create a random number, the expression uses the current date in milliseconds, which it accesses through the .now
reference. The generated number is then appended to the welcome_prompt
string to build a valid key contained in the message bundle.
Note: Some of the welcome_prompt
keys use a parameter to add the user name to the message. For this you passed ${profile.firstname}
as a second argument in the expression. If a message does not support parameters, this second argument is ignored.
In this section, you are going to replace all other string messages with resource bundle references. For simplicity, the starter skill has three resource bundle keys defined for each message.
prompt
property from
"Where would you like to go to?"
${rb('destination_prompt${(.now?long % 3)+1}')}
destination_prompt.txt
file located in the strings
folder of the extracted resources for this article.prompt
property from
"Please provide a start date"
"${rb('departureDate_prompt${(.now?long % 3)+1}')}"
departureDate_prompt.txt
file located in the strings
folder of the extracted resources for this article.text
property to the string below. You can copy the expression from the confirmation_prompt.txt
file located in the strings
folder of the extracted resources for this article.
${rb('confirmation_prompt${(.now?long % 3)+1}',
'${destination.value}','${startDate.value.date?
long?number_to_date?string("dd-MMM-yyyy")}',
'${returnDate.value.date?long?number_to_date?
string("dd-MMM-yyyy")}')}
Figure 2: Prompt expression not enclosed within double quotation marks.
confirmation_prompt.txt
, it will be in a single line, which is perfectly OK.
Hi
into the Message field and press the Enter key.August 20 2019
.August 31 2019
.Note: In step 44, the Apache FreeMarker expression is added as a value to the text
property without surrounding quotes. The reason for this is that double quotation marks are used in the formatting of the dates: ?string("dd-MMM-yyyy")
. Adding surrounding double quotation marks to the expression as a whole would have led to an invalid BotML document.
Did you notice there is no alternating message defined yet for the prompt of the setEndDate
dialog flow state in line 53? Well, how about a challenge? Try building the expression yourself considering the following information:
returnDate_prompt
.Note: To verify your solution, or to skip this challenge on a lazy day, you can find the correct expression in the returnDate_prompt.txt
file located in the strings
folder of the extracted resources for this article.
With this addition, you have completed the first part of this hands-on exercise. All skill bot prompts and text responses should now use alternating messages and appear less robotic. You can find a completed solution—OraMagTravel_Completed(1.0).zip
—in the completed
folder of the extracted downloads for this article.
Composite bag entities are like business domain objects and encapsulate multiple entities and variables into a single object. A composite bag entity, for example, could represent an order, an account, a product, and more.
Besides being business oriented, the benefit of composite bag entities is that they resolve themselves at runtime by generating the dialog boxes needed for a user to provide required entity information.
Because composite bag entities generate the bot conversation flow at runtime, you don’t build dialog flow states, which has an impact on how you define prompts. In the next sections, you will learn how to define prompts for composite bag entities and how to define them so they display alternating responses.
To start working with composite bag entities, first import the composite bag skill.
Figure 3: Left arrow icon in the skill builder header to exit skill editing
starter
folder.OraMagTravelCompositeBag(1.0).zip
starter bot file, and click Open.Ora
into the Filter field above the + New Skill tile.As mentioned earlier, prompts ideally reference resource bundles, so they are easy to maintain and support translations. In this section, you are defining prompts for composite bag entity items and adding the composite bag entity to the dialog flow using the System.ResolveEntities
component.
${rb.departureDate_prompt1}
into the Prompt field.${rb.departureDate_prompt2}
and ${rb.departureDate_prompt3}
.Figure 4: Definition of three departure date prompts
Bag Item | Prompts |
TravelDestination | |
${rb.destination_prompt1} |
|
${rb.destination_prompt2} |
|
${rb.destination_prompt3} |
|
EndDate | |
${rb.returnDate_prompt1} |
|
${rb.returnDate_prompt2} |
|
${rb.returnDate_prompt3} |
rb
of type resourcebundle
has been defined already for you (in line 11). This variable is mandatory for the skill to use resource bundle references, not only in dialog flows but also in composite bag entities.travelBooking
variable (in line 10), which, as a type, is set to the name of the composite bag entity (TravelBooking
).System.ResolveEntities
component state to the dialog flow. To do this, first click the + Components button at the top of the editor.resolveEntities
state name to selectDestination
.variable
property value to "travelBooking"
.
variable: "travelBooking"
nlpResultVariable:
maxPrompts:
cancelPolicy:
transitionAfterMatch:
autoNumberPostbackActions:
headerText:
footerText:
showMoreLabel:
translate:
selectDestination:
component: "System.ResolveEntities"
properties:
variable: "travelBooking"
transitions:
next: "printConfirmation"
Note that the size of each indentation is two blank spaces.
What you just did: In this section, you created prompts for the three bag items defined in the TravelBooking composite bag entity. For each item, you defined three prompts that reference resource bundle strings. The resource bundle strings are the same as were used in the first part of this hands-on exercise. To resolve the composite bag entity, you used a component template for the System.ResolveEntities
component. To resolve the component to the composite bag entity, you referenced the travelBooking
variable, which is of type TravelBooking
from the component’s variable
property.
Now test the user experience with the composite bag entity.
Hi
into the Message field and press the Enter key on your keyboard.Hello
into the Message field and press the Enter key.August 20 2019
into the Message field and press the Enter key.Lisbon
when prompted for a destination. Because Lisbon is an invalid value, a prompt appears, this time with a different message.printConfirmation
state and notice the variable reference to the composite bag entity being used to pass parameter values to the resource bundle.Note: By default, the composite bag items use sequences to determine when to show which message. Because of the sequences, the prompts are displayed the same when rerunning the whole conversation. To see alternating prompts, you either need to cause a field to be rerendered, as you did by providing invalid values for a prompt, or you need to remove the sequence numbers.
Both approaches, showing alternating messages in a sequence and showing them in random order, have their use cases. Sequences are good for “escalating” user input failure, because the initial prompt in the sequence can be short while subsequent prompts can provide more information about what the user is expected to provide.
Note: You can find a completed solution—OraMagTravelCompositeBag_Completed(1.0).zip
—in the completed
folder of the extracted downloads for this article.
In this article, you learned about the two approaches in Oracle Digital Assistant to implementing alternating bot response messages for chatbots to make them appear less robotic. In real bot implementations, you will use both approaches—random messages defined in the dialog flow and messages defined on composite bag entity items—because there are no restrictions on how and when to use composite bag entities within a bot conversation.
READ more about the speaking clock.
DOWNLOAD the bot for this article.
Illustration by Wes Rowell
Frank Nimphius is a Master Principal Product Manager at Oracle Corporation where he works on Oracle Digital Assistant and Health AI
Frank joined Oracle Product Management more than 20 years ago and since then worked on various Oracle products including Oracle Forms, Oracle JDeveloper, Oracle Application Development Framework (ADF) and the Mobile Application Framework (MAF) and Oracle Mobile Hub.
In his 20+ years at Oracle Frank enjoyed the many opportunities the job offered and became an author, an in-class and online-video trainer, a presenter at various international conferences, a collateral and training writer, a Java developer, as well as a product marketer and blogger.