DialogFlow : Using Original Value Associated with Parameter
Dialogflow has capability of converting the strings to required entities, and it’s quite powerful as well. It can extract entities from the user queries which we can use to complete the task.
We can see in the image above, that Dialogflow is able to recognize that today is date and london is a city.
We will be getting value of date, depending what user have asked, as part of Dialogflow raw API response.
We get this value in parameters, tomorrow is converted to actual date.
We can also use this in our response using $parameter_name
We can see that Dialogflow is intelligent enough to convert tomorrow into an actual date object, and showing human understandable date format in it’s response.
But sometimes, there might be a requirement where we want to use the actual phrase said by the user in our response, or for some processing.
How do we get that?
Well, there is no direct way to do this. But we can make use of contexts to get it done.
We will have to set an output-context in our intent. By doing so, we will get an extra value in our raw API response like below:
We can use it in the response using #context_name.parameter_name.original. Or we can use use it in our webhook for some processing, if required, as well.
In our example, context_name is book-flight and parameter_name is departure_date. So we will be using #book-flight.departure_date.original in our response. This way, response will be more human like.
Here is the question asked on stackoverflow from which this article is inspired : https://stackoverflow.com/questions/54678897/dialogflow-get-original-string-associated-with-parameter
Original article is posted on Medium : https://medium.com/@sid8491/dialogflow-using-original-value-associated-with-parameter-10c97b510982
Thanks for reading!