article by Frank Nimphius, April 2021

 

Most if not all messengers support attachments for users to share documents with a chatbot.

Unfortunately, chatbots don't control the messenger and therefore users could send attachments to a point in time where the bot does not expect an attachment to be sent. While you cannot prevent users from sending attachments, you can handle the gracefully.

This article explains how you can suppress attachments in Oracle Digital Assistant skills. 

How attachments are sent

Attachments are sent as JSON objects that contain information about the type of attachment and the URL from which the bot can download the document. 

Problem statement

When a conversation state is waiting for user input and that user input is not validated against an entity but is stored in a string variable, users who upload attachments without being prompted for an attachment actually risk to interrupt the conversation flow. 

To avoid this in Oracle Digital Assistant, you can use a default transition handler in a skill that detects an attachment to be received and then prints a user message before proceeding with the current state of the conversation.

Example

The skill in this example has two conversation states defined where users a prompted for input. In both cases, the user input is not validated against entity type variables and therefore happily accept an attachment being uploaded. 

To handle attachments gracefully without breaking the user user conversation, the sample uses a default transition (image below) that directs all attachment requests to a specific dialog flow state.

The collectStates dialog flow state uses a custom component to retrieve an array dialog flow states that has the most recent state – the one to which a user uploaded the attachment – as its first element (see image below)

With this information, programmatically you can now navigate back to the state that originally awaited the user input. However, before you can do so, you need to reset all variables that need to be reset (keep in mind that the variable most likely expects a string, which it received in form of a JSON string). 

The code shown in the image below, prints a message to the user, alerting her about the problem with the attachment as a not expected input. It then uses the dialog flow name retrieved by the custom component  to lookup the names of variables that need to be reset in the resetVariables dialog flow state.

The variable names are looked up from a map that was added to the top of the dialog flow at design time

Note that the contains dialog flow states that expect user input and that don't have their own "attachmentReceived" transition defined. Dialog flow state that have their own attachmentReceived transition defined don't use the default transition. This also means that if there is a state that expects users to send attachments, you set the "attachmentReceived" transition for this state

Sample at Runtime

Run the sample in the conversation tester or using the Oracle web messenger. Start the conversation with "hi" or similar. When prompted for your name, upload an image. In the conversation tester you would click on the attachment button and then paste an image URL into the URL field. In the Oracle web messenger (websdk) you can upload an image from your local machine.

The image above shows the prompting for the name and the attachment sent using the embedded skill conversation tester. A message is printed for the user to understand that an attachment wasn't expected before the "name" prompt is displayed again. 

You will observe the same behavior when you provide a name when prompted for a name and then upload an attachment when prompted for your favorite meal. The difference is that in this case you will be prompted again for providing your favorite meal and not the name. 

Custom Component

For completeness, and for the the geeks out there, here is an image showing the custom component code

 

Related Content

TechExchange: How-to Download Documents in Oracle Digital Assistant Conversations

 

 

 

 

Author