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 .
1
onestep:
2
goto somestep
3
say "after the goto" /* will not be executed */
4
goto someotherstep /* will not be executed */
5
6
somestep:
7
say "hi"
8
9
someotherstep: /* will not be executed */
10
say "hey"
Copied!

say

Send a message to the end user. For the full reference on Components
1
say "The quick brown fox jumps over the lazy dog."
Copied!

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.
1
do somevalue = 123
2
debug somevalue // output: 123
3
4
do mylargeobj = {
5
"val": 1,
6
"something": {"toto": "tutu" },
7
"other": "hello",
8
"onemore": [1, 2, 3]
9
}
10
debug mylargeobj // output: {"val": 1, "something": "[Object]", "other": "hello", "onemore": "[Array]"}
Copied!
Unlike the say keyword, it can also be used inside native CSML functions:
1
fn is_triple_even(num):
2
do triple = num * 3
3
debug triple
4
return (triple % 2)
Copied!

hold

Wait for user input: simply hold the conversation in place until the user responds.
1
somestep:
2
say "What's up doc?"
3
hold
4
5
remember updoc = event
6
goto end
Copied!

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:
1
start:
2
say "Type something super secret, I promise I won't tell!"
3
hold_secure // indicates that the next input will be secure
4
5
// Value can not be displayed back or remembered in any way
6
say "this is a secret: {{event}}" // prevented by CSML
7
remember impossible = event // prevented by CSML
8
do impossible = event // prevented by CSML
9
10
11
// You can however perform operations on the event,
12
// for example checking if the value is accepted
13
if (event == "password") say "This is hardly a good secret!"
14
else say "OK, good good"
Copied!
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.
1
// remember a hardcoded value
2
remember truc = "tutu"
3
4
// remember a local variable
5
do myvar = 123
6
remember tata = myvar
7
8
// overriding a local variable's scope
9
do myvar = 123 // `myvar` has a local scope
10
remember myvar = myvar // `myvar` is now a globally-available memory
11
do myvar = myvar // `myvar` will still be available globally
Copied!

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.
1
// execute a function
2
do Fn("someFunc")
3
4
// assign new values
5
do array[3] = "X"
6
do obj.val.toto = 123
7
8
// however, this will fail:
9
remember myarr = [1, 2]
10
do myarr[42] = 1 // the array needs to have at least the requested number of items
11
12
remember myobj = Object("key"="value")
13
do myobj.missing.otherkey = 1 // all the parent properties must exist and be objects as well
Copied!

forget

The forget keyword lets you forget memories selectively, or globally.
1
forget something // forget a single memory
2
forget [something, otherthing, thirdthing] // forget several memories at once
3
forget * // forget EVERYTHING (dangerous!)
Copied!

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!
1
const MY_CONST = 42
2
3
start:
4
say "The value of MY_CONST is {{MY_CONST}}" // The value of MY_CONST is 42
5
do MY_CONST = 14 // Forbidden! MY_CONST is immutable
Copied!

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.
1
do Button("A") as btn1
2
// is equivalent to
3
do btn2 = Button("B")
4
5
// say and save a component at the same time
6
say Question(
7
title = "Pick one",
8
buttons = [btn1, btn2] as btnlist
9
) as myquestion
10
11
// repeat the same question
12
say myquestion
Copied!

if / else if / else

Simple logic operators if, else if and else. See examples.
1
// regular notation
2
if (1 > 2) {
3
say "I have my doubts"
4
} else if ("mi casa" == "tu casa") {
5
say "Welcome home"
6
} else {
7
say "The force is strong with you"
8
}
9
10
// shorthand notation
11
if (sky == "blue") goto beach
12
else goto restaurant
Copied!

foreach

Iterate over each element of an array.
1
do array = ["a", "b", "c"]
2
foreach (val, index) in array {
3
say "at position {{index}} is element with value {{val}}"
4
}
Copied!

while

A simple loop with a condition check at every turn
1
do i = 0
2
while (i < 3) {
3
say "i = {{i}}"
4
do i = i + 1
5
}
Copied!

break, continue

Exit from loop early, or skip an iteration
1
remember lightsabers = [
2
{"color": "red", "owner": "Kylo Ren"},
3
{"color": "purple", "owner": "Mace Windu"},
4
{"color": "yellow", "owner": "Rey Skywalker"},
5
{"color": "green", "owner": "Yoda"},
6
{"color": "red", "owner": "Darth Vader"},
7
{"color": "green", "owner": "Luke Skywalker"},
8
]
9
10
foreach (ls) in lightsabers {
11
// we want to skip any red lightsaber
12
if (ls.color == "red") continue
13
14
say "{{ls.owner}} had a {{ls.color}} lightsaber"
15
// we want to stop after we find the first green lightsaber
16
if (ls.color == "green") break
17
}
18
19
say "There might be even more lightsabers!"
Copied!

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.
1
do Button(
2
title = "I agree",
3
accept = ["OK", "yes", "right"]
4
) as btn
5
6
/* a direct click on the button will match the button */
7
/* typing "yes" will match the button */
8
/* typing "of course" will not match the button */
9
if (event match btn) { // Note: this is equivalent to event.match(btn)
10
say "good"
11
} else {
12
say "not good"
13
}
Copied!

use..as (deprecated)

This syntax is obsolete, but for backwards-compatibility reasons remains valid CSML.
See as keyword.
1
use 42 as answer
2
3
say "The answer is {{answer}}"
Copied!

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:
1
do i = 8
2
do i += 5
3
say "i = {{i}}" // i = 13
Copied!

String Concatenation

Starting with CSML v1.8.0, you can concatenate two or more strings together by using the + sign:
1
do val1 = "John"
2
do val2 = "Nutella"
3
say val1 + " likes " + val2 // John likes Nutella
Copied!
It is also possible to use string templating to insert any value in another string:
1
do val1 = "John"
2
do val2 = "Nutella"
3
say "{{val1}} likes {{val2}}" // John likes Nutella
Copied!