Built-in Functions
Macros are built-in functions that perform some common tasks. Below is a list of some common macros that you can use at any stage in your CSML flows.
OneOf
Return one the elements of the array passed in the first argument at random.
Useful for randomisation of dialogue parts!
Or
If the first element exists return it, otherwise return the second argument as a default value
Shuffle
Given an array, return it with its elements in a random order.
Especially useful in questions to randomize the available options!
Find
Return whether a string is contained in another string.
Length
Return the length of a given string or array
Random
Return a random floating point number in the range 0-1 (0 included, 1 excluded).
Floor
Return the largest integer less than or equal to the given number.
This is useful to generate a random integer in a given range:
UUID
Generate a random UUID (v1 or v4, defaults to v4)
Time
The Time()
helpers lets your manipulate timestamps and dates easily.
CSML's Time function is based on Rust's Chrono library. All the formatting options are listed here: https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html
Exists
Check if a variable has been saved in the chatbot's memory before for the current user.
Exists
only checks for the existance of top-level variable names in the chatbot's memory for the current user, i.e obj
and not obj.prop
Last updated