Keywords
Action keywords
goto
Inside a step, goto some other step. The step's memories are saved and its messages are sent right after this instruction, and before the next step is started.
Special cases:
If the target step does not exist, the conversation will be closed.
If the target step is
end
, the conversation is closed.
goto
behaves as return
in other languages: anything after a goto
is ignored, the goto
is immediately executed.
To reach another flow, you can also use goto flow otherflow
.
say
Send a message to the end user. For the full reference on Components
debug
Print a simplify version of the following value. Its output is a special debug component (same structure as a Text
component with a debug
content_type).
If the value is a primitive (String, Number...), it will be printed entirely. If it is an Object or Array, only the structure of the first level will be printed.
Unlike the say
keyword, it can also be used inside native CSML functions:
hold
Wait for user input: simply hold
the conversation in place until the user responds.
hold_secure
introduced in CSML v1.10.0
Same as hold
, except any user input that comes after that will not be saved in any CSML memory or displayable. However, you can perform operations on the value itself. This is a good use case for secret values that should not be saved in clear text anywhere in a database:
This keyword should be used with extreme care. It is for example a very bad practice to ask users for their password in a chat, and it should not be used for this purpose. However, this keyword can be extremely useful to share data (personal information, short-lived secrets...) that requires extra precautions or should not be stored in clear text (or at all).
remember
Save a value to the bot's memory with the given key. It can later be retrieved (as soon as the next step) with "{{memory_item}}"
.
By default, the scope is bot/user/channel. The same user on a different channel, or a different user on the same channel, or the same user with a different bot will get a fresh memory instance.
do
Execute the following expression.
Usually used for executing functions without caring for its return value, or for updating values of objects or arrays.
When used in an assignment (as in x = y
), the value x
is saved as a local (temporary) variable.
forget
The forget
keyword lets you forget memories selectively, or globally.
Root-level keywords
These keywords can only be used at the root of the flow, outside of any step
const
Declare constant values that are accessible and immutable across the whole flow. Two different flows can have a different set of const
or different values for the same const
!
import
Other keywords
as
Save any value as a local variable, only available within the step. Local variables remain in memory after the step is done.
if / else if / else
Simple logic operators if
, else if
and else
. See examples.
foreach
Iterate over each element of an array.
while
A simple loop with a condition check at every turn
break, continue
Exit from loop early, or skip an iteration
Deprecated keywords
match (deprecated)
This syntax is obsolete, but for backwards-compatibility reasons remains valid CSML. However, prefer using the event.match(...)
alternative which is much more versatile.
Whether or not a variable "equals", in any way, another variable.
use..as (deprecated)
This syntax is obsolete, but for backwards-compatibility reasons remains valid CSML.
See as
keyword.
Operators
Mathematical Operators
In CSML, you can use the 4 basic mathematical operators +
, -
, *
and /
, as well as the modulo operator %
. The regular order of operations applies.
Additionally, since CSML v1.8.0, you can use the shortcut +=
and -=
operators to add/subtract and assign values at the same time:
String Concatenation
Starting with CSML v1.8.0, you can concatenate two or more strings together by using the +
sign:
It is also possible to use string templating to insert any value in another string:
Last updated