Parameter(s) validation on Dialogflow
Trust me, if you are dealing with parameter validation on Dialogflow, then use the Contexts with multiple Intents.
Greek mode alert
If you are not familiar with Intent, Entity, Event, Fulfillment and Slot-filling, then you can find them here.
Basic parameters validation
Entity can help you on that, but what if not support entity or more complex condition? You can not use entity anymore.
Well, if you are planing to use Slot-filling, rethink about it. Because Slot-filling is only design to ask only missing required parameters not validate parameters. And when Slot-filling is working Dialogflow will generate controlled Contexts automatically. You are not allow to manage them.
Expert parameters validation
For not support entity and complex condition problem, you can use Contexts and multiple Intents.
For example, I need to validate my users age is only between 20–50 years old and their location is not too far.
- Create an intent to display age question {{ Prompt Age Intent }}
- Set output context for {{ Prompt Age Intent }} with [[ age-context ]]
- Create an intent for keeping user’s age {{ Got Age Intent }}. Do not forget to enable Fulfillment and config the (( age )) parameter, I recommended entity @sys.age if your agent support, if not support, then @sys.number is OK.
- Set input context of {{ Got Age Intent }} to be the same as output context of {{ Prompt Age Intent }},
- This is very important. Do not set output context for {{ Got Age Intent }}, because we will going to do this in the {{ Got Age Intent }} Fulfillment.
- Put the age validation logic in the {{ Got Age Intent }} Fulfillment.
- If validation pass then response something to tell user that age is OK and ask for the location. Then set the output context to [[ location-context ]] which is match to the next intent {{ Got location Intent }}.
- If validation not pass then response something to tell user that age is not OK and ask for re-input age. Then set the output context to [[ age-context ]] but set life span to 1.
For location validation or if you want to validate more parameters, you can repeat step 3–6.
Noted:
- {{ … }} is intent
- [[ … ]] is context
- (( … )) is parameter
Also, you can put some trick to this technique. For example if you are not allow user input wrong condition more than 3 times. You can add counter to the context.
In conclusion, to validate not support entity or complex parameters, you will need Contexts with multiple Intents.
Why Dialogflow still not support validation on slot-filling yet?
Thank you,