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

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. Message Platform Server : Is a NodeJS application, deployed on Oracle Application Container cloud, acts as a channel between Facebook Messenger and the chatbot engine. It simply converts the incoming messages from Facebook and sends it to chatbot readable format. Also, when chatbot replies, it converts to Facebook readable formats and passes it to messenger. Chatbot Engine : Is a NodeJS application, which communicate with some REST APIs based on a conversation flow document and moves the flow of the conversation from one state to another. Flow JSON : Where we document, every state of a conversation and which APIs to call to generate a response. For example, at the beginning of the con

Create Micro CRUD services for Oracle Database Cloud using NodeJS

I will try to explain, how you can use NodeJS to create mirco services for the tables in your Oracle Database Cloud or on-premise Database. Complete Github project : https://github.com/sohamda/LeasifyAPIs You need to do "npm install" to download the node_modules. Step by Step guide : 1. NodeJS : either 32 or 64 bit. If you already have NodeJS installed, please check whether it is 64 or 32. Use below command to figure that out : C:\>node > require('os').arch() If you get : 'ia32' , then it is 32 bit installation. 2. Install oracle-db node module .  This was a lengthy and time consuming installation for me, because for Windows, it has a lot of pre-requisites. If you are a Mac user, you are lucky. :) I followed : https://community.oracle.com/docs/DOC-931127 There is also a detailed one in github : https://github.com/oracle/node-oracledb/blob/master/INSTALL.md 3. Config your DB Cloud Create a user and couple of tables on which we'

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 grid c