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 :

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.



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


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.


Popular posts from this blog

Secure your Node/Express REST APIs using Passport JS

Recently I have been involved in various discussions on how to make the REST APIs as secure as SOAP.
First of all, let me start with a very basic statement, about security, it doesn't depend on your Webservice type, be it REST or SOAP, your design decisions depicts whether they can be made secure or not.
In this example blog, I will use "Micro CRUD services for Oracle Database Cloud" APIs and implement (read attach) Passport's "local" authentication strategy, to make them secure.

Code in Github : LeasifyAPIs with Passport

What is Passport JS? (from Documentation)

Passport is authentication middleware for Node. It is designed to serve a singular purpose: authenticate requests. When writing modules, encapsulation is a virtue, so Passport delegates all other functionality to the application. This separation of concerns keeps code clean and maintainable, and makes Passport extremely easy to integrate into an application.

What are "strategies" in P…

ADF Utility : Find UIComponent from Managed Bean

Many a times, it is required to find an UIComponent from ADF managed bean, to do something with it, for example : change the value of an af:outputText, change readOnly property of an af:inputText etc.

private UIComponent getUIComponent(String id) { 

        FacesContext facesCtx = FacesContext.getCurrentInstance(); 
        return findComponent(facesCtx.getViewRoot(), id);

    private UIComponent findComponent(UIComponent base, String id) {

        if (id.equals(base.getId())) {
            return base;

        UIComponent children = null;
        UIComponent result = null;
        Iterator childrens = base.getFacetsAndChildren();
        while (childrens.hasNext() && (result == null)) {
            children = (UIComponent);
            if (id.equals(children.getId())) {
                result = children;
            result = findComponent(children, id);
            if (result != null) {

Chatbots and Oracle Cloud Services

Thanks to Oracle A-Team, I had a chance to work with Chatbots.
3 pure NodeJS applications, on couple of Oracle Cloud platforms and Facebook messenger, and my chatbot was running.

Let me explain, the architecture a bit. To start with, following is the simple representation of how it works.