Constants
Constants¶
Variables starting with an @
are treated as constant values. These
can only be defined outside a dialog.
@constant "key"
@version 12
@message "Hello and welcome!"
dialog main do
say @message
say "My version is: " + @version
end
notice that you do not need to use an assign (=) character for assigning values into a constant!
Platform-specific constants¶
The following constants have special meaning, when they are defined.
@timeout
- defines when the__timeout__
dialog should be triggered. The timeout is specified in the number of seconds since the last user message. Alternatively, it can specifed in human readable format, like"1h"
or"15m"
. When there was no user message, the timeout dialog will never be triggered.@delay
- defines the standard delay (in seconds) after the bot shows the next 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)@duckling_reftime
- When set to"start_of_day"
, all Duckling-related message triggers are calculated with a reference time from the start of the day instead of the current time.
Example:
@ask_timeout :infinity
@timeout "15m"
@delay 1
@typing_indicator 1
# Other time formats
@timeout "1h"
@timeout "60s"
@timeout "200ms"
Besides these globals that can be overwritten there are some read only globals that you MUST NOT overwrite:
@intents
- is a list of all intents defined in the intents files (read only)@skills
- is a list of the skills (modules) this bot has (read only)
Note: the intents and data files you create also create constants that can conflict with these system constants. So don't create an intent or data file with the name
skills
orintents
Intent constants¶
When you create new intents via the training panel or directly in the training yaml file they will be exposed in the code as constants. So the @yes
constant refers to the yes
intent.
Loading constants from a file¶
When adding a YAML or a JSON file in the DialoX 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
following contents:
- 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@data_people
.Read more about data files and content management
Constant accumulation¶
The accumulate
top-level statement can be used to merge constants from
different files together into a list. The use case of this is that sometimes
there are various skills in a bot which all contribute to some list
constant. This cannot be done using a normal constant because constants
overwrite each other when they are defined in multiple files.
So by prepending the constant with the accumulate
keyword, the value is forced
to be a list and collected from all script files.
As an example, when you have in one file:
accumulate @list 1
And in another:
accumulate @list 2
The @list
constant will contain the list [1, 2]
.