Create an intent with parameters

We now need an intent that can schedule an appointment for the bike shop. Unlike the first intent Hours, which only returns the static response "We're open from 9 AM to 6 PM every day. Is there anything else I can do for you?", the new intent must be able to perform a more complex set of tasks.

Let's examine the following interaction between the user and the agent:

      User: Hi.

      Agent: Welcome. I can tell you the shop hours, or I can set up an appointment. Which would you like?

      User: I need to make an appointment at 3 PM today.

      Agent: Got it. I have your appointment scheduled on Wednesday, August 1 at 3 PM. See you soon. Good-bye.

In the dialog above, the user utterance "I need to make an appointment at 3 PM today" contains important information, "3 PM" and "today", that indicates what time and date the user wants to visit the bike shop. The agent's response includes the time and date information mentioned in the user utterance: "Got it. I have your appointment scheduled on Wednesday, August 1 at 3 PM. See you soon. Good-bye."

For us, identifying important pieces of information from utterances is simple; for machines, however, it is a complex task. We need to give intents the ability to extract important information, parameters, from user utterances.

Extract information using entities and parameters

Dialogflow uses concepts known as entities and parameters to extract targeted information from user utterances and convert it to a set of parameters, which then can be processed by other functions or systems to perform various tasks.

To create a new intent with parameters, follow these steps:

  1. Create an intent named Make Appointment.
  2. In the Training phrases section, add the following training phrase:

    I need to make an appointment at 3 PM today.

  3. In the Action and parameters table, verify that the system entities @sys.date and @sys.time have appeared.

  4. In the Text response table, add the following response phrase:

    Got it. I have your appointment scheduled on $date at $time. See you soon. Good-bye.

  5. Click SAVE.

    Figure 5. Flowchart showing the addition of the Make Appointment intent.

With this setup, the intent Make Appointment examines user utterances, captures any words that are mapped to Dialogflow's built-in system entities @sys.date and @sys.time, and puts those captured values into the parameters $date and $time. Therefore, in the response, we can use $date and $time to refer to the date and time values captured from user utterances: "Got it. I have your appointment scheduled on $date at $time. See you soon. Good-bye."

Dialogflow also allows you to create customized entities for extracting parameters that are uncommon or uncategorized. However, in our scenario, using system entities is sufficient for capturing typical parameters such as time and date. If you'd like to learn more about entities, check out Entities.

Obtain required parameters using slot-filling

Following the best practice from the previous section, we now need to provide more training phrases in addition to the current training phrase, "I need to make an appointment at 3 PM today."

Add the following training phrases:

  • Can I schedule service for 4 PM tomorrow?
  • Can I set up an appointment for noon on Friday?

So far, all of the training phrases contain the time and date information: "3 PM today," "4 PM tomorrow," and "noon on Friday." However, in the real world, user utterances may not always include all the necessary parameters. Add the following training phrases:

  • Can you fix my road bike?
  • My bike is broken.
  • I'd like to get my bike fixed, I have a mountain bike that needs servicing.
  • I need to fix my bike today.
  • I'd like to schedule an appointment on this Thursday.

All the phrases above indicate that the user wants to schedule an appointment; thus, our new intent should be matched with such phrases to handle the task of scheduling an appointment. However, each of these phrases lacks the time information, the date information, or both. Phrases like these are troublesome because the intent cannot schedule an appointment without the time and date information.

Dialogflow provides a feature called slot-filling that ensures an intent obtains all the necessary information from a user. To activate this feature, we need to mark the parameters as required.

When an intent has required parameters, but it is matched with a user utterance that lacks any of the required parameters, the intent asks prompt questions in order to retrieve all the required parameters from the user. Let's take a look at the following dialog:

      User: Hi.

      Agent: Welcome. I can tell you the shop hours, or I can set up an appointment. Which would you like?

      User: I need to fix my bike.

      Agent: Okay, I can help you with that. What day do you want to come in?

      User: Today.

      Agent: And what time works for you?

      User: 3 PM.

      Agent: Got it. I have your appointment scheduled on Wednesday, August 1 at 3 PM. See you soon. Good-bye.

To make the parameters $time and $date required and provide prompt questions for the parameters, follow these steps:

  1. Click on the Make Appointment intent.
  2. In the Action and parameters table, check the REQUIREDboxes for the parameters $time and $date. A column called PROMPTS is created.
  3. If the $date parameter is located underneath the $time parameter in the table, drag up the row of the $date parameter above the $time parameter. (The placement in the table determines the order in which the prompt questions are asked.)
  4. For the $date parameter, click the link Define prompts under the PROMPTS column and add the following prompts:
    • Okay, I can help you with that. What day do you want to come in?
    • Sure, what day are you coming in?
    • Okay, what day will work for you?
  5. For the $time parameter, click the link Define prompts and add the following prompts:
    • And what time works for you?
    • What time?
    • Now, what time do you want the appointment?
  6. Click SAVE.
  7. Test the slot-filling setup using the simulator in the Dialogflow console.

    Figure 6. Flowchart showing the slot-filling prompts for required parameters.

We now have an intent that makes sure to obtain the date and time information once a user indicates the need for making an appointment. However, at the moment, the intent only replies with a mock-up response; no actual appointment is scheduled. We need to create a backend process, fulfillment, that can perform the task of scheduling an appointment on Google Calendar.

We'll explore how to create fulfillment for the intent Make Appointment in the next section.