Deconstructing Chatbots: Build an Appointment Scheduler with Dialogflow
In the first blog we learnt what conversation experiences are, why they are important, covered NLU briefly, and how Dialogflow lets you get up and running really quickly. In second article, we described a simple high level architecture to set up an agent in Dialogflow and learned about intents, entities, context and fulfillment at a high level. Now, we are ready to start working with Dialogflow and create our first chatbot.
Wouldn’t it be awesome to have access to an appointment scheduler at a doctor’s office or DMV or a repair shop? In this article you will build a simple chatbot using Dialogflow and learn how to integrate it with web using one click integration.
The exercises are ordered to reflect a common cloud developer experience:
- Create a Dialogflow agent
- Create intent
- Test the chatbot
- Enable web integration
What you’ll learn
- How to create a Dialogflow Agent
- How to create intents within an Agent
- How to create training phrases within an intent
- How to create responses within an intent
- How to test Dialogflow agent
- How to set up the web integration
Basic concepts and constructs of Dialogflow. For introductory Dialogflow tutorial videos that covers basic conversational design check out the following videos:
Create a Dialogflow Agent
- Navigate to the Dialogflow Console.
- Sign-in, if you are a first time user, then use your email to sign up
- Accept the terms and conditions and you will be in the console
- Create an Agent. To create, click on the dropdown menu in the left pane in order to see “Create new agent”
- Call this “AppointmentScheduler”
- Dialogflow creates a GCP project for you to access logs, cloud functions etc. You can select an existing project as well.
- When you’re ready, click Create.
- Dialogflow creates two default intents as a part of the agent.
- Default Welcome intent helps greet your users
- Default Fallback intent helps catch all the questions that your bot does not understand.
- At this point, we have a functional bot that greets the users.
Test the Agent!
On the right hand side of the Dialgflow console, you can see the testing panel that looks like this:
To test the agent, in the “Try it now” box type “Hi”. The agent should respond back with the default greeting defined in the “Default Welcome Intent”. This could be “Greetings! How can I assist?” You can also modify the response.
Now, if you try “set an appointment” it does not know what to do so it initiates the fallback intent. This is because we have not created any intent to catch that particular question!
- To create the intent, click on “Intent” within the “Agent” and then click on the “CREATE INTENT” button on the right. Name the intent as “Schedule Appointment”
- For now, Skip over Contexts & Events at the top. Click on “Add Training phrases”.You can use the following phrases for this. Try them out individually.
Set an appointment on Wednesday at 2pm
Need an appointment for 4pm tomorrow
I would like to set an appointment for 3pm on Tuesday
- As you are putting these in, you will see ”date” and “time” are automatically identified as system entities @sys.date and @sys.time.
- To make this functional we need to respond back to the user. Let’s add a response. Scroll down to the “Response section and actually click on “Add Response”. You could just say — “You are all set. See you then!” or you could make it more interesting and say “you are all set for $date at $time. See you then!” Dollar($) sign here helps you access the entity values.
- At this point you can click “Save” and test the agent with “set an appointment for 4pm on Thursday.” and as expected, you get the response with the right date and time.
Now, try to test “set an appointment”, since that is not very specific and we have not currently handled that scenario, it should be handled by Fallback intent. To support this, we use something called Slot-filling.
Slot filling allows you to design a conversation flow for parameter value collection within a single intent.This is useful when an action can’t be completed without a specific set of parameter values. To learn more about slot-filling refer to this documentation.
Next, let’s set up Slot-filling.
- Click on “Actions and Parameters”.
- Make the entities as required and Dialogflow will make sure to ask for both date and time before it responds back.
- For time add “what time would you like to come in”
- For the date add “what date”. You can add other variants too.
- When you’re finished, click Save.
Test Your Chatbot!
At this point, the Dialogflow should be set up. Test it in the Try it now panel on the right by entering the following conversation:
- User: “Hi”
- User: “Set an appointment”
- Chatbot response: “What time would you like to come in?”
- User: “10am”
- Chatbot response: “What date?”
- User: “May 23”
Enable One-Click Web Integration
Dialogflow provides many types of integration for your chatbot. Let’s take a look at a sample web user interface for the chatbot.
Click on Integrations in the Dialogflow left panel.
Enable the Web Demo integration by flipping the switch
Click on the URL link to launch Web Demo
Start using the chat interface by typing in the Ask something… section! If you are using a Chrome browser, if you click the microphone icon and you can speak your questions to the chatbot. Start chatting with the chatbot using the following conversation:
- Type “Hi” and hit Enter. The chatbot should respond as before.
- Then enter/say “set an appointment for 4pm tomorrow”. The bot should respond back with the confirmation of the appointment.
You built a chatbot, and you’re now a chatbot developer! Keep reading for more tutorials like this here on medium or on GCP youtube series.