Say I create an intent AskForFruit
in Dialogflow where the user says:
I want an apple
here apple gets assigned to a param fruit
I want to restrict the value of fruit
to 'apple', 'orange' and 'banana' only
If the user says 'peach' the agent will respond with 'Please select between apple, orange and banana'
How do I restrict the value of fruit
to these 3 fruits only?
There are two things you need:
fruit
should be assigned to a Custom Entity typeCustom Entity
You'll create a custom entity by selecting the Entity
menu item on the right and then Create Entity.
You'll enter in the possible values this Entity can take on. You can also add aliases for some of the entities if you want.
When you go to create your Intent, you want to make sure the entered phrase has a word highlighted and the Entity Type correctly selected for that word. (And, as @Ido notes in the comments, you probably want to say the parameter is required.)
Fallback Intent
That handles the case when the user says one of the valid fruits. But what about invalid fruits? How you handle this depends on what other things you're talking about.
The easiest solution is to create a Fallback Intent, which is an intent of last resort if nothing else matches. If you're using contexts, you can create a fallback intent for a particular context, and this is a great way to keep track of where you are in a conversation.
In either case, you'd edit your responses to tell them what valid fruits they can pick.
If, however, you want to very specifically respond if they ask for something you don't want, you can create a lower priority intent that will match if there isn't a better match. This is useful if you have a lot of conversation parts and aren't using contexts (but you should use contexts) or want to reserve your Fallback Intent for a more general message.
You change the priority of an intent by clicking on the dot next to the intent name.
So, for example, if you have an AskForSomethingElse
intent that would match the more general @sys.any type, you could have it respond with the valid types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With