# Dynamic Node

The **Dynamic Node** is used to create dynamic nodes based on some logic written in JavaScript.

{% hint style="warning" %}
This is an advanced node. You need have the knowledge of Javascript to use this node.
{% endhint %}

You need to write body of a function which takes user as parameter and returns list of nodes or actions as a response. Below is the format of function.

```javascript
function getNodes(user) {
    //your logic goes here
    return {
        nodes:[]
    };
}
return getNodes(user)
```

You can also return actions as response. Below is an example

```javascript
return{
actions : [{
type : 'ADD_CONTEXT_VAR',
key : 'full_name',
value : user.context.first_name + ' ' + user.context.last_name
}]
}
```

You need to write only body of the function. To refer to the complete user object with all of the fields [please check go to this link](https://docs.quickreply.ai/product-modules/ai-builder/custom-bots/nodes#:~:text=use%20%7B%7Bcontext.plan%7D%7D.-,User%20Object,-Below%20is%20the).

the function should return nodes in required JSON format. Below is the format of json for each type of nodes. Please note that all nodes are not supported here. Below are nodes which are supported.

### **Add and send data**

{% tabs %}
{% tab title="Text" %}

```json
{
      "node_type": "TEXT",
      "txt": "<desired text>"
}
```

{% endtab %}

{% tab title="Image" %}

```json
{
  "node_type": "IMAGE",
  "txt": <null or String>,
  "img": "<url of image",
}
```

{% endtab %}

{% tab title="Links" %}

```
{
  "node_type": "LINKS",
  "txt": "<text message before links>",
  "links": [//array of links as per the requirement. At least one obect is required in the array
    {
      "link_type": "EMAIL",//To show email link
      "open_in_new_tab": true,
      "title": "<text of button such as Email us>",
      "email": "<email>"
    },
    {
      "link_type": "PHONE",//To show click to call button
      "open_in_new_tab": true,
      "title": "<text of button such as Call us>",
      "phone": "<phone number with ISD code"
    },
    {
      "link_type": "WHATSAPP",//To show click to whatsapp
      "open_in_new_tab": true,
      "title": "<text of button such as Whatsapp us>",
      "phone": "<phone number with ISD code"
    },
    {
      "link_type": "LINK",//To show another link
      "open_in_new_tab": true,//where you would like to open link on new tab on click
      "title": "<text of button such as click here",
      "url": "<full URL starting with https:// or http://"
    },
    {
      "link_type": "PLAYBOOK",//To show another link
      "open_in_new_tab": false,
      "title": "<text of button such as click here",
      "playbook": "5d78c366380d7b0c67bb6230"//playbook id
    }
  ]
}
```

{% endtab %}

{% tab title="Youtube" %}

```
{
  "node_type": "YOUTUBE",
  "url": "<URL of youtube video such as ",
  "autoplay": true,//whether you would like to autoplay video
  "txt": "<desired text before the video>",
}
```

{% endtab %}

{% tab title="Gallery" %}

```
{
  "node_type": "CAROUSEL",
  "elements": [// array of card templates, at least one is required
    {
      "title": "<card title>",
      "subtitle": "<card subtitle>",
      "image_url": "<card img url>",
      "buttons": [// array of links node, up to three
        {
          "link_type": "EMAIL",//To show email link
          "open_in_new_tab": true,
          "title": "<text of button such as Email us>",
          "email": "<email>"
        },
        {
          "link_type": "PHONE",//To show click to call button
          "open_in_new_tab": true,
          "title": "<text of button such as Call us>",
          "phone": "<phone number with ISD code"
        },
        {
          "link_type": "WHATSAPP",//To show click to whatsapp
          "open_in_new_tab": true,
          "title": "<text of button such as Whatsapp us>",
          "phone": "<phone number with ISD code"
        },
        {
          "link_type": "LINK",//To show another link
          "open_in_new_tab": true,//where you would like to open link on new tab on click
          "title": "<text of button such as click here",
          "url": "<full URL starting with https:// or http://"
        },
        {
          "link_type": "PLAYBOOK",//To show another link
          "open_in_new_tab": false,
          "title": "<text of button such as click here",
          "actions":[],//actions to run when this button is selected. can be found on https://docs.intelliticks.com/ai-builder/nodes/additional/actions (see actions(after first json), not the action node json)
          "playbook": "5d78c366380d7b0c67bb6230"//playbook id
        }
      ]
    }
  ]
}
```

{% endtab %}

{% tab title="GoToPlaybook" %}

```
{
  "node_type": "GO_TO_PLAYBOOK",
  "playbook_id": "5d78c366380d7b0c67bb6230"//plabook id
}
```

{% endtab %}

{% tab title="Video" %}

```json
{
      "node_type": "VIDEO",
      "text": "<desired text>",
      "url": "<video url>"
}
```

{% endtab %}
{% endtabs %}

### Collect User Data

### &#xD;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.quickreply.ai/product-modules/ai-builder/nodes/add-and-send-data/dynamic-node.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
