Chatbot
The Chatbot module adds a standard V3 chatbot implementation and test page to a project.
Dependencies
The Chatbot module is dependent on the following modules:
Methods
render
Used to allow other modules to render the default chatbot test page.
Parameters:
msg (object): The Node-RED msg object.
customData (object, optional): Custom data to include. If specified and a query string is also included in the request, the two will be merged, with the custom data passed using this parameter taking precedence.
template (string, optional): The key of the chatbot settings to use when rendering. If not specified, the default chatbot settings will be used.
Returns: Nothing, the response is handled directly by this method.
Implementation Notes
Translation
The Chatbot module translates input and output when the request language is something other than the default language of English. If a language is specified in session (msg.payload.session.language) it will use that, otherwise it will detect the appropriate language using the Translation module (detectLanguage).
Custom Data
The Chatbot module will automatically carry through any query string parameters as custom data and make it available in the original request data payload in Orbita.
Chat Transcript Capturing
Set chatbot.enableTranscripts in the settings content to enable chat transcript capturing.
Bot Provider Node
The bot provider stores the socket ID at msg.payload.originalRequest.socketId:
msg.payload.originalRequest.socketId = msg.socketIOId;
It sets a flag of isChatRequest (true) on msg.payload.originalRequest for use by session.isChatSession in the Utilities module.
msg.payload.originalRequest.isChatRequest = true;
It records the current language:
msg.payload.originalRequest.language = msg.language;
As noted above, it carries through any custom data:
The bot provider node sets enableArrayResponse to true in the Bot Out Parser section:
It checks if a session flag of msg.payload.session.modules.chatbot.disableKeyboard is set to true, and, if so, it will disable keyboard input globally:
It checks if a session flag of msg.payload.session.modules.chatbot.enableAudio is set to true to determine whether or not to enable audio output.
It checks if a session value is set at msg.payload.session.modules.chatbot.wpm, and if so, will set a dynamic word per minute rate:
It also contains the default text-to-speech configuration:
Event Type Filtering
Only socket events of type “request” will be passed through to the Bot Provider node.
Error Logging
Any errors from the provider node will be logged as follows:
DEADLINE_EXCEEDED errors will be logged as an error of type “Timeout” with an indication as to what the user query was.
Queries that exceed the Dialogflow length limit will be recorded as an error of type “Invalid Query” with an indication of the user query that caused the issue.
Other errors will be recorded as an error of type “Dialogflow” with an indication of the user query and the error message returned (if any).
Test Page
The Chatbot module establishes a simple test page using the default settings at:
/oeapi/[Hyphenated Project Name]/chatbot
For example if the project is called “Orbita Test Project”, the URL for the test page would be:
/oeapi/orbita-test-project/chatbot
The test page can be directed to use specific chatbot settings by specifying the chatbot settings key as a parameter at the end of the URL:
/oeapi/[Hyphenated Project Name]/chatbot/[Chatbot Settings key]
The Orbita project ID and the current environment host are pulled from the project context for use in chatbot initialization.
If settings.project.description is set, it will utilize that in the test page title, otherwise it will use a generic title with the Orbita project ID and the environment host.
If settings.chatbot.template is set, it will use that as the chatbot settings key, otherwise it will use the default chatbot settings.
If the environment is non-production, chat-core.js will be referenced directly by the test page. On production, chat.js will be referenced.
Cross Domain Testing Endpoints
The Chatbot module also establishes endpoints for easy testing via the Cross Domain Testing Page:
/oeapi/[Hyphenated Project Name]/cross-domain
and
/oeapi/[Hyphenated Project Name]/cross-domain/[Chatbot Settings key]
Will redirect to the Cross Domain Testing Page with the appropriate query string parameters filled in.
The bypassCdn parameter will automatically be set to true for non-production environments.
Included Example Chatbot Settings
Outreach
The Outreach chatbot settings presents a full page and centered view of the chatbot, as an example of an approach for presenting the chatbot to users being contacted as part of an Orbita Outreach campaign: