conditions - Avaya-CXI/virtual-agent-public GitHub Wiki
HOME / REFERENCE DOCUMENTATION / CONDITIONS
Virtual Agent allows you to format options so that they are only triggered when certain conditions are met. If all you are doing is matching against static DTMF/speech values then you should be fine with just using the DTMF / Speech input fields. However if you want to only allow certain options to trigger when the fulfillment response contains a certain value or during a certain time of the day / day of the week then you will need to use Conditions. To enable an option for Conditions, simply check the Condition box on the option of interest. An input field should then appear where you can type out your condition. Below is a simple example that triggers when the DTMF value is 1 and the UserInput.type field is equal to “dtmf”. When the Virtual Agent attempts to match options, it first looks at the DTMF and Speech inputs, unless the options that may be triggered subsequently follow a Record menu that was not in the recorded in the background. When the options follow a Record menu (No Speech / No DTMF) then only the Conditions are checked against for the option matching. Otherwise, if the options being matched against do not directly follow a Record menu then the options are matched based on the DTMF/Speech inputs in conjunction with the condition. If an option matches either the DTMF or Speech Input and does not contain a condition, then that option will be matched. If an option matches DTMF or Speech Input and also contains a condition that evaluates to true, then this option is matched. If no options are matched after checking the conjunction of the DTMF/Speech input and the conditional evaluation, then Virtual Agent will attempt to match an option purely based on of the condition. If it then finds a condition that evaluates to true, it will return that option, but only after it already tried to match the DTMF/Speech input AND the condition.
When formulating a condition it is crucial to remember the following. Virtual Agent tokenizes the input based on spaces that do not lie between a set of quotes. So in the above example, Virtual Agent would see 3 tokens, one for UserInput.type, one for the == , and another for “dtmf”. There must be a space between each token or else Virtual Agent will assume it is all the same token. Below are some more examples under “Conditional Examples”. When wrapping string values and object field references that contain spaces, please use double quotes. Pay attention to the spacing between the tokens even when using parenthesis to wrap expressions. The Virtual Agent supports combining expression results with AND and OR, they must be used exactly like this in all caps. The Virtual Agent also supports the following comparators: == , != , > , < , >= , <=
The Virtual Agent recognizes one common function which is the .contains() function. This function checks to see if the value that it is invoked on contains the string that is passed in as a parameter to the function. Examples 13 and 14 below show how to use this function.
Nested expressions are also supported. It is important to remember that if you are nesting several expressions, then there must be a space between each token including the parenthesis being used to group expressions. Examples 11 and 12 below show how to do this. It is possible to access a specific numeric index of an array as well. Example 10 shows this. Any value that would typically have the .length property will also have that property in the Virtual Agent. For example you might want to check the length of an array or a length of a string. Examples 6, 7 and 8 show how this can be done. Lastly, the Virtual Agent supports conditional expressions that need to look at time of day, day of the week, current month, or current year. You could find more information on how to use the DATE object in Virtual Agent conditions in the corresponding Virtual Agent DATE Object document. However, there are a few examples below to quickly highlight how to use them in conditions. Virtual Agent DATE is all in UTC.
UserInput.value == "1"
1==1
UserInput.value == "1" AND fulfillmentResponse != null
UserInput.value == "1" OR fulfillmentResponse != null
UserInput.value == "1" OR UserInput.value == "2"
UserInputHistory.length > 0
UserInputHistory.length != 0
UserInputHistory.length == 3
UserInput.value == fulfillmentResponse.value
fulfillmentResponse.responseArray[0].field1 == "5"
UserInput.type == "speech" AND ( UserInput.value == speechValue OR UserInput.value == "live agent" )
UserInput.type == "speech" AND ( UserInput.value == speechValue OR ( UserInput.value == "live agent" AND UserInput.value != "" ) )
UserInput.value.contains("name") == true
UserInput.value.contains(fulfillmentResponse.name) == true
UserInput.NO_INPUT == true
DATE.hours >= 13 //After 1pm UTC time
DATE.hours >= 13 AND Date.minutes >= 30 //After 1:30 pm UTC time
DATE.monthNumeric == 11 AND DATE.dayOfMonthNumeric == 25 //Christmas
DATE.dayOfWeekNumeric == 0 OR DATE.dayOfWeekNumeric == 6 //Saturday or Sunday
( DATE.dayOfWeekNumeric == 0 OR DATE.dayOfWeekNumeric == 6 ) AND DATE.hours >= 4