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
.
onestep:goto somestepsay "after the goto" /* will not be executed */goto someotherstep /* will not be executed */somestep:say "hi"someotherstep: /* will not be executed */say "hey"
Send a message to the end user. For the full reference on Components
say "The quick brown fox jumps over the lazy dog."
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.
do somevalue = 123debug somevalue // output: 123do mylargeobj = {"val": 1,"something": {"toto": "tutu" },"other": "hello","onemore": [1, 2, 3]}debug mylargeobj // output: {"val": 1, "something": "[Object]", "other": "hello", "onemore": "[Array]"}
Unlike the say
keyword, it can also be used inside native CSML functions:
fn is_triple_even(num):do triple = num * 3debug triplereturn (triple % 2)
Wait for user input: simply hold
the conversation in place until the user responds.
somestep:say "What's up doc?"holdremember updoc = eventgoto end
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.
// remember a hardcoded valueremember truc = "tutu"// remember a local variabledo myvar = 123remember tata = myvar// overriding a local variable's scopedo myvar = 123 // `myvar` has a local scoperemember myvar = myvar // `myvar` is now a globally-available memorydo myvar = myvar // `myvar` will still be available globally
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.
// execute a functiondo Fn("someFunc")// assign new valuesdo array[3] = "X"do obj.val.toto = 123// however, this will fail:remember myarr = [1, 2]do myarr[42] = 1 // the array needs to have at least the requested number of itemsremember myobj = Object("key"="value")do myobj.missing.otherkey = 1 // all the parent properties must exist and be objects as well
See as
keyword.
This keyword will be deprecated in a future release.
use 42 as answersay "The answer is {{answer}}"
Iterate over each element of an array.
do array = ["a", "b", "c"]foreach (val, index) in array {say "at position {{index}} is element with value {{val}}"}
Exit from loops early or skip an iteration.
remember lightsabers = [{"color": "red", "owner": "Kylo Ren"},{"color": "purple", "owner": "Mace Windu"},{"color": "yellow", "owner": "Rey Skywalker"},{"color": "green", "owner": "Yoda"},{"color": "red", "owner": "Darth Vader"},{"color": "green", "owner": "Luke Skywalker"},]foreach (ls) in lightsabers {// we want to skip any red lightsaberif (ls.color == "red") continuesay "{{ls.owner}} had a {{ls.color}} lightsaber"// we want to stop after we find the first green lightsaberif (ls.color == "green") break}say "There might be even more lightsabers!"
Save any value as a local variable, only available within the step. Local variables remain in memory after the step is done.
do Button("A") as btn1// is equivalent todo btn2 = Button("B")// say and save a component at the same timesay Question(title = "Pick one",buttons = [btn1, btn2] as btnlist) as myquestion// repeat the same questionsay myquestion
Simple logic operators if
, else if
and else
. See examples.
// regular notationif (1 > 2) {say "I have my doubts"} else if ("mi casa" == "tu casa") {say "Welcome home"} else {say "The force is strong with you"}// shorthand notationif (sky == "blue") goto beachelse goto restaurant
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.
do Button(title = "I agree",accept = ["OK", "yes", "right"]) as btn/* a direct click on the button will match the button *//* typing "yes" will match the button *//* typing "of course" will not match the button */if (event match btn) { // Note: this is equivalent to event.match(btn)say "good"} else {say "not good"}
In CSML, you can use the 4 basic mathematical operators +
, -
, *
and /
, as well as the modulo operator %
. The regular order of operations applies.