Skip to main content

Bot Design Patterns : Multi-bot approach

Oracle Bots comes with platform Translation services, which you can connect to Google or Microsoft services to translate the bot to user default locale.
But what if you want to control this auto-translation and restrict the bot to only a few languages. Or want to do Intent matching properly or extracting the Entities properly depending on the language.
In the following Bot Design pattern, I will explain how to approach a development of an Oracle Bot which support multiple languages with different Intents and Entity sets.

Before I start, I have to give credit to Oracle A-Team for this, they are the one who first introduced this, I am merely a message-borrower in there. So special thanks to Tamer Qumhieh and Steven Davelaar.

The Situation

You need to create a bot which can respond to multiple languages, with proper Intent matching and Entity identification. Also, the implementation later can be extended to new languages with minimal changes to existing bot implementation.

The Pattern

You need to create a Master-Bot, which will hold the Intents, Entities, Dialog Flow, Custom Component mapping and Channel(Facebook, Webhook) mapping of the bot. Then you need to create language specific bots, which will only hold Intents and Entities(optionally, only if you have a requirement to match language specific entities).



The idea is to do Intent matching properly for specific languages. Ideally you code the Master Bot in the default language the bot needs to respond. So all the Intents you add is being trained for that particular language, for example English.
Then the other bots have language specific Intents and they are being trained for that language.
Advantage you achieve is, the bots are being trained separately for each language and your Intent matching works properly.

Implementation Details 

After you have added all required language specific bots, add the Intents and Entities to them. Make sure you train all these bots before moving on the steps mentioned below.
Now, in the Master Bot implement the below mentioned steps. 

Step 1 : How to detect the language

There are couple of ways to detect user language. Oracle bot provides a out-of-the-box Translation services, which you can use to in your bot to detect the language.
Couple of steps to implement this:
1. Define a Translation Service (Google or Microsoft)
2. Add a Dialog Flow state(Detect Language) to detect and store user language.

You can find more info in the dev guide : https://docs.oracle.com/en/cloud/paas/mobile-suite/develop/localization.html#GUID-997ED305-D011-4E89-9440-566092A4870A

Secondly, you can use a Custom Component to detect user language. This custom component will call an external API (Yandex) to identify user language and store the detected language in a variable.



The implementation details of this Custom component is in this blog.

Step 2 : Implement a Switch State in Dialog flow 

Once the user language is detected, we have to introduce a "Switch" State in the dialog flow.
If you use the Custom Component to identify the language, you Switch state show look like below:

Step 3 : Intent Matching States 

The Switch state, should direct the dialog flow to a particular Intent matching state. The Intent matching state has a variable "botName", which you can use to invoke the language specific bot match the user input.

So, in the below picture, you can see 2 different Intent matching states, invoking 2 different bots.

 

Finally

As a whole the complete implementation  of the Dialog Flow should look like:


ExtraTip

To make the Bot development more flexible, you can use Apache FreeMarker to reference the "botName" property in the "Step 3" above and completely remove the "Step 2" (switch state).
What you need to do :
  1. Name you bot with a language tag. For example : MyBot_en, MyBot_nl, MyBot_es. So here in this example "MyBot_en" is your master bot. Also, all the Intent names need to be same in the all these bots.
  2. Identify the language, as explained earlier in the "Step 1".
  3. Refer to an Intent matching state like below. There 2 flavours of it, one if you use platform configured Translation services or use a Custom comp to detect the language.

Advantage of this implementation is higher than my earlier technique. With this implementation you can scale to as many language specific bots you want without changing the Master bot at all.

Comments

Popular posts from this blog

Rich Text Editor - Oracle JET

Oracle JET has a lot of excellent UI components, but according to Murphy's law, client always comes up with something which you don't have at your disposal. So, driven by one of my client's requirements, I created a Rich Text Editor or WYSIWYG editor for Oracle JET. This is based on Quill JS and fully customizable. Github project download: https://github.com/sohamda/JET-Web-Components/tree/master/rich-text-editor I will explain in this blog, on how to integrate it in your own Oracle JET project. 1. Create and initialize your JET application and then put the downloaded web component inside "src\js\jet-composites" folder. 2. Once copied update your viewModel first. Add a snippet for passing the default content to be displayed by the editor after load. 3. Update view to load this editor Above you can see the "toolbar-options" property, that controls which options you should display to user on the editor. Those are basically the forma...

Exception Handling in ADF

This blog will give you an overview on how you can successfully deal with unhandled Runtime exceptions in an ADF application. This will give you an idea of: How to catch the unhandled exceptions. Write a separate log file with stacktrace and thread dumps. Redirect the user to an static error page #1. Catch unhandled exceptions :  Create a class "MyExceptionHandler" which extends : oracle.adf.view.rich.context.ExceptionHandler. Override handleException() method.     public void handleException(FacesContext facesContext, Throwable throwable, PhaseId phaseId) throws Throwable {         // this method is going to create a separate file with stacktrace and thread dumps         writeException(throwable);         // redirect to error page         redirectToErrorPage(facesContext);     }  Create a fo...

Layout Management & CSS Classes with Oracle JET

Oracle JET provides automatic responsive layout using CSS classes. So that, from large screens to small screens the application fits itself the best possible way. JET’s layout management are based on 2 types of CSS classes “Responsive Grid” and “Flex”. Responsive grid classes which deals with size, number of columns and functions of a particular <div>. Naming convention of these classes are oj- size - function - columns sizes can be: sm, md, lg, xl functions can be: hide, only-hide columns can be: any number between 1 to 12.   Just like Bootstrap, JET also divides the width of the available space into 12 columns, so for example, if you want a section of your page should take up atleast 5 columns if you divide the available screen into 12 columns, you need use : oj- size -5. Now comes the size part, you need to define that for each size of the screen, from hand-held mobile devices to large or extra large desktop screens. With combination with theses gr...