Skip to main content

YAML dictionaries

YAML dictionaries are used for storing various structured data relevant to the project.

Sample use cases of YAML dictionaries:

  • You can transfer the texts of your bot’s replies to a YAML dictionary in order to store them in one place and maintain them separately from the code.
  • Separate dictionaries should be created for bot configuration properties which are referenced often and are liable to be changed, such as external API keys, counter thresholds, etc.


YAML dictionaries are placed in files with the .yaml or .yml extension.

YAML is a simple format for storing typed values and standard data structures, such as sequences and key–value pairs of arbitrary depth. This is an example YAML dictionary:

id: 1
summary: Greeting
- Hello, {{$}}!
- {{$}}, nice to meet you!

# ...

id: 99
summary: Unrecognized input
- Sorry, I didn’t catch that.
- Could you rephrase your question?
If you want to use strings from a YAML dictionary after reaction or action tags, they can include string interpolations. The {{}} brackets can contain any valid JavaScript expression. It will be resolved and interpolated into the string during bot runtime.


To import a YAML dictionary into the script, use the require tag with a var parameter:

require: states.yaml
var = states
After being imported, the dictionary will be transformed into the equivalent JavaScript object. It can be referenced from the script by the name provided after var.

How to use

Let’s use the dictionary defined and imported above to send a random reply to unrecognized input. Note the use of $reactions.random to generate a random number.

state: CatchAll
event!: noMatch
$temp.index = $reactions.random(states.catchAll.answers.length);
a: {{states.catchAll.answers[$temp.index]}}