Variables starting with an
@ are treated as constant values. They can only
be defined outside dialog.
@constant "key" @version 12 @message "Hello and welcome!" dialog main do say @message say "My version is: " + @version end
The following constants have special meaning, when they are defined.
@timeout- defines how long the script will be allowed to run before it times out. When the script times out, the next time the user interacts with the bot, a new session is started (starting again in the
@delay- defines the standard delay (in seconds) after the bot shows a message to the user
@typing_indicator- defines the standard delay (in seconds) how long the typing indicator should be displayed before any message is shown to the user.
@ask_timeout- defines how long to wait for a user to give an answer on a question (ask)
@ask_timeout :infinity @timeout "15m" @delay 1 @typing_indicator 1
Loading constants from a file¶
When adding a YAML or a JSON file in the Botsqud studio, the contents of that file is exposed in a constant which is named after the JSON/YAML script file name.
Data files are a convenient way to keep data outside the bot script contents, but still embedded as part of the bot.
For instance, when you create a YAML file called
people with the
- name: Arjan age: 38 - name: Pete age: 22 - name: Julie age: 32
The contents of the
people file is now accessible in your bot script
under the constant
@people. It can be used like this:
repeat person in @people do say "Name: " + person.name say "age: " + person.age end
When a data file is defined in a folder, say, a data file named
data/people, the slash in the filename will be transliterated into an underscore, so that in this case, the constant name becomes
Read more about data files and content management
It is possible to create a list of constant values which is assembled
over multiple scripts, by using a special
Script one contains:
accumulate @a, "hello"
Script two contains:
accumulate @a, "world"
When used in dialogs, the final value of the constant
@a will now be
the list of
["hello", "world"]. This construction is used to build
composable lists of intents or values.