1

I am brand new to Dialogflow CX and am having trouble figuring out how to use a date in a condition. I want to require that a birthdate be entered and be greater than 2000-01-01. I have tried

$intent.params.dob.resolved > 2005-01-01

with and without quotes, but it does not work (always false). I discovered that $intent.params.dob.original > "1/1/01" is resolved as True for all dates, so that is of no help.

Is there a way that works?

Mike Blyth
  • 4,158
  • 4
  • 30
  • 41

3 Answers3

1

To achieve your described use case, you can utilize the condition route or conditional response to return a response according to the condition. Here is a condition you may use:

$intent.params.birthdate.resolved.year > 2000 OR 
($intent.params.birthdate.resolved.year = 2000 AND 
$intent.params.birthdate.resolved.month > 1) OR 
($intent.params.birthdate.resolved.year = 2000 AND
$intent.params.birthdate.resolved.month = 1 AND
$intent.params.birthdate.resolved.day > 1)

Here are examples for your reference:

A. Using the condition in the Conditional Response Conditional Response

B. Using the condition as the Condition Route: Condition Route

Please note that the birthdate parameter isn’t a string parameter. It is composed of year, month, and day sub-parameters so it is appropriate to utilize them for your use case. Also, note that dates are in ISO-8601 format. For more information, you can refer to the System Entities documentation.

Here are the following results using the condition defined in the conditional response:

  1. When the user enters the same year but not January 1st 1
  2. When the user enters an invalid date 2
  3. When the user enters a previous date from 2000-01-01 3
  4. When the user enters a valid date and latest from 2000-01-01 4
Riel
  • 444
  • 2
  • 5
0

I guess $intent.params.dob.resolved returns a string, so you need to build a date object firstly, and then compare it with your date.

0

I encountered a similar problem a few weeks ago. Thing is, Dialogflow actually defaults to string parameters: this means that every value entered as a parameter will (by default) be a string, surrounded by "quotes". To operate comparisons between dates you'd want to compare integers/numbers, and I think the best way to do so is to take advantage of date system entities.

For example, the system entity

@sys.date

allows you to match a date inserted by the user. Then the best part is, in your condition, you can even manage the date by referencing sub-parts. Here is an example:

if $intent.params.dob.year <= 2005 AND $intent.params.dob.month <= 04:
    I'm sorry, you're too young to use this service!
endif

Also, on a side note, "intent parameters" actually become "session parameters" as soon as Dialogflow makes a step from the state in which the parameter was set to another page. This means that if you set the parameter dob when the user says "I was born on the thirteen of July, 2004" and then you go on to a new page, that parameter will only be accessible as $session.params.dob (and session parameters don't have a "resolved value", they are resolved by default).

So, to recap. Make sure you're using the system date entity. Make conditions for all the parts of the date you need to verify (year, month, day) and try to use your parameter as a session parameter.

I hope at least some of what I wrote can help you, happy bot-building!

fcagnola
  • 640
  • 7
  • 17