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!

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!

use..as (deprecated)

See as keyword.
This keyword will be deprecated in a future release.
1
use 42 as answer
2
​
3
say "The answer is {{answer}}"
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!

break, continue

Exit from loops 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
say "{{ls.owner}} had a {{ls.color}} lightsaber"
14
// we want to stop after we find the first green lightsaber
15
if (ls.color == "green") break
16
}
17
​
18
say "There might be even more lightsabers!"
Copied!

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!

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!

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.
Last modified 4mo ago