Introduction to States — Jovo Beginner Course Part 5
States let you manage conversational context in your Jovo app. Without states, every intent fires the same handlers regardless of where the user is in the conversation. With states, you can have an AskNameState where only a name-response handler is active, and a separate QuizState with its own logic. This is Part 5 of the Jovo Beginner Course.
What Are States?
A state is a named context that Jovo persists in the user session. When a user is in a state, Jovo first looks for handlers registered under that state before falling back to global handlers.
// Enter a state
this.followUpState('NameState')
.ask('What is your name?');
// Handle intent inside that state
NameState: {
async MyNameIsIntent() {
const name = this.$inputs.name.value;
this.tell(`Hello, $\{name}!`);
}
}
States in Jovo v4
In Jovo v4, states work through component routing. Each component acts as its own state scope, and you navigate between components with $delegate():
async START() {
return this.$delegate(NameComponent, {
resolve: {
resolved: this.onNameCollected,
}
});
}
Unhandled in States
If a user says something unexpected while in a state, Jovo calls Unhandled inside that state first. If none exists, it falls through to the global Unhandled. Always define a state-level Unhandled to re-prompt the user gracefully:
NameState: {
async Unhandled() {
this.followUpState('NameState')
.ask('Sorry, I did not catch that. What is your name?');
}
}
Course progress: This is Part 5 of the Jovo Beginner Course. See the Hello World project to start from the beginning.