What would be the right way to use delegate and resolve?


#1

Hey everyone,

I’m having a scenario where i have an intent with 2 entites. I also want to handle the scenario where the user only provides one of the two entities by giving a reprompt and saying “Please tell me ‘entity1’” in case he only provided ‘entity2’.
I’ve read about delegate and resolve in the docks but i don’t really understand how it works for my scenario?

Code wise I’d like that i can stop inside my Intent function and wait for the second input and then continue going down the function. I don’t want to create a seperate handler because i want to avoid having double code.

I think the solution should be quite simple to this but right now it’s hard for me to figure it out, hence i’m asking this to the community.

Thanks in advance


#2

In my case, I went with a stateless solution. Model phrases like “play show number” or “play by show number”, are recognized as IncompleteEpisodeNumberIntent, which asks “OK, what episode number”. “{number}”, or “number {number}” or “play show number {number}”, map to EpisodeNumberIntent, so any more-specific phrasing the user is likely to give me will do the right thing.

Staying with stateless also gives the user the opportunity to change their mind without my having to try to figure out what to do when the input doesn’t match the missing slot value.

That may or may not suit your application, of course. If you really need to be able to interrupt the flow to request clarification, I think you may need to look at dialog states rather than delegate.


#3

I was thinking if you could maybe add something like this to filter if all entities are set:

// This handler is used if all entities are filled successfully
@Handle({
  intents: [ 'ReservationIntent' ],
  if: (jovo) => jovo.$entities.numberOfPeople && jovo.$entities.time
})
confirmReservation() {
  // ...
}

// This handler is used to prompt for a missing entity
@Handle({
  intents: [ 'ReservationIntent' ],
  if: (jovo) => jovo.$entities.numberOfPeople === undefined
})
askForNumberOfPeople() {
  return this.$send('For how many people would you like to reserve a table?');
}

#4

Hey Jan,

Thank you - looks like a great solution to me.
Only thing i don’t quite understand is, after the askForNumberOfPeople() is called, how do i route back to confirmReservation() after the user tells us the amount of people?

Edit:

I looked up about the $state object in the docs and found a solution for it. Maybe there’s a cleaner way to this but i will extend the example above with my solution:

// This handler is used if all entities are filled successfully

@Handle({

intents: [ 'ReservationIntent' ],

if: (jovo) => jovo.$entities.numberOfPeople && jovo.$entities.time

})

confirmReservation() {

this.ConfirmReservationExtension(this.$entities.numberOfPeople.resolved, this.$entities.time.resolved)

}

// This handler is used to prompt for a missing entity

@Handle({

intents: [ 'ReservationIntent' ],

if: (jovo) => jovo.$entities.numberOfPeople === undefined

})

askForNumberOfPeople() {

this.$component.data.Time = this.$entities.time.resolved;

return this.$send('For how many people would you like to reserve a table?');

}

@Intents('NumberIntent')

ReceiveNumber(){

this.ConfirmReservationExtension(this.$entities.numberOfPeople.resolved, this.$state[this.$state.length - 1].data.Time);

}

ConfirmReservationExtension(people, name){

//Send reservation to your API ...

}

#5

This is an interesting way of validating entities @jan

Quick question:

I’m assuming this would be “outside” of START() { }, correct?

In that case, how can we make the code to ignore START() {} on that component and validate right away these conditions as the first thing we enter on that component?


#6

Usually, I would prompt for a value in START (e.g. “how many people?”) and then do the validation in a handler in the same component.


#7

I finally managed to add docs for this as well: https://github.com/jovotech/jovo-framework/pull/1255