Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dialogflow: How to restrict an Action parameter to one of the allowed values

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?

like image 549
Souvik Basu Avatar asked Mar 07 '23 20:03

Souvik Basu


1 Answers

There are two things you need:

  1. fruit should be assigned to a Custom Entity type
  2. You will need a Fallback Intent (or a lower priority Intent) to handle input if there isn't a match.

Custom Entity

You'll create a custom entity by selecting the Entity menu item on the right and then Create Entity.

enter image description here

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.

enter image description here

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.)

enter image description here

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.

enter image description here

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.

enter image description here

like image 199
Prisoner Avatar answered May 14 '23 05:05

Prisoner