Skip to content

fallback

morfeusys edited this page Mar 31, 2020 · 4 revisions

Each time the user sends a request that can't be handled by any state of the scenario, a fallback state will be activated without a changing the current dialogue's context.

init {
    state("state1") {
        activators {...}
        action {...}
    }
    
    fallback {
        reactions.say("Sorry, I didn't get that. Could you repeat please?")
    }
}

CatchAll activator

Fallback builder utilises a CatchAll activator. Thus you have to add it to the list of activators of the BotEngine:

val helloWorldBot = BotEngine(
    model = HelloWorldScenario.model,
    activators = arrayOf(
        ...,
        CatchAllActivator
    )
)

Dialogue context

Fallback state doesn't change the current dialogue's context meaning that the next user's request will be processed in the same context as a previous one.

Context-aware fallbacks

It's possible to use fallback as an inner state:

init {
    state("state1") {
        activators {...}
        action {...}

        fallback {
            reactions.say("Okay!")
        }
    }
    
    fallback {
        reactions.say("Sorry, I didn't get that. Could you repeat please?")
    }
}

Clone this wiki locally