Capturing date ranges with Dialogflow and storing them in Manychat

Josh Barkin
Being Janis
Published in
6 min readJan 21, 2020

--

One of the benefits of a Dialogflow-enhanced Manychat bot is that you can use Dialogflow to understand the messages your users send, extract data from those messages, and automatically store those values in custom user fields in Manychat.

One of the great features of Dialogflow and its approach to natural language processing is that you only need to capture one message and data in that message can be variable. Instead of having to define every possible variable value yourself, the values are automatically determined by Dialogflow. Numbers are a prime example of this. Let’s say a user says in response to a quantity related question from your chatbot:

I’d like 4 please

You can add @sys.number to the number in your phrase. This is Dialogflow’s built-in entity for numbers.

If the user had said 1, 4, 400, or 40,000, Dialogflow will know it’s a number and store the number in a Parameter and if your Custom User Field name (number type field) matches your parameter name (in this case a custom user field named “number”), then the value Dialogflow extracts from the message will be automatically stored in your matching Custom User Field in Manychat.

Ranges

We just covered a very basic example of how values get extracted from your messages with Dialogflow and stored in Manychat.

Manychat, however, doesn’t have the capability of extracting multiple values from a single parameter. When you have ranges of data in a user’s message, you’re going to get two values from the user, and you’ll want to store those values separate in separate Custom User Fields.

Let’s look at an example. Let’s say your goal is to book a user for an appointment and you want to capture a range of time the user is available.

Your bot might ask the user:

Is there a time that works best for you?

and if the user doesn’t have a specific time in mind, or if a particular time is unavailable on your calendar, they might reply with a range of time that works for them:

Anytime between 8pm and 11pm

You’re going to want to extract a start time and end time from that message.

Using Dialogflow

In Dialogflow you’ll want to capture a range of time, so you might add a phrase that represents something the user says to indicate a range of time.

Dialogflow will automatically recognize your input as a time period, and automatically add the @sys.time-period entity to your phrase. You can see that Dialogflow automatically creates a time-period parameter where the value will get stored in Dialogflow.

If you test your message in the Dialogflow console, you’ll see how Dialogflow will output the data:

See how the parameter value includes both endTime and startTime those are two separate things. Dialogflow will only create one parameter though when you add the phrase. This is what is referred to as a Composite Entity. It’s an Entity that combines other entities. In this case startTime and endTime are entities and they are combined to create the @time-period entity.

Using Manychat

In Manychat, you would create two custom user fields. One for the startTime and one for the endTime. In your Custom User Fields (in Settings for your bot), create a new user field named time-period.startTime and set the field type to Date & Time.

Now do the same for the end time. Create a new user field named time-period.endTime and set the field type to Date & Time.

You can see that you have the both the parameter name time-period, then a "." and the other entity which is one part of the time-period.

With two separate custom user fields set up this way, this will tell Janis to extract the startTime and the endTime from the time-period parameter and store the values separately into custom user fields. Since Janis is also able to translate the Dialogflow values it gets back from Dialogflow for time and date, then Janis will save them for you in Manychat’s preferred data format so you can then work with these values in the way Manychat expects!

It may not look pretty, but the data you store is “machine readable”. It’s in a format that is universally understood by computer systems. So you can convert the time into a prettier format with Manychat, or by connecting some other third party application that can convert time and date data into a format you want. At the very least, Janis makes sure that the time and date values it gets from Dialogflow are saved into a format that Manychat can work with and you can take it from there.

Another example is the travel niche. Let’s say a travel bot asks a user:

When did you want to book a flight?

…and a user, using natural language, might reply:

January 25 to Feb 1.

You’ll want to capture a start date and end date from that single message and store the values individually in custom user fields so you can create conditional responses based on a date range, or simply have a live travel agent follow up and have the user’s preferred travel dates easily accessible in a customer profile.

The above examples work well for Dialogflow’s @time-period and @date-period Entities because these Entities capture ranges of data. Test it out in the Dialogflow console to get the entities associated with the main Entity @date-period , or time-period

How you can create your own combined Entities with Dialogflow.

While I just showed you how to use Dialogflow’s build-in Entities to extract more than one value from a single entity, because certain Entities combine other Entities (i.e. a start and end period) you can also create your own entities that combine other entities, and then extract individual values into Custom User Fields.

In this example, let’s say my bot asks the user:

What would you like to order?

and the user replies:

I’d like 3 hamburgers and 2 pizzas please

You can extract the order from that single message and store the individual items and their quantities in separate custom user fields.

First, you can see that I created a custom entity in Dialogflow called full-order-info . I’ve added the @number Entity (Dialogflow’s built-in Entity for understanding a number) and @menu Entity (a custom Entity we created that has a list of items on a restaurant menu like hamburgers, and pizza).

Now create a training phrase and Dialogflow might automatically add your full-rder-info entity, or you could manually select it from the from the phrase and assign it the Entity (You can remove Entities that get automatically added by clicking the little trash can when the Entity menu pops up).

Select the part of the phrase that to trigger your Entity.

Create two Custom User Fields in Manychat. Create one user field called full-order-info.food and another user field for full-order-info.number and you’ll be able to access the individual values.

You’ll be able to store the individual values for the user’s order from a single message and can then use those values to process the user’s order through Manychat.

Before you go…

🤖 Need an easy way to connect Dialogflow to Manychat?

👉 https://www.janis.ai

🤖 Training Dialogflow NLP takes time. Need a Dialogflow template?

👉 https://janis.ai/dialogflow-templates/

🤖 Learn more how to build chatbots with Manychat and Dialogflow

👉 https://janis.ai/manychat

--

--

Josh Barkin
Being Janis

Building conversational AI platforms since 2016