JB Manager Architecture
Last updated
Last updated
This document explains the inner workings of the JB Manager.
All the services are generic i.e. they are designed for multiple bots or use cases. The only customization that exists lies in the tiny bot code (finite state machine code) which is published by the Studio.
To change this diagram edit this file
Bot
bot_id (e.g. "12345") is at the highest level. All other entries like person, sessions are against a particular bot. We support multiple bots from the same backend.
User
A user needs to be registered for the bot. Phone Number & Bot ID make the user unique.
Session
This table stores the state (stage in the workflow) and variables for every user. We maintain session for 24 hours. After that a fresh conversation starts.
Turn
Every message received from the user creates a new turn in the conversation. Against one user message, we can have multiple bot responses.
Message
Every message received or sent is logged to the DB.
Provides APIs to interact with JB Manager. Here are the top buckets of APIs:
Callback from channels like WhatsApp or Telegram
JB Studio like publishing the bot
Managing bots changing their states and variables
Viewing chat logs and analytics
Triggering indexing jobs
Callback
Figure out bot_id
based on the callback
Create person if doesn't exists. Fetch pid
Create session_id
if session has expired (> 24 hours).
Creates turn_id
for the new conversation
Create msg_id
Responsible for both input and output communication with the channel (WhatsApp / Telegram). It needs to handle channel specific API calls and rendering of UI messages (e.g. WhatsApp Flow, List & Buttons)
If media present in the message, fetch and upload to Azure.
Provides standard dialogues (list/buttons) for features that are common to all bots. It handles rendering (outbound) and the related user action. It let's Flow service know that the user has completed a dialogue.
Language - It shows the dialog and saves the user's language preference
Reset (not yet there)
In the inbound scenario:
It mostly enqueues messages for the Language service
Unless the message related to a dialogue (e.g. language), WhatsApp Flow or Button. In this case it directly talks to the Flow service.
In the outbound scenario:
It mostly receives messages from the Language service.
Unless the message is related to WhatsApp flow in which case Flow directly writes to it's queue.
There are two flows:
Receiving users message
Sending the response to the user.
It's responsible for translating labels in case of interactives messages e.g. Lists & Buttons
We assume that all messages sent by the user obey the user's preferred_language
.
For outbound messages, Language service will look at the message type from the Flow Service and then decide on the following:
If text
Then fetch details about the turn -- In what mode did the user ask their question:
If user asks in text / form / interactive, we respond in text
If user asks in voice, we respond in voice + text -- Language service creates two inputs for Channel service
In all other cases, send text
If document
,
Translate the caption
image
Translate the caption
If interactive
Translate the text, header, footer
Translate the labels for buttons
Retrieve session from DB based on session_id. This provides it memory of the current state (stage of the workflow), variables.
Process the message via a finite state machine code (this code is generated in the Studio and pushed to the JB Manager)
It can send multiple messages for every user message
It can make API calls or use plugins
The responses that it sends can include the following:
Text
Interactive - WhatsApp flow, List, Buttons
Documents, Images
Dialogues -- it uses keywords language
to trigger Channel service into sending a standardized dialogue.
On complete (or logical pause in the workflow e.g. user input or plugin input), save the state and variables.
This fetches data from the Vector DB (PG Vector / Postgres) based on query and metadata if any. The metadata is used to create filter query to restrict the similarity search even further.
This service receives input files (urls from Azure) and pre-processes them and indexes them into the Vector DB.