## 2. Code-based nodes Code-based nodes allow you to execute actions such as retrieving or sending data via API responses, implementing custom logic for specific actions, and using stored variable data effectively. ### 2.1 API > This node is also available for voice bots. With the API node, you can connect to an API at a specific point in a flow to send and get responses from a third-party system outside of your chatbot. <img src="https://i.imgur.com/Fnsvd0z.png" alt="drawing" width="70%"/> To know about the various features of the node and how to use it, click [here](https://docs.yellow.ai/docs/platform_concepts/studio/api/add-api-apinode). ----- ### 2.2 Variables > This node is available for voice bots. Use the variable node to assign values to a new variable which has not been previously used to collect/store data. ![](https://i.imgur.com/aZzdF0J.png) There are two ways by which you can assign values: * **Assign a static value** 1. In **Name** select a variable or [create a variable](https://docs.yellow.ai/docs/platform_concepts/studio/build/bot-variables). 2. In **Value**, type the value you'd like to assign to that variable. <img src="https://i.imgur.com/Qh4qqPe.png" alt="drawing" width="60%"/> * **Assign a dynamic value** 1. In **Name**, select a variable or [create a variable](https://docs.yellow.ai/docs/platform_concepts/studio/build/bot-variables). 2. In **Value**, click the variable icon to fetch the variable value you'd like to assign to the variable. <img src="https://i.imgur.com/HzUsnqB.png" alt="drawing" width="69%"/> For example, let's say that you have captured the **First name** and the **Last name** of a user and you want to save both the names under one variable **Full Name**. 1. Add two [prompt nodes](https://docs.yellow.ai/docs/platform_concepts/studio/build/nodes/prompt-nodes) to [capture the responses in two different variables](https://docs.yellow.ai/docs/platform_concepts/studio/build/bot-variables#store-data-in-variables). 2. Add a **Variable node**, create a new variable **Customer Name** and fetch the variable values of the prompt nodes. This **Customer Name** can then be used throughout the flow for a different use case. Refer to the gif below to understand how this works. ![](https://i.imgur.com/B0qUAvJ.gif) ----- ### 2.3 Database > This node is available for voice bots. This node helps you perform database operations such as insert, update and search operations in your [database tables](https://docs.yellow.ai/docs/platform_concepts/studio/database). <img src="https://i.imgur.com/Tb0EHym.png" alt="drawing" width="80%"/> * **Insert:** Select **Insert** to insert data in each column into any existing database table you select. To know more, click [here](https://docs.yellow.ai/docs/platform_concepts/studio/database#insert-new-records-or-values-to-a-database-table). * **Search:** Select **Search** to look for specific data in the database. To know mroe, click [here](https://docs.yellow.ai/docs/platform_concepts/studio/database#fetch-database-records-using-the-database-node). * **Update:** Select **Update** to update any column in the databse. For steps to do so, click [here](https://docs.yellow.ai/docs/platform_concepts/studio/database#update-database-table-records-using-the-database-node). -------- ### 2.4 Function > This node is available for voice bots. This node lets you run custom logic written in the [Function](https://docs.yellow.ai/docs/platform_concepts/studio/build/code) section for specific use cases and store the result in a variable to use it in bot ocnversations. ![](https://i.imgur.com/v4HNlCq.png) * **View function** takes you to the function chosen in the **Function** field. * **+Create new function** button takes you to the function section where you can create a new function. * **Store Response in** lets you store the response of the function in a variable which can later be used in the flow if required. Function node is most commonly used to fetch transformation codes that parses API responses to filter specific data. Click [here](https://docs.yellow.ai/docs/platform_concepts/studio/api/send-receive-apiresponses#parse-api-response-using-function-node) for the steps to use this node. ----- ### 2.5 Modifier The node lets you convert the user input to a certain format before passing it to a database/API, or displaying it to the user. Use **Store Response in** option in this node to store the modified input in a variable to use it further in a flow. For example, let's say that you want to convert the user input to all caps. Your input would be **Test** and the would be **TEST**. To see how this node works, click the button at the top and enter your input to observe the corresponding output. ![](https://i.imgur.com/EbhyWqD.png) The following actions can be performed: | Action | Description | Output type | Sample input | Sample output | |-----------------------|-------------------------------|-------------|--------------|---------------| | Capitalize 1st letter | Capitalizes the first letter of the input | String | i am aakanksha | I am aakanksha | | Capitalize 1st char of word | Capitalizes the first character of the input | String | hi aakanksha | Hi Aakanksha | | Lower case all | Converts all the letters of the input to lower case | String | Hi AakanKsha | hi aakanksha | | Upper case all | Converts all the letters of the input to upper case | String | Hi AakanKsha | HI AAKANKSHA | | Clean Input | Cleans the input off extra characters | String | vidyadhār nāgār,jaĭpŭr | vidhyadhar nagar, jaipur | | Add on both sides | Adds a character on both sides of the input (The length should be lesser than teh defined length) | String | Akku (x = - , y = 6) | -Akku- | | Add at end | Adds a character at the end of the input (will be added if length is lesser than the defined length) | String | Akku (x = - , y = 6) | Akku-- | | Add at start | Prefix the input with a character. (will be added if the length is lesser than the defined length) | String | Akku (x = - , y = 6) | --Akku | | Replace first | Replaces the character entered in find preset with the character in replace preset at the prefix of the input. | String | abc@gmail.com (x=.,y=[dot]) | abc@gmail[dot]com | | Replace All | Replaces the character entered in find preset with the character in replace preset at any part of the input. | String | abc@gmail.com (x=.,y=[dot]) | abc@gmail[dot]com | | Remove from both sides | Removes the specified character from both the sides of the input| | -Akku- (x=-) | Akku | | Remove from start | Removes the specified character from the prefix of the input | String | -Akku- (x=-) | Akku- | | Remove from end | Removes the specified character from the suffix of the input | String | -Akku- (x=-) | -Akku | | Limit length | The input length is restricted to the specified number in the length preset, and any additional characters beyond that are substituted with the character defined in the omission preset. | Length limit | Aakanksha Jain (x=12) | Aakanksha Ja... | | Slice | Provides the input between the set positions | Array | [1,2,3,4,5] (2,4) | 3 |Slice| |Split by space|Splits the input into arrays|Array|tree house|["tree", "house"] |Split into words|The input is divided into individual words based on the character specified in the preset.| Array|treehouse ,| ["tree", "house"]| | Join | Join the input array with the character in preset | String | ["My", "Name", "is", "Aakanksha"] (with = '-') | My-Name-is-Aakanksha | |Pick by position|Picks the word in the array in the specified position| String | ["My", "Name", "is", "Aakanksha"] (3)| is |Get length|Returns an array's length |String | []"My", "Name", "is", "Aakanksha"]| 4| | For each | Apply modifier options on each element of the array | Select modifier | ["My", "Name", "is", "Aakanksha"] (operation = Upper case all) | ["MY", "NAME", "IS", "AAKANKSHA"] | ----- ---