...
The value of the control ID and Name are available in the msg object atmsg.payload.session.attributes.orbitaSession.flowInfo.controlId
and msg.payload.session.attributes.orbitaSession.flowInfo.controlName
respectively.
Using Custom Control ID for hook data
Below is a sample script evaluating the Custom control ID and dispatching accordingly.
...
Code Block |
---|
msg.payload.session.attributes.orbitaSession.flowInfo.controlId |
Flow jumping
If you want to jump to another flow and control, you can do it by replacing the flowInfo
property in the output payload object.
...
Warning |
---|
By replacing the |
Using a Custom Control Name for hook data
You can also configure your logic for a Custom Control based on its Name.
...
You can use the Hook events if you have reusable functions in your conversation flow.
Setting up Hook Event
In Experience Designer, design a flow as shown below
or you can use a built-in example flow.In the Experience Designer, create a new flow.
Click on the hamburger menu on the top right corner and navigate to Import > Built-in > Orbita Flows-(BETA) > Flow Manager.
Place the flow on the canvas and Deploy the flow
The Hook-Data function node contains the below code to enable the hook to fire the custom logic based on the Custom Control Name.
Code Block try { const _ = global.get('lodash'); controlId = msg.payload.session.attributes.orbitaSession.flowInfo.controlId, controlName = msg.payload.session.attributes.orbitaSession.flowInfo.controlName, hookName = controlName.indexOf(":") > - 1 ? controlName.substr(0, controlName.indexOf(":")) : controlName, args = controlName.indexOf(":") > -1 ? [msg, ...controlName.substr(controlName.indexOf(":") + 1).split("|") .map(arg => arg.trim()) .filter(arg => !!arg) .map(arg => arg === "null" ? null : arg)] : [msg]; msg.payload.externalHook = { data: hookName } if (hookName) { const hook = global.get("hooks")[hookName]; msg.hookResult = { hookFound: !!hook }; if (hook) { hook.apply(null, args); } else { msg.hookResult.executionSuccess = false; msg.hookResult.error = `Could not find hook '${hookName}'`; node.warn(`Could not find hook '${hookName}'`); return msg; } } } catch (error) { msg.hookResult.executionSuccess = false; msg.hookResult.error = error; node.warn(`Error executing hook`); node.error(error); return msg; }
To set up the Hook Events, you need to initialize the hooks. The Settings / Hooks Initialize function node is used to register the hook condition so that the Hook-Data function knows what to do with it.
Code Block const settings = global.get("settings") || {}; settings.emptyString = ''; global.set("settings", settings); const hooks = global.get("hooks"); global.set("hooks", hooks || {}); return msg;
You will register your Hook Event with an Inject node. All the Inject nodes in this flow have the same configuration.
When the Custom control named HTMLDirective gets called in Flow studio, the function node named HTML form Hook will be called.
Code Block global.get("hooks").HTMLDirective = msg => { node.send(msg); };
The next function node calls the HTML form and it is subsequently connected back to the Flow Manager node to continue the conversation flow.
Custom Control usage with bmiCalculator flow
When you drag the Custom control to the Flow Studio canvas, you can see a name field and the control's ID. In Experience Designer, developers can write code that executes when the Custom control is reached.
...
Code Block |
---|
try { const _ = global.get('lodash'); controlId = msg.payload.session.attributes.orbitaSession.flowInfo.controlId, controlName = msg.payload.session.attributes.orbitaSession.flowInfo.controlName, hookName = controlName.indexOf(":") > - 1 ? controlName.substr(0, controlName.indexOf(":")) : controlName, args = controlName.indexOf(":") > -1 ? [msg, ...controlName.substr(controlName.indexOf(":") + 1).split("|") .map(arg => arg.trim()) .filter(arg => !!arg) .map(arg => arg === "null" ? null : arg)] : [msg]; msg.payload.externalHook = { data: hookName } if (hookName) { const hook = global.get("hooks")[hookName]; msg.hookResult = { hookFound: !!hook }; if (hook) { hook.apply(null, args); } else { msg.hookResult.executionSuccess = false; msg.hookResult.error = `Could not find hook '${hookName}'`; node.warn(`Could not find hook '${hookName}'`); return msg; } } } catch (error) { msg.hookResult.executionSuccess = false; msg.hookResult.error = error; node.warn(`Error executing hook`); node.error(error); return msg; } |
Related Articles
Filter by label (Content by label) | ||||||||
---|---|---|---|---|---|---|---|---|
|
...