1
votes

Let say I have 2 basic intents i.e Set Appointment and Cancel Appointment.

Each of the intents has its own follow up questions and so on. When the user is in the follow up chain for the intent, Set Appointment, I want to prevent the user from hopping to another intent if he/she says "cancel appointment for abc"

Since both intents have empty input contexts so they can be called from the Google Assistant's invocation i.e Tell XYZ App to set appointment for...., it seems that this allows the user to be able to hop between intent mid conversation.

How do I limit this behavior? Or is there some kind design best practices here?

1

1 Answers

0
votes

First of all, remember that Intents represent what the user says, not what you're doing with that the user says.

Second, remember that users can change the course of the conversation at any time. So it makes sense that if they start adding an appointment, that they might want to cancel that appointment.

The best approach is that, if they try to cancel in the middle of making an appointment, you decide how you want to handle this change in conversation. And then just reply that way. You may choose to change tracks. Or you may choose to say something like "let's add this new appointment first, and then we can cancel the old one". With this scheme:

  • You have one Intent that matches "set the appointment for 10am"
  • In your handler:
    • If you aren't taking any action, you'd start prompting them for additional appointment setting info, or whatever.
    • If you are already setting an appointment, prompt them if they want to change the time to 10am
    • If you're cancelling an appointment, tell them that you'll talk about canceling the old one when you're done with the new one.

I tend to go with this approach in most (tho not all) cases. It lets me code the logic and lets me determine the best way to reply based on the entire state.

Another approach that you can use is to create an Intent with the Input Context that matches your current contextual line of questioning that matches the phrases from the Intent you don't want to match. (This might even be reasonable as part of a negative training phrase for a context-specific Fallback Intent.) Context matches are handled before context-free matches. So under this scheme you would have:

  • An Intent, without input context, that matches "set the appointment for 10am". The handler for this Intent would set the "set" context and start prompting for additional info.
  • An Intent, with your "set" input context, that matches "set the appointment for 10am". This could do something like re-start the prompting, or just change the time they're requesting.
  • An Intent, with your "cancel" input context, that matches "set the appointment for 10am". This handler would let them know that you'll ask about cancelling older appointments at the end.

Which method you use depends on how you're handling other state management in your code.