13 How to get a user’s birthdate in DialogFlow ES

Dialogflow ES Quickstart Templates Part 2

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.

Introducing $date.partial

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:

Intent definitions

Create an intent called book.appointment with the following details

Create another intent called provides.birthdate and add the following information

Demo

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.


About this website

I created this website to provide training and tools for non-programmers who are building Dialogflow chatbots.

I have now changed my focus to Vertex AI Search, which I think is a natural evolution from chatbots.

Note

BotFlo was previously called MiningBusinessData. That is why you see that watermark in many of my previous videos.

Leave a Reply