article by Frank Nimphius, July 2022
Oracle Digital Assistant allows developers to create multilingual assistants and skills. Similarly, the Oracle Web SDK messenger can be configured for a specific user language so that intent is understood and messages are displayed in that language.
Another Web SDK messenger feature widely used by our customers is ability to trigger the digital assistant to start the conversation when a user opens the messenger widget. This start of a conversation can be anything from a simple personalized welcome message, a reminder of what the user worked on last time, or an overview of tasks a user has scheduled next.
The previously mentioned feature works in that the messenger sends a hidden user message, which for multilingual digital assistants must be in a language supported by the digital assistant.
This article explain how a simple addition to the Web SDK configuration can detect the user language configured in the browser to then send a start message in this language. It also handles the case in which the browser language is not a language supported by the digital assistant.
Pre-requisite
This article assumes that you have built your digital assistant to use native NLU language support to enable at least one additional language besides the base language you used to develop the digital assistant.
The solution at runtime
The digital assistant in the screen shots below supports users in ordering pasta. When the user opens the Oracle Web SDK messenger widget on the web page, then a hidden message is sent to the server to start the order process in English.
Changing the browser language in Google Chrome (image below) to German displays the same conversation in German after restarting the browser (a restart is required by the browser to pick up the language setting)
The pasta order conversation in German is displayed below
How to set it up
You can download the Oracle Web SDK from here. After unzipping the dowloaded package file, you see the following structure on your file system
The Web SDK configuration is added in the settings.js file located in the scripts folder. To keep the setup simple, use the scripts-auth-disabled folder. Configure the settings.js file as shown in the image below.
- Set your ODA instance host name to the URI property
- Set the channelId property to the channel ID of the Oracle Digital Assistant web channel
- Add the initUserProfile and initUserHiddenMessage properties to set the user language tag and the language specific initial message to start the conversation
For you to copy and paste, add the following code to the top of the settings.js file
const browserLanguage = navigator.languages && navigator.languages.length? navigator.languages[0] : navigator.language;
var initMessage = {en: 'I want to order pasta', de: 'Ich möchte Pasta bestellen'};
Notice the initMessage variable that is defined as an object with properties named after the supported languages ("en" and "de" in the sample)
Then, in the chatWidgetSettings object, add the following entries
initUserProfile: {profile: {languageTag: browserLanguage}},
initUserHiddenMessage : initMessage[browserLanguage] != null? initMessage[browserLanguage] : initMessage['en'],
Notice that the default language is set to "en" so that if the browser language is not supported by the digital assistant, a default – English – is used.
How to run the sample
You can run the sample from your local machine by invoking the index.html file
Download the sample skill
The YAML based sample digital assistant can be downloaded from here
Related Content
Access a Skill from Your Website (tutorial, uses Web SDK)
Secure Your Oracle Web SDK Chat