The Function component allows conversational designers to access and manipulate data using JavaScript code (e.g., adapt data to a conversational format and specify variable conditions, among other functionalities).
Adding a Function component
1. Click on a Autopilot model and select Automation Designer [1].
2. You will be taken to the Automation Designer inside the Builder app, where the flow configuration will take place.
3. Under “Automation”, select the Function component [2] and then drag it to a canvas on your right side [3].
4. Double-click the component. Then, the component settings panel [4] will appear.
5. Provide the required details of the component.
- “Component name” [5]: The name of the Function component. The name can only contain letters, numbers (except as a first character), and underscores, and can be as long as 30 characters.
- “Function” [6]: Here you can define the code editor field to execute JavaScript code. In this component, you can use standard JavaScript code, as well as the following two methods that allow the conversational designers to manage Autopilot’s variables, namely:
-
- Context.getVariable(variable name): Get value from a variable. This method allows getting the Autopilot’s variable data so that you are able to use those values in the logic execution previously defined.
- Context.setVariable(variable name, new value): Define the value of a custom variable. This method allows you to set the Autopilot’s variable data so that you are able to execute the logic that you previously defined, and store the transformed data into a VA’s variable. Note: The system’s variable values cannot be changed (e.g. the utterance, caller ID, and confidence score).
- The code editor has 20 lines by default and will increase in height if you keep editing below, with the scroll on the side.
- There is a limit of 16000 characters and another for an execution timeout of 2 seconds, meaning that if you have code exceeding 2 seconds of running time, the code will stop running and the component will move with the error exit.
6. Click Save [7].
After the component is created, you can connect it with another component: One for “Success” and another for an “Error” scenario. Keep in mind that if the component is not directly or indirectly connected to a Flow Trigger component, it will be ignored when the flow is executed.
Note: A red exclamation mark will appear on the component node if any required field is invalid. Hold the pointer over it to see further details.
Deleting a Function Component
1. On your canvas, click the Function component you want to delete, and then press the backspace key (Windows) or the delete key (Mac) on your keyboard. Alternatively, you can double-click the component and select Delete in the side panel that appears.
2. Click Delete component in the dialog that appears to confirm the deletion.