In an Extension, it could be the case that the Cognigy Conversation Designer should be able to add different Flow snippets based on the Extension's result. Thus, two Child Nodes could be exposed to the Flow Node:
In the example above the Get Weather Node provides an On Success and On Error Child Node in order to check if the execution went successfully or threw an error.
How to
In order to provide Child Nodes, some steps need to be implemented in the Extension's code:
- Develop a Child Node
- Add Child Node to Parent Node
- Add Parent and Child Node to the createExtension() Funktion in module.ts
Develop a Child Node
In general, Child Nodes use almost the same pattern as Parent Nodes to be described and developed while one needs to tell the Extension which Node is the parent:
export const onSuccess = createNodeDescriptor({ type: "onSuccess", parentType: "getWeather", defaultLabel: "On Success", appearance: { color: '#2ecc71', textColor: 'black', variant: 'mini' }, constraints: { editable: false, deletable: true, collapsable: true, creatable: true, movable: false, placement: { predecessor: { whitelist: [] } } } });
Now, this Node can be executed in the Parent Node, for example when an API request was executed successfully:
function: async ({ cognigy, config, childConfig }: IParams) => {
// Find the Child Node
const onSuccessChild = childConfigs.find(child => child.type === "onSuccess");
// Check if the Child Node exists if (!onSuccessChild) { throw new Error("Unable to find 'onSuccessChild'. Seems its not attached."); }
// Use the Cognigy API to execute the Child Node api.setNextNode(onSuccessChild.id); return;
}
In the end, everything needs to be exposed through the createExtension() function in module.ts:
import { getWeatherNode, onError, onSuccess } from "./nodes/getWeather"; export default createExtension({ nodes: [ getWeatherNode, onSuccess, onError ], connections: [] });
Important:
If one forgets to add the Child Nodes to the createExtension() function, the Node can't be added to a Flow in Cognigy.AI.
Comments
0 comments