The Kore.ai XO Platform allows you to declare and use variables within the assistants you build. These variables can be used to capture values that are commonly used by different tasks, nodes, and other elements.
In this Use Case we will explore a scenario in a Travel Planning Assistant, where Variables can be used. We will see how Global Variables can be used to pass API endpoints and change them easily when migrating from development to testing to production environments.
For details on what Variables are and how they are implemented in the Kore.ai XO Platform, refer here. For a use case with Content Variables, refer here.
Problem Statement
In our Travel Planning Assistant, we have two tasks:
- Check Flight Status, which makes a service call and retrieves the flight status based on a flight number provided by the user.
- Update Booking, which makes a service call to update user bookings based on the booking number and type of update.
Both the above tasks call the same service and the service API endpoint changes for development, testing, and production environments.
Changing the service call in both the Dialog Tasks is cumbersome and can lead to errors, if the change is not done properly.
In this document, we will see how Global Variable can be used to store the API endpoint and use it for the service calls.
Prerequisites
To go through these configurations, you need to know at least the basics of building a Virtual Assistant. This is because your assistant needs to have been already built when you begin working on your variables.
Implementation
Declaring a Global Variable to hold the API endpoint will help make the transition easier and faster.
- Open the Travel Planning Assistant.
- Select the Build tab from the top menu.
- From Configurations select the Environment Variables section.
- Click Add Variable to open the corresponding window.
- Enter Variable Name and Variable Value. For this use case, we are calling the Variable bookingURL, and for value, we are entering the Service API call endpoint.
- Save.
- Now open the Check Flight Status Dialog Task.
- Select the Get Status Service Node.
- Click Edit Request under the Request Definition
- Replace the request URL with the Global Variable created above. using the env prefix followed by any parameters needed. In this case:
{{env.bookingURL}}{{context.entities.FlightNumber}}
- Repeat for the Update Booking Dialog Task.
- Now when you Export and Import the assistant to another environment, all you need to worry about is to change the value of the Global Variable and the changes will be effective in both the Dialog Tasks.