First published: Sep 2017 | Last updated: May 2022
A reader recently asked:
How do we create a script that will ask for a date of birth?
My immediate thought was, “Oh, that’s easy. You just ask for the date and use the built-in system entity etc”. And quite stupidly, I also acted on that thought and sent the email out. 🙁
But that doesn’t work
It is more nuanced than that. Of course!
Turns out, because Dialogflow ES is so flexible in the way it parses dates, if the user were to respond to that question with just the month and the day it automatically assumes the current year. Now, at the rate at which kids are adopting technology, it is possible that a kid born this year actually used the bot.
But let us suppose that didn’t happen. 🙂
Full vs partial birthdate
Apparently, when someone wants to make an appointment with a doctor, they can uniquely identify the patient if they have their birthdate (including the year) and the patient’s last name. Let us suppose it is true. So we would like to get the user’s birthdate.
This article is based on a thread which does have the answer.
There is just this vague mention of incomplete dates, but the link didn’t seem to be going anywhere. But I spent a little time on that page linked out and found the following section:
(Hope they don’t change that URL in their next docs update!)
Extracting the correct value
Now, when you capture the date using the @sys.date, you will use the $date.partial value as shown below.
Two types of user input
Now, the $date.partial can handle both the incomplete as well as the complete date input. When user inputs partial date, this is what the output looks like:
The year simply contains UUUU – so you know the user didn’t fill in the year and you can prompt the user to do so (from your webhook).
On the other hand, if the user did add the year, it is correctly identified:
Create an intent called book.appointment with the following details
Create another intent called provides.birthdate and add the following information
Here is a side by side comparison of what happens depending on whether the user provided a full birthdate or only a partial birthdate. As you can see from the simulator output, when the user does not provide a year, Dialogflow uses the current year. However, if you see the value in the parameter table, you do see the UUUU prefix. So we can use this knowledge to get the full birthdate.
<— End of article —>
This website contains affiliate links. See the disclosure page for more details.
"The magic key I needed as a non-programmer" The custom payload generator was the magic key I needed (as a non-programmer) to build a good demo with rich responses in DialogFlow Messenger. I've only used it for 30 minutes and am thrilled. I've spent hours trying to figure out some of the intricacies of DialogFlow on my own. Over and over, I kept coming back to Aravind's tutorials available on-line. I trust the other functionalities I learn to use in the app will save me additional time and heartburn. - Kathleen R Cofounder, gathrHealth
"Much clearer than the official documentation to be honest" Thanks a lot for the advice (of buying and following your videos)! They helped a lot indeed. Everything is very clear when you explain, much clearer than the official documentation to be honest 🙂 Neuraz T Review for Learn Dialogflow CX
"I will strongly recommend this course because even I can learn how to design chatbot (no programming background)" I think Aravind really did a great job to introduce dialogflow to people like me, without programming background. He organizes his course in very clear manner since I have been a college professor for 20 years. It is very easy for me to recognize how great Aravind’s course is! Very use-friend and very easy to follow. He doesn’t have any strong accent when he gives the lectures. It is so easy for me to understand. Really appreciate it. Yes, I will strongly recommend this course because even I can learn how to design chatbot (no programming background) after studying Avarind’s course, you definitely can! Ann Cai Review for Learn Dialogflow ES