Search code examples
node.jsdialogflow-esfulfillment

Dialogflow - Dealing with user discrepancy when coding fulfilment


When coding fulfilment for Dialogflow (API.AI) is there a way to deal with discrepancies in user responses without having to do a full if statement for all the possible ways a user could say the same thing? A.K.A the manual way.

For example, if I'm asking where the user located and they say they're from the West Midlands, which is one of my locations - do I have to do an IF statement that looks something like this:

if (location === 'West Midlands' || 'west Midlands' || 'w midlands' || 'w mid') {}

Or can I pass it back to Dialogflow where it can handle the users input using the AI or whatever.


Solution

  • You can create an Entity that represents the locations you support.

    Each of the possibly values in your Entity can have a canonical value and then the aliases that the user can enter that will map to this canonical value. When the parameter is sent to your fulfillment, the canonical value will be sent. (If you needed exactly what they entered, it is available as well, but you should use the canonical value for your tests.)