article by Rohit Dhamija, May 2020
The Digital Assistant Client SDK for Oracle Web provides you with a widget that enables you to run a skill in a web page. This article explains how users of an Oracle Digital Assistant chatbot conversation can upload images and documents through the Oracle Web SDK.
About content upload in the Oracle Web SDK
The Oracle Web SDK has an integrated document and image upload functionality that saves content in Oracle Cloud Infrastructure (OCI) storage service. Once the content is uploaded, the server returns a JSON payload similar to the payload shown below
{
"messagePayload": {
"attachment": {
"type": "image",
"URL": "http://your-oda-instance.com/attachment/v1/attachments/d43fd051-02cf-4c62-a422-313979eb9d55"
},
"type": "attachment"
},
"userId": "guest"
}
The payload is sent as a message to Oracle Digital Assistant where it can be passed to a custom component for further processing of the uploaded content. Note that he Oracle Cloud Infrastructure (OCI) storage service that the content got uploaded to is not meant to be a permanent storage but only for temporary use. To save documents and images permanently, or to process them, a custom component is needed that loads the content from the storage service.
Accessing the payload in a custom component
You access the attachment content of the JSON payload shown before using custom component code similar to the one shown below:
…
let attachment = conversation.attachment();
//if the message sent to the custom component does not contain an attachment, then the call
//above returns null. Otherwise the JSON attachment part of the JSON object payload is returned.
let fileurl = attachment != null? attachment.url : null;
//the sample code logs the storage URL. In your custom component, you would pass the URL
//to code that downloads and further processes the content,
conversation.logger().info('Attachment URL: ' + fileurl);
…
About the sample
The sample you can download for this article, if run using the Oracle Web SDK as a messenger, uploads content like an images to the before mentioned temporary storage in OCI and passes the returned payload as a message to a custom component. The custom component extracts and saves the uploaded file URL to a dialog flow variable in BotML for display. The BotML code of the sample is shown below:
uploadDocument:
component: "uploadfile"
properties:
variable: "variable"
transitions:
actions:
success: "uploadSuccess"
error: "uploadError"
next: "uploadError"
uploadSuccess:
component: "System.Output"
properties:
text: |-
Upload completed
URL: ${variable.value}
Thanks.
keepTurn: false
transitions:
return: "done"
When you run the skill from the web, you see the following bot conversation
Notice the use of the paper clip icon to select and upload an image or document from the user local file system.
Note: bee image courtesy of pixabay.com
File types supported for upload using the Oracle Web SDK
aac, 3g2, 3gp, 7z, aac, amr, avi, csv, doc, docx, eml, gif, ics, jfif, jpeg, jpg, key, log, m4a, m4v, mov, mp3, mp4, mp4a, mpeg, mpg, mpga, neon, numbers, odt, oga, ogg, ogv, pages, pdf, png, pps, ppsx, ppt, pptx, qt, svg, tif, tiff, txt, vcf, wav, webm, webp, wmv, xls, xlsx, xml, yml, yaml
To run the sample
Do the following to run the sample on your own Oracle Digital Assistant instance
- Ensure you have an instance of Oracle Digital Assistant version 20.x or later
- Download and import the SAMPLE SKILL (ZIP)
- Expose the sample skill on the Oracle Web channel
- Configure and use the Oracle Web SDK (download from the "Oracle Native Client SDKs (for OCI Native environments" section at https://www.oracle.com/downloads/cloud/amce-downloads.html) to access the web channel
- Start the conversation by typing "hi"
- Use the paper clip icon to select an image from your file system
Sample Skill
Download the custom component source code
Related Content
Oracle Web channel product documentation
TechExchange: How-to Download Documents in Oracle Digital Assistant Conversations
TechExchange: How To Create A Custom Drop-Down Menu In The Oracle Web SDK
TechExchange: How to Optimize The Display of Long Texts in Oracle Digital Assistant Web Messenger
TechExchange Quick-Tip: Extending the Oracle Web SDK Delegate Feature To Execute Code Asynchronously
Oracle TechExchange: Integrating the Oracle Digital Assistant Web SDK Messenger to Oracle JET web applications