Methods and APIs overview
Expression language provides a set of methods and built-in APIs that are used to access and process various data. They are one of the most important Expression language features.
On this page, you will find an introductory information about what methods and APIs can help you with and how to use them properly. Detailed lists of methods and APIs can be found on separate pages listed below.
Methods are functions that can be used on specific types of data. In Expression language, there are 4 types of data that have their own methods:
- date time values.
Methods are used to process and filter data. The most common operations performed by methods are:
- Editing and editing in bulk (eg. mapping an array to change all of its elements using the same function).
- Formatting (eg. changing string's characters to uppercase or formatting a date).
- Filtering and sorting (eg. deleting duplicated elements from an array).
- Accessing values and information (eg. checking the number of elements in an array or retrieving a month number from a date).
How to use methods?
To use a method, put a dot
. directly after a variable, add a method name and finish with the brackets
VARIABLEmay be a string, an array, an object or a DateTime value. In the example below, we can use an array written literally
[1, 2, 3]or an array stored in a variable, eg.
METHOD NAMEis the name of currently used method, eg.
()if there are any arguments required, they go into this brackets. If not, leave them empty.
[1, 2, 3].length()
The best way to learn how to use methods is toanalyze examples added to every listed method.
Using multiple methods in the same expression
Any time you use a method, the existing piece of expression is treated as a result that can be immediately processed by another method added to the same expression, like this:
Let's say we want to delete duplicates from an array using
unique() method and then use
length() to check how many elements the new array has.
[1, 2, 3, 6, 8, 2, 5, 8, 8].unique() - this expression uses
unique() to get an array without any duplicated elements. When the code is evaluated, this part is already treated as a new array with unique elements:
[1, 2, 3, 6, 8, 5]
This is why now, instead of adding another block or another memory input to check
length() of this new array, we can do it by simply adding to the already existing expression:
[1, 2, 3, 6, 8, 2, 5, 8, 8].unique().length()
The result of this expression will be identical to this one:
[1, 2, 3, 6, 8, 5].length(), which is 6.
There is no limit to the number of methods used in the same expression.
There are four APIs built into Expression language that are used to access and sometimes process data relevant to bot development:
- NLU API
- System API
- DateTime API
- System Math API
- Knowledge Base API
NLU API is the most important Expression language environment which allows bot designers to use recognized intents and entities in flows.
For example, to access a name of the intent recognized by the NLU in the most recent user input, use
NLU API is commonly used to steer the conversation and save variables based on user preferences.
System API contains a set of general variables that can be accessed at any time, like session id, content of the last user input, current time etc.
DateTime API provides a set of methods that can be used to process and format DateTime values.
System Math API
System Math API contains a set of handy mathematical and geometrical methods.
Knowledge Base API
Knowledge Base API is a small API that enables accessing Knowledge Base items. Knowledge Base items can also be accessed, filtered and processed using arrays and objects methods.
Updated 7 months ago