Skip to main content

Trigger tags

Trigger tags determine the user actions and events which can switch the dialog context to some state. There are two types of all trigger tags: local and global tags.

  • Transitions by local tags can be made only from the nearest parent, sibling, or children states.
  • Transitions by global tags can be made from anywhere in the script. Their names end with !.
TagDescription
q
q!
Declares a pattern by which the dialog can enter a state.
intent
intent!
Declares an intent by which the dialog can enter a state.
intentGroup
intentGroup!
Declares a group of intents by which the dialog can enter a state.
event
event!
Declares an event by which the dialog can enter a state.

Parameters

info

Parameters are key–value pairs separated from the name or value (if present) with two vertical bars. If there are several parameters, they are separated from each other with commas. Parameters modify the tag behavior.

All local tags (q, intent, intentGroup, event) accept the following parameters:

ParameterTypeDescriptionDefault value
fromStateStringA path to a state from which a transition to the current state by this event tag can be made.
toStateStringA path to a state to which a transition from the current state by this event tag can be made.
onlyThisStateBoolean• If true and the fromState parameter is present, a transition to the current state can be made strictly from the state specified in fromState, but not from its nested states.
• If true and the toState parameter is present, a transition to the state specified in toState can be made strictly from the current state, but not from its nested states.
false

fromState

The fromState parameter sets a path to a state from which a transition to the current state by this event tag can be made.

tip
Use the fromState flag to switch the dialog from a certain context to the necessary state without using global patterns. Additionally, this is one of the ways you can exit the context of modal states.

Take a look at an example. In the script below, the user can exit the context of the OrderStatus modal state if they don’t know the order number.

theme: /

state: OrderStatus || modal = true
q!: * (where/status) * [my] ~order *
a: What is your order number?

state: GetNumber
q: * @duckling.number *
a: Your order is on its way!
go!: /WhatElse

state: LocalCatchAll
event: noMatch
a: This doesn’t look like an order number. Please try again.

state: WhatElse
intent: /DontKnow || fromState = "/OrderStatus"
a: What else can I help you with?

toState

The toState parameter sets a path to a state to which a transition from the current state by this event tag can be made.

tip
toState has the same function as fromState, and whether you should use one or the other is largely a matter of personal preference. When you need to set up possible transitions from one state to multiple states scattered across different parts of the script, then toState is preferable: in this way, all the information related to possible context changes is kept in one place.

The following example works in the same way as the one above. Note that trigger tags with the toState parameter are usually written after all reaction tags.

theme: /

state: OrderStatus || modal = true
q!: * (where/status) * [my] ~order *
a: What is your order number?
intent: /DontKnow || toState = "/OrderStatus"

state: GetNumber
q: * @duckling.number *
a: Your order is on its way!
go!: /WhatElse

state: LocalCatchAll
event: noMatch
a: This doesn’t look like an order number. Please try again.

state: WhatElse
a: What else can I help you with?

onlyThisState

The onlyThisState parameter is used together with either fromState or toState. If set to true, it restricts the state from which or to which a transition can be made by the current trigger tag.

  • If the fromState parameter is present, a transition to the current state can be made strictly from the state specified in fromState, but not from its nested states.
  • If the toState parameter is present, a transition to the state specified in toState can be made strictly from the current state, but not from its nested states.

Take a look at an example. In the script above, it was possible to make a transition to /WhatElse from either /OrderStatus or /OrderStatus/LocalCatchAll, while in the one below, only transitions from /OrderStatus are allowed.

theme: /

state: OrderStatus || modal = true
q!: * (where/status) * [my] ~order *
a: What is your order number?
intent: /DontKnow || toState = "/OrderStatus", onlyThisState = true

state: GetNumber
q: * @duckling.number *
a: Your order is on its way!
go!: /WhatElse

state: LocalCatchAll
event: noMatch
a: This doesn’t look like an order number. Please try again.

state: WhatElse
a: What else can I help you with?