Skip to content

activators

morfeusys edited this page Mar 17, 2020 · 6 revisions

Each scenario's state can be activated by any of configured activator - a rule that tries to handle the user's request and find an appropriate state to activate. Activators function is a builder function of scenario that can be used to define which activators could activate the state.

How it works

state("launch") {
    activators {
        regex("/start")
        event(AlexaEvent.LAUNCH)
        intent(DialogflowIntent.WELCOME)
    }

    action {
        ...
    }
}

Here is a top-level state "launch" that can be activated by Alexa's LAUNCH event, Dialogflow's WELCOME intent or regular expression that matches any input with "/start" character sequence.

Learn more about different activators here.

globalActivators

By default activators will activate the state only if the parent state was activated previously. You can configure activators to be global - in this case the state can be activated by these activators as it was a top-level.

state("main") {
    state("inner") {
        activators {
            intent("some_intent")
        }
        globalActivators {
            event("activate_inner_state")
        }
    }
}

In the example above state "inner" could be activated by two different activators - intent activator with "some_intent" intent's name and event activator with "activate_inner_state" event's name. Once the intent activator could activate this state only in case the parent "main" state was activated previously, the event activator is a global and can activate "inner" state from everywhere.

fromState

Activators function accepts an optional state path from where it is available. It means that you can "override" a parent's state path to make a state available from some other state.

state("main") {
    state("inner") {
        activators("/other") {
            event("event1")
        }
    }
}

In the example above "inner" state can be activated once a dialogue is in state "/other". You can think about this as a mix-in feature.

Clone this wiki locally