Sometimes it may come in handy to make use of a pre-existing script or a data set in your solution. In Teneo it is possible to upload a variety of different file formats, from Groovy scripts to compiled .jar files, as well as simple text based formats such as .txt or .csv.
On this page will:
The .csv file with the opening hours for Longberry Baristas coffee shops can be downloaded here. It consists of two columns, one for the weekdays and one for the respective opening hours.
To add the file your solution, proceed as follows:
/script_lib
. This ensures the file can be accessed using a Groovy script later.In order to access the content of this file, we will process the file content and store it in a global variable using a Groovy script. This script will be executed at the beginning of each new dialog. Before we can do that however, we need to add the global variable in which we want to store the opening hours.
Let's start with creating the global variable in which will store the opening hours:
businessHours
.[:]
.Now we will add the Groovy code to the global script 'Begin Dialog'. Scripts in 'Begin Dialog' are executed each time a conversation starts. Our script will read the .csv file, turn the data into a map and store it in the global variable we created earlier.
You can now edit the 'Begin Dialog' and paste the following code snippet below the already existing code:
// get the csv file
def file = groovy.io.FileType.class.getClassLoader().getResource('business_hours.csv')
// parse the csv
file.eachLine {
def (k,v) = it.split(",")
businessHours[k] = v
}
The existing code in the 'Begin Dialog' script came with the Teneo Dialogue Resource template solution that you used when you created the solution.
To find out whether the opening hours from the .csv file have been correctly loaded into the global variable, we can look at the value of this variable after having started a new dialog:
Was this page helpful?