-
Notifications
You must be signed in to change notification settings - Fork 22
Default and Local Fallback
A fallback is the reaction of the bot when it receives an unexpected intent. In the example below the bot expects a number from the user, but receives a city name. Since the bot cannot continue the conversation it triggers a fallback and asks the user to rephrase.
[Bot] Hi! Let's play a game, can you pick a number between 1 and 10?
[User] Barcelona
[Bot] Sorry I didn't get it, can you try again?
A default fallback is the generic error reaction executed by the bot, such as the Sorry I didn't get it
answer above. They are defined once for the entire application, and triggered every time an error occurs. Default fallback are usually not very helpful to the end user because they don't have access to much contextual information, and need to be generic enough to work at every possible failure point.
Local fallbacks are the opposite: they are defined at a specific failure point in your bot's conversation flow, and have access to contextual information. A local fallback can use this additional information to provide better feedback to the user (e.g. reply I am expecting a number here
in the example above), print some examples of valid inputs, or even access a knowledge base to find a possible answer.
📚 While local fallbacks are the most adapted for customized feedback, it's usually a good practice to define a default fallback as a safety net for uncaught errors.
Xatkit's DSL provides out of the box constructs to define local and default fallbacks. A Xatkit bot is a state machine containing states representing bot reactions, linked with transitions representing user intents.
The Xatkit state machine contains a mandatory defaultFallback
state, that is executed when an unexpected intent is received and the current state does not define a local fallback:
model()
.initState(myInitState)
.defaultFallbackState(fallbackState()
.body(context -> react.reply("Sorry I didn't get it"));
)
Note that this fallback state does not contain any transition. The Xatkit engine will automatically return to the previous valid state once the fallback has been executed.
Xatkit local fallbacks are directly defined inside their containing state. The DSL provides the optional fallback
construct after the transition definition, which accepts a context parameter containing all the contextual information of the current conversation.
state("MyState")
.body(context -> {
react.reply(context, "Hi! Let's play a game, can you pick a number between 1 and 10?"")
})
.next()
.when(intentIs(IntegerValue)).moveTo(handleCity)
.fallback(context -> {
react.reply("Sorry, I am expecting a number here");
})
- Getting Started
- Configuring your bot
- Integrating an Intent Recognition Provider
- Adding a bot to your website
- Deploying on Slack
- Basic concepts
- Intents and Entities
- States, Transitions, and Context
- Default and Local Fallbacks
- Core Library