Methods and APIs overview
Expression language (AEL) 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 AEL 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
Methods are functions that can be used on specific data types. In AEL, there are 5 types of data that have their own methods:
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 duplicates from an Array).
- Accessing values and information (eg. checking the Number of elements in an Array or retrieving a month 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 ()
:
VARIABLE
+ .METHOD_NAME()
VARIABLE
may be a String, an Array,a Number, 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.memory.myArray
.METHOD NAME
is the name of the currently used method, eg.length
.()
if there are any arguments required, they go into this brackets. If not, leave them empty.
Example:
[1, 2, 3].length()
The best way to learn how to use methods is to analyze 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:
VARIABLE
+ .METHOD_NAME()
+ .METHOD_NAME()
+ .METHOD_NAME()
Example
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.
APIs
There are 5 APIs built into Expression language that are used to access and sometimes process data relevant to bot development:
NLU 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.intent
.
NLU API is commonly used to steer the conversation and save variables based on user preferences.
System API
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
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 8 months ago
Learn more about methods and APIs, discover dozens of AEL examples: