Bots use adaptive expressions to evaluate the outcome of a condition based on runtime information available in memory to the dialog or the Language Generation system. These evaluations determine how your bot reacts to user input and other factors that impact bot functionality.
An adaptive expression can contain one or more explicit values, prebuilt functions, or custom functions. Consumers of adaptive expressions also have the capability to inject additional supported functions. For example, all language generation templates are available as functions as well as additional functions that are only available within that component's use of adaptive expressions.
Operators
Adaptive expressions support the following operator types and expression syntax:
Concatenation operators. Operands will always be cast to string. Examples: A & B, 'foo' + ' bar' => 'foo bar', 'foo' + 3 => 'foo3', 'foo' + (3 + 3) => 'foo6'
N/A
'
Used to wrap a string literal. Example: 'myValue'
N/A
"
Used to wrap a string literal. Example: "myValue"
N/A
[]
Used to refer to an item in a list by its index. Example: A[0]
N/A
${}
Used to denote an expression. Example: ${A == B}.
N/A
${}
Used to denote a variable in template expansion. Example: ${myVariable}
N/A
()
Enforces precedence order and groups sub expressions into larger expressions. Example: (A+B)*C
N/A
.
Property selector. Example: myObject.Property1
N/A
\
Escape character for templates, expressions.
N/A
Variables
Variables are always referenced by their name in the format ${myVariable}. They can be referenced either by the property selector operator in the form of myParent.myVariable, using the item index selection operator like in myParent.myList[0], or by the getProperty() function.
There are two special variables. [] represents an empty list, and {} represents a empty object.
Explicit values
Explicit values can be enclosed in either single quotes 'myExplicitValue' or double quotes "myExplicitValue".
Functions
An adaptive expression has one or more functions. For more information about functions supported by adaptive expressions, see the prebuilt functions reference article.
Bot Framework Composer
Bot Framework Composer is an open-source visual authoring canvas for developers and multidisciplinary teams to build bots. Composer uses adaptive expressions to create, calculate, and modify values. Adaptive expressions can be used in language generation template definitions and as properties in the authoring canvas. As seen in the example below, properties in memory can also be used in an adaptive expression.
The expression (dialog.orderTotal + dialog.orderTax) > 50 adds the values of the properties dialog.orderTotal and dialog.orderTax, and evaluates to True if the sum is greater than 50 or False if the sum is 50 or less.
Adaptive expressions are used by language generation (LG) systems to evaluate conditions described in LG templates. In the example below, the join prebuilt function is used to list all values in the recentTasks collection.
# RecentTasks
- IF: ${count(recentTasks) == 1}
- Your most recent task is ${recentTasks[0]}. You can let me know if you want to add or complete a task.
- ELSEIF: ${count(recentTasks) == 2}
- Your most recent tasks are ${join(recentTasks, ', ', ' and ')}. You can let me know if you want to add or complete a task.
- ELSEIF: ${count(recentTasks) > 2}
- Your most recent ${count(recentTasks)} tasks are ${join(recentTasks, ', ', ' and ')}. You can let me know if you want to add or complete a task.
- ELSE:
- You don't have any tasks.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.