Adaptive expressions

APPLIES TO: yesSDK v4 no SDK v3

Bots use 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.

Adaptive expressions address this core need by providing an adaptive expression language that can be used with the Bot Framework SDK and other conversational AI components, like Bot Framework Composer, Language Generation, Adaptive dialogs, and Adaptive Cards.

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:

Arithmetic operators

Operator Functionality Prebuilt function equivalent
+ Addition. Example: A + B add
- Subtraction. Example: A – B sub
unary + Positive value. Example: +1, +A N/A
unary - Negative value. Example: –2, -B N/A
* Multiplication. Example: A * B mul
/ Division. Example: A / B div
^ Exponentiation. Example: A ^ B exp
% Modulus. Example: A % B mod

Comparison operators

Operator Functionality Prebuilt function equivalent
== Equals. Example: A == B equals
!= Not equals. Example: A != B not(equals())
> Greater than. Example: A > B greater
< Less than. Example: A < B less
>= Greater than or equal. Example: A >= B greaterOrEquals
<= Less than or equal. Example: A <= B lessOrEquals

Logical operators

Operator Functionality Prebuilt function equivalent
&& And. Example: exp1 && exp2 and
|| Or. Example: exp1 || exp2 or
! Not. Example: !exp1 not

Other operators and expression syntax

Operator Functionality Prebuilt function equivalent
&, + 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".

Additional resources