article by Frank Nimphius, January 2019

All bot responses are messages. The most common output is the text message that prints in a bubble. Especially at the end of a bot task, bot designers look for a way to print a summary of outcome of the user-bot interaction. For this, designers have different requirements

  • Print text messages in Multiple Bubbles
  • Print multi-line text messages in a single bubble

Printing Messages in Multiple Bubbles

In Oracle Digital Assistant, a message in a bubble is the outcome of a System.Output component, a System.CommonResponse component, or calls to conversation.reply(message) in a custom component. From a UX perspective, printing messages in multiple bubbles appears more engaging than a long message in a single bubble. Well, at least until you print too many message bubbles so the user loses orientation with this approach.

The key to printing multiple messages in a bubble is to keep on printing message without waiting for users to provide another input. Here's How you do it

System.Output

The System.Output component has a text property that bot designers use to reference message content from, or type messages in. At runtime, the output component prints a message to then wait for user input. To continue printing, the System.Output component has a keepTurn property that by default is set to false. Set the keepTurn property to true on a System.Output component and the dialog flow continuous to the next state until a state is reached that actually has keepTurn set to false, or is an input component that awaits user input.

The dialog flow code (BotML) below prints messages from the message array. It uses Apache FreeMarker expressions to determine the size of the array and to increment the runner variable. A System.Switch component checks whether the loop has printed all messages or not. If all messages were printed, then Switch component transitions to a state that has a return transition or keepTurn set to false. In the example below, the last System.Output component ends the conversation by returning "done"

The code above prints the following messages.

System.CommonResponse

The System.CommonResponse component is the Clark Kent among the components Oracle Digital Assistant provides off the shelves. As you see in the code below, the component knows itself how to iterate arrays and prints message bubbles from its text  response type. The key to success for this component for this use case is to set processUserMessages to false, which turns the text response type into a read-only label, and to set the separateBubbles property to true. The separateBubbles property is set to false by default and would print all messages in a single bubble. 

The output of this component is the same as before and shown in the image below

Print multi-line text messages in a single bubble

In some cases you may want the messages to be printed in a single bubble. Again, you have at least to options.

System.CommonResponse

The System.CommonResponse component can be used with its separateBubbles property set to false. This probably is the easiest way of doing this

Note the "\n" character at the end of the text property. This character actually add the carriage return when a message string is printed. The line break character may not work on all channels, but certainly does for those that support Rich media output.

The message gets printed as shown below

System.Output

Last but not least, you can use the System.Output component along with Apache FreeMarker scripts to print the content of an array in multiple lines. The secret here is the |- combination

The Apache FreeMarker expression is used to iterate over the array of text messages. For each item in the array it then prints the text and adds a new line. Again, the output shows as 

Which one to use?

Well, all options are valid to use. Whether you print messages in a single or multiple bubbles is up to you and your taste. Common sense forbids long messages that are printed in a single message bubble. The rule is that if you make me scroll, I go. So make sure users have it easy to read and digest your messages. 

From a component position, I think the Common Response component should be your go-to component for all two use cases. The one reason to use System.Output I see is if the multi-line messages are not read from an array but directly added to the text property. Here the System.Output component means less code to write (though its minimally less). Anyway, I suggest the Common Response component. 

Related Articles

TechExchange – Using Apache Freemarker Expression in Oracle Intelligent Bots

TechExchange – Building Smart Value Lists from Entities

Author