Switching states
A chat bot script is defined in a text file with a tree structure. This means some elements are nested in other ones. These elements are states of the system it can switch to in the course of a conversation. They are called system states. Generic states include more specific states.
Switching to a state
A state is switched in the following cases:
Activation rules for patterns, intents and groups of examples in a script are processed for the following objects in descending priority: q!, eg!, intent!.
The conversation can switch to a global tag state from any other state. A local tag is only active in the context of the conversation; you can switch to this state from one of the nearest parent or child states.
- The client’s request falls under the
qtag pattern. - From the parent state, if the client’s request falls under a nested state.
- From any state, if the
fromStatestate is specified for theqtag. This flag defines the state from which a switch based on this pattern is possible. - When a
go!orgotag is activated.
Processing activation rules
When the system is in a state, rules associated with that state and all its parents are activated. Activation rules associated with that state have the highest priority.
Therefore, identical activation rules can be declared in different states, but they are processed depending on the current state of the system.
Consider the following script:
patterns:
$Yes = (yes|of course)
$No = (no|not|no way)
theme: /
state: Start
q!: $regexp</start>
go!: ../morning exercise
state: morning exercise
a: Do you do morning exercise?
state: every day
q: * $Yes *
a: Do you do morning exercise every day?
state:
q: * $Yes *
a: Good!
state:
q: * $No *
a: Morning exercise has to become your habit!
state:
q: * $No *
a: Morning exercise helps your body and brain wake up, work on yourself!This script shows how a client’s yes/no answers are processed depending on the active state.
Let us have a look at how this script is processed:
- The script is started,
go!redirect the client to themorning exercisestate. - The bot asks
Do you do morning exercise?from themorning exercisestate. - The system will then remain the current state where the patterns are active:
q: * $Yes *,q: * $No *. - The client answers
yesand the system switches to themorning exercise/every daystate. The bot then asksDo you do morning exercise every day?, and the system activates the next set of patterns. - The system will interpret the next answer of the client in the
morning exercise/every daycontext. Responses activate nested state patterns as they have a higher priority.