Flow Manager
The Flow Manager module adds a standard flow studio manager implementation with capabilities for randomized content and the registration and execution of hooks via Custom nodes in flow studio flows.
- 1 Dependencies
- 2 Methods
- 2.1 changeFlow
- 2.2 handle
- 2.3 registerHook
- 2.4 getHook
- 2.5 setCurrentModule
- 2.6 getCurrentModule
- 2.7 clearCurrentModule
- 3 Standard Hooks
- 3.1 error
- 3.2 disableKeyboard
- 3.3 enableKeyboard
- 3.4 disableAudio
- 3.5 enableAudio
- 3.6 setWpm
- 3.7 setCurrentModule
- 3.8 getCurrentModule
- 3.9 clearCurrentModule
- 3.10 trackFlow
- 4 Hook Requirements
- 5 Execution of Hooks
- 5.1 Module Context
- 5.2 Parameters
- 6 Button Injection
- 7 Handlers
Dependencies
The Flow Manager module is dependent on the following modules:
Methods
changeFlow
Clears the flow session and redirects the user to the specified flow.
Parameters:
msg (string): The Node-RED message object.
flowId (string): The ID of the flow to switch to.
Returns: Nothing.
handle
Passes a request back to the flow manager node to be handled.
Parameters:
msg (string): The Node-RED message object.
Returns: Nothing.
registerHook
Registers a hook for retrieval and execution.
Parameters:
key (string): The key that the hook will be retrieved by and executed (see Execution of Hooks).
hook (function): The hook handler function (see Hook Requirements).
module (string, optional): The module key if this hook is specific to a particular module context.
Returns: Nothing.
getHook
Retrieves a hook by key for execution.
Parameters:
key (string): The key of the hook to retrieve.
module (string, optional): The module key if in a specific module context.
Returns: The hook, if a match is found, nothing otherwise.
setCurrentModule
Sets the key of the currently active module in session.
Parameters:
msg (object): The Node-RED message object.
moduleKey (string): The key of the currently active module.
getCurrentModule
Returns the key of the currently active module in session.
Parameters:
msg (object): The Node-RED message object.
clearCurrentModule
Clears the key of the currently active module from session.
Parameters:
msg (object): The Node-RED message object.
Standard Hooks
error
Records an error of type “Flow Studio”
Parameters:
msg (object): The Node-RED message object.
error (string): The error message.
handleResponse (boolean, default = true): Whether or not the message should be handled by the Flow Manager module (true) or if the flow should continue on.
disableKeyboard
Disables keyboard input in the Chatbot module.
Parameters:
msg (object): The Node-RED message object.
enableKeyboard
Enables keyboard input in the Chatbot module.
Parameters:
msg (object): The Node-RED message object.
disableAudio
Disables audio in the Chatbot module.
Parameters:
msg (object): The Node-RED message object.
enableAudio
Enables audio in the Chatbot module.
Parameters:
msg (object): The Node-RED message object.
setWpm
Sets a dynamic word per minute based wait time in the Chatbot module.
Parameters:
msg (object): The Node-RED message object.
wpm (string): The desired word per minute rate.
setCurrentModule
Sets the key of the currently active module in session.
Parameters:
msg (object): The Node-RED message object.
moduleKey (string): The key of the currently active module.
getCurrentModule
Gets the key of the currently active module from session and sets it as msg.currentModule.
Parameters:
msg (object): The Node-RED message object.
clearCurrentModule
Clears the key of the currently active module from session.
Parameters:
msg (object): The Node-RED message object.
trackFlow
Invokes the currently registered trackFlow handler, passing it the message object and current flow name.
Parameters:
msg (object): The Node-RED message object.
Hook Requirements
The only strict requirement for a hook is that it must be a function.
If a hook does have parameters, the first parameter must be:
msg (object): The Node-RED message object.
The msg object can then be sent on to subsequent nodes for processing via node.send(msg), and ultimately sent back to the flow manager for handling via the handle method.
Any parameters after msg will have any additional parameters from the hook execution applied in order (see Parameters).
Execution of Hooks
Hooks are executed through Custom nodes in flow studio flows. To execute a hook, just change the name of the Custom node to the name of the hook you want to invoke:
The above example will invoke a hook that has been registered with the key “getConfiguration”.
The msg object will be passed automatically as the first parameter to the hook.
Module Context
Hooks for a module can be namespaced by specifying the optional module parameter when registering them.
If a current module has been set using the setCurrentModule hook, when a hook is executed, it will first be looked for in the module context namespace, and if not found there, root level hooks will be checked.
This allows for the behavior of root level hooks established by other modules to be overridden in a particular module context, if needed.
Parameters
The following is an example of specifying additional parameters:
The pattern for this sort of invocation is a colon after the hook name and pipes separating the parameters:
<hookName>:<parameter 1>|<parameter>|…|<parameter n>
In the above example for the starRating hook (see Input Controls) the hook function signature is:
(msg, max, minLabel, maxLabel) => {
...
}
The values of “7”, “Not Satisfied at All”, and “Extremely Satisfied” will get applied to the “max”, “minLabel” and “maxLabel” parameters.
The values will be applied as strings. The hook is responsible for doing any necessary parsing of additional parameters from strings to other types.
Button Injection
An array of button choices (in the appropriate format for the Orbita button directive) set in session at msg.orbita.session.modules.flowManager.injectedButtons will be included in the next response generated by the Flow Manager module, and cleared from session.
Handlers
Handlers for the following events can be registered by calling flowManager.registerHandler and passing it the handler key:
beforeIntraFlowResponse
This handler is executed immediately after pin 1 of the flow manager node produces an output, and before response randomization and button injection. The handler can be asynchronous and modifications made to the msg object by the handler will be carried forward.
The handler is passed the following parameters:
msg (object): The Node-RED message object.
beforeEndFlowResponse
This handler is executed immediately after pin 2 of the flow manager node produces an output, and before response randomization and button injection. The handler can be asynchronous and modifications made to the msg object by the handler will be carried forward.
The handler is passed the following parameters:
msg (object): The Node-RED message object.
trackFlow
This handler is executed when the trackFlow hook is invoked.
The handler is passed the following parameters:
msg (object): The Node-RED message object.
flowName (string): The name of the current flow.