Reputation: 35
In some intents in dialogflow I want to evaluate some parameters (that are required) and then, if they do not meet some criteria, request them again. More specifically, I ask the user a date an event happened and in case he just provides me with e.g. "june" the @sys.date-period entity that's associated with the parameter translates this to "01/06/2019 to 30/6/2019", a date that has not been past yet and cannot be accepted. Therefore I want to check if the date is valid, and if not, ask the user again to provide it (erase the previous parameter and "reprompt").
The date can have many forms, month, year, period defined by start and end dates, so the automatic entities of google are really helpful. At the beginning I tried to create my own entities (like months, seasons), but because this procedure must be implemented for multiple different intents in the project, I do not want to end up with 100+ intents solely for the date retrieval. For the same reason, I want to do this through my webhook and not through intents that can be triggered if the date is not valid etc. So I want to say to the user "You date is invalid, please retry." and then wait for a date, which will be evaluated and depending on the result of the evaluation, the procedure will either proceed or ask again for a valid parameter.
I read about this and I didn't find anything to indicate that this can be done (if anyone knows a way, please share it with me). So now I am trying to trigger an event(eventToTrigger), that I entered in this intent (that needs the date), but without success.
var bool1=isDateInValid(startDate);
var bool2=isDateInValid(endDate);
if (bool1 && bool2) {
agent.add("This date is invalid: "+startDate+ " to "+endDate+". Please retry");
return {
"followupEventInput": {
"name": "eventToTrigger"
}
};
}
It prints "This date is invalid: 2019-06-01 to 2019-06-30. Please retry", which was expected, but nothing else. Apart from the above message, I wanted to also ask the user "give me a period", which is the response of the bot when entered in the specific intent without the user having provided a date, which is required as I said above. How can I do this? Thanks in advance!
Edit:
I implemented the advice @sid8491 gave me. I made an intent with input context wrongDate and I added to my fulfillment code the following:
if (bool1 && bool2) {
agent.add("This date is invalid: "+startDate+ " to "+endDate+". Please retry");
const context=agent.session+"/contexts/wrongDate";
console.log("Follow up intent with context: "+context);
return {
"outputContexts": [
{
"name": context,
"lifespanCount": 1
}
]
};
}
I also related this new intent with the same function through intentMap. When I give (as a user) an invalid date (e.g. "may") the bot responds "This date is invalid: 2019-05-01 to 2019-05-31. Please retry". After that I type "may" or "may 2018" and the bot enters the fallback intent, as if I did not send the output context (which is similar to my problem with the event, I could not be sure if the message was just ignored or if I did not send it in a correct form/way).
Upvotes: 1
Views: 699
Reputation: 6800
In your condition when the date is wrong, instead of invoking an event you can simply return a message with the error prompt along with an extra context.
Here's what you need to do:
This
date is invalid: "+startDate+ " to "+endDate+". Please retry
wrong-date
Make
one more intent which will handle date input, and set input-context
to wrong-date
#output-context.parameter_name
(replace output-context with
wrong-date and parameter_name with your exact name of parameter) Hope it helps.
Upvotes: 2