# 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(user) {
    //your logic goes here
    return {
        nodes:[]
    };
}
```

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](/ai-builder/nodes.md#user-object).

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" %}

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

{% endtab %}

{% tab title="Image" %}

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

{% endtab %}

{% tab title="Links" %}

```javascript
{
  "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" %}

```javascript
{
  "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" %}

```javascript
{
  "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" %}

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

{% endtab %}
{% endtabs %}

#### Collect User Data

{% tabs %}
{% tab title="Quick Reply" %}

```javascript
{
  "node_type": "QUICK_REPLY",
  "actions_on_response": [],
  "text": "<text before quick reply>",
  "responses": [//array of responses
    {
      "txt": "<option 1>"
    },
    {
      "txt": "<option 2>"
    },
    {
      "txt": "<option 3>"
    }
  ],
  "option_display_mode": "",// one of "HORIZONTAL" "VERTICAL" "DROPDOWN"
  "placeholder": "<placeholder in case of dropdown such as Type to search..>"
}
```

{% endtab %}

{% tab title="Form" %}

```javascript
{
  "node_type": "QUESTION_FORM",
  "questions": [
    {
      "text": "<label for the field>",
      "failMsg": "<Error msg when validation fails>",
      "input_type": "NAME",//used when asking for name
      "actions": [//array of actions to run after getting response
        {
          "type": "SET_NAME"//this action sets name to user's profile
        }
      ],
      "skip": false//whether user can skip this field
    },
    {
      "text": "<label for the field>",
      "failMsg": "<Error msg when validation fails>",
      "input_type": "REGEX",//used to take single line input with regex based validation
      "actions": [//array of actions to run after getting response
      ],
      "skip": false,//whether user can skip this field
      "regex_pattern": "^[a-zA-Z ]*$"//regex to validat the input
    },
    {
      "text": "<label for the field>",
      "failMsg": "<Error msg when email validation fails>",
      "input_type": "EMAIL",//used to take email as input
      "actions": [//array of actions to run after getting response
        {
          "type": "SET_EMAIL"//action to set email to user's profile
        }
      ]
    },
    {
      "text": "<label for the field>",
      "failMsg": "<Error msg when email validation fails>",
      "input_type": "PHONE",//used to take phone as input
      "actions": [//array of actions to run after getting response
        {
          "type": "SET_PHONE"//action to set phone to user's profile
        }
      ]
    },
    {
      "text": "<label for the field>",
      "failMsg": "<Error msg when email validation fails>",
      "input_type": "TEXT",//used to take input using multi-line text area
      "actions": []//array of actions to run after getting response
    }
  ],
  "txt_b4_questions": "<message before the form or null>",
  "txt_after_questions": "<message after the form or null>",
}
```

{% endtab %}

{% tab title="Datepicker" %}

```javascript
{
  "node_type": "DATEPICKER",
  "actions_on_response": [],
  "text": "<text before asking date",
  "allow_old_dates": true//whether to allow selecting past dates
}
```

{% endtab %}

{% tab title="Rating" %}

```javascript
{
  "node_type": "RATING",
  "txt": "<message before rating>"
}
```

{% endtab %}

{% tab title="Slider" %}

```javascript
{
  "node_type": "SLIDER",
  "actions_on_response": [],
  "txt": "<text before slider>",
  "unit": "<units to show for slider input such as kg, years etc.",
  "sliderType": "RANGE",//SINGLE(for single input) RANGE(for selecting range)
  "defaultMin": 30,//default value shown(default min value in case of range slider)
  "defaultMax": 60,//default max value in case of range slider.
  "min": 10,//min allowed value
  "max": 300,//max allowed value
  "step": 1,//interval between each value user can select.
  "title": "<title to show above the slider>"
}
```

{% endtab %}

{% tab title="Ask Question" %}

```javascript
{
  "node_type": "TEXT_RESPONSE",
  "actions_on_response": [],
  "text": "<text for the question>"
}
```

{% endtab %}

{% tab title="Multi Selection" %}

```javascript
{
  "node_type": "MULTI_SELECTION_REPLY",
  "text": "wegewgew",
  "skip": false,//whether user can skip without selecting anything
  "responses": [
    {
      "txt": "gewg"
    },
    {
      "txt": "ggg"
    }
  ]
}
```

{% endtab %}
{% endtabs %}


---

# 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.intelliticks.com/ai-builder/nodes/add-and-send-data/custom-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.
