article by Frank Nimphius, March 2023

 

Answering frequently asked questions is a popular use case for chatbots. In Oracle Digital Assistant, FAQs are defined as answer intents. Answer intents are special types of intents that resolve a predefined response based on a trained NLP model. With NLP, the correct answer will be displayed even if the user doesn't send exactly one of the questions and utterances the bot was trained on.

For humans, however, it is unlikely that they would use exactly the same wording when answering a question they have previously answered. This raises the question of how answer intents can be created so that different wordings are used when a question is answered again – just for the bot to appear a little bit more human like. 

This article explains how you can define multiple answers for an answer intent, so that if a user asks the same question again (in one way or the other), she most likely will see the answer with a different wording. I say "most likely" because the wording for an answers is picked by random.

Showing alternating answer intent messages in practice

Below image shows the sample skill that you can download at the end of this article in action. For simplicity and better visualization, the alternating answer intent messages are "About ODA 1", "About ODA 2", "and About ODA 3". In your bot implementation, you would use an alternate wording for the answer you want to provide for each of the answer intent messages. 

To run the sample, after you downloaded the sample skill and imported it to your Oracle Digital Assistant instance, open the skill's conversation tester and type "what is Oracle Digital Assistant" multiple times. As shown in the image below, the way the solution works is that the skill shows one of the three answers in random and repetitive order.

Alternating messages for answer intents

Defining the answer intents

Answer intents are like regular intents in that they are trained using sample utterances. The difference to regular intents is that answer intents display a pre-defined answer when the intent resolves. In the image below, the answer text is defined as "dummy" for all answer intents. To create answer intents and not regular intents, an intent must have an answer defined, even if the answer isn't used (like in this example).

It is important, as shown in the image below, that the Conversation Name is set to the question that is answered by the intent. It is good conversation practice to put an answer into context. Using the Conversation Name to hold the question also prepares your FAQ bot to be used with multiple languages. 

Defining answer intents

Defining the answers for a question (answer intent)

Another good practice in conversation design is to put text into message bundles so copy writers find it easy to edit it. As with putting the question into the conversation name field, the use of resource bundles allows your FAQ bot to be used with multiple languages.

The image below shows the resource bundles for the Conversation Name. The sample has two answer intents defined and thus then Intent section in the resource bundle shows 2 entries. Notice that the key name of the intent resources start with systemFlowName_ followed by the intent name. This knowledge is required later when displaying the queston on top of an answer.

Resource bundle for intents

Creating user defined resource bundle entries for intents is the secret source of the solution explained in this article. For each answer intent you create multiple resource bundle entries. The resource bundle keys must follow the following naming convention.

<intent name>.answer<number>, e.g. reag.ans.aboutODA.message1

The number of answers per question is totally up to you but must be a consistent number between all answer intents. 

Note: The sample you can download from this article uses 3 answers per intent. The more answers you define the more likely is that asking the same question twice will show alternating answers. 

user defined resource bundles holding answers

Mapping answer intents to a common flow

Oracle Digital Assistant Visual Flow Designer (VFD) allows developers to map all answer intents into a single conversation flow for displaying answers at runtime. To do this, select the Main Flow and select (+) on the Built.In Events category.

Mapping answer intents to a specific flow

Select Answer Intent from the list and map it to the flow that handles displaying answers. In the sample skill you can download  at the end of this article, this flow is named "global.faq" (shown in the image below)

Note: Make sure you have created the flow before mapping the answer intents. The name of the flow is totally up to you and does not need to be "global.faq" as used in the sample. 

mapping of answer intents to specific flow

Defining the common FAQ flow

Next it is time to configure the answer flow with two flow states

  1. A SetVariable state to set a random index number
  2. A Common Response Component state to display the question and the random selected answer

First, create a SetVariable state by choosing Add State on the flow's start state node. The dialog shown in the image below allows you to create a SetVariable state by selecting the Variables and then SetVariable option.

Adding SetVariable state to flow

Next, choose Add State from the context menu of the SetVariable state. In the component state dialog, select User Messaging and then Display Multi Media Messages. In the Display Multi Media Messages menu, select the Display Intent Answer option. This will create a Common Response component state that is readily setup for answers intents. Still you will need to apply changes, but these are simply a copy and paste from code provided in this article.

adding answer intent state

In the flow designer, select the SelectVariable state (the sample has this state named "setAnswerIndex"). Use the Create button to create a new flow scope variable of type Integer. This variable is set to a random number by the SelectVariable state and is used in the second dialog flow state to select which message to print. 

Note: If you use created 3 resource bundle entries per intent (as used in the sample), the expression to add as the Setvariable state expression is ${(.now?long % 3)+1} . Make sure the Expression toggle is enabled so the SetVariable state does interpret the expression. 

Setting random value to variable in SetVariable state

Next, select the state that displays the answers (which is the second state you created). Use the Edit Response Items button in the Component tab to open the edit dialog.

Editing answer state

Remove the existing content in this dialog and replace it with the expressions shown in the image below.

modified answer state configuration

Here is the expression again for you to copy and paste.

responseItems:
  – text: "${rb('systemFlowName_'+skill.system.nlpresult.value.intentMatches.summary[0].intent)}"
    type: text
  – text: "${rb(skill.system.nlpresult.value.intentMatches.summary[0].intent+'.message'+answerIndex.value)}"
    type: text

The expression has two text nodes. The first node prints the question for an answer (its the string you defined as the conversation name for each answer intent). The message is the string defined as the Conversation Name in the intent. The second node prints the answer. The index variable that you created when configuring the SetVariable state is used to determine which of the resource bundle entries should be used for printing the answer. 

 

Sample Download

Below is the link to the skill used in the screen shots of this article.

Download Sample Skill (zip)

Author