# Adding Child Nodes

**Cognigy Support**  
December 27, 2021

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:

1. Develop a Child Node
2. Add Child Node to Parent Node
3. 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.**

### Getting Started

- [Extensions Overview](https://support.cognigy.com/hc/en-us/articles/360016409380-Extensions-Overview)  
- [NPM Package: @cognigy/extension-tools](https://support.cognigy.com/hc/en-us/articles/4413844565906-NPM-Package-cognigy-extension-tools)  
- [Getting Started with Extensions](https://support.cognigy.com/hc/en-us/articles/360016534459-Getting-Started-with-Extensions)  
- [Extensions Installation](https://support.cognigy.com/hc/en-us/articles/360016505680-Extensions-Installation)  
- [Extensions Best Practices](https://support.cognigy.com/hc/en-us/articles/360016505740-Extensions-Best-Practices)  
- [Adding Child Nodes](https://support.cognigy.com/hc/en-us/articles/360018106500-Adding-Child-Nodes)  
  
#### Table of contents

How to  
- [How to](https://support.cognigy.com/hc/en-us/articles/360018106500-Adding-Child-Nodes#how-to-0-0)  
- [Develop a Child Node](https://support.cognigy.com/hc/en-us/articles/360018106500-Adding-Child-Nodes#develop-a-child-node-0-1)
