Fulfillment: How to Integrate Dialogflow with Google Calendar

Google Cloud Tech
21 Jun 201905:49

Summary

TLDRIn this episode of 'Deconstructing Chatbots', Priyanka Vergadia guides viewers on integrating Dialogflow agents with backend systems like databases or CRMs using fulfillment. The tutorial covers enabling the Google Calendar API, setting up a service account, and creating a calendar. It then demonstrates how to implement fulfillment in Dialogflow for scheduling appointments, including handling calendar conflicts, by connecting the Dialogflow agent to Google Calendar through a Cloud Function.

Takeaways

  • 📕 Deconstructing Chatbots is a series hosted by Priyanka Vergadia focusing on chatbot development.
  • 💵 Dialogflow agents require back-end integration, such as with databases or calendars, to transfer information using business logic.
  • 💵 Fulfillment in Dialogflow is a code piece deployed as a webhook that connects the agent to business logic on a per-intent basis.
  • 💵 For dynamic responses and back-end actions, Dialogflow's NLP-extracted information is used during conversations.
  • 💵 The example in the episode is an appointment scheduler chatbot that needs to integrate with a calendar for real-world functionality.
  • 💵 To integrate with Google Calendar, the Google Calendar API must be enabled in the Google Cloud Project.
  • 💵 A service account key is created and a JSON file is downloaded, which is used for authentication in the fulfillment.
  • 💵 The calendar ID from Google Calendar is required and should be replaced in the index.js file for the fulfillment to work.
  • 💵 The fulfillment code includes functions for making appointments and handling calendar events, checking for conflicts.
  • 💵 After setting up the fulfillment and enabling the webhook in the Schedule Appointment intent, the chatbot can be tested for functionality.
  • 💵 The chatbot can now handle appointment scheduling, checking for availability, and providing appropriate responses based on the calendar's status.

Q & A

  • What is the purpose of fulfillment in Dialogflow?

    -Fulfillment in Dialogflow is a piece of code deployed as a webhook that allows a Dialogflow agent to call business logic on a per intent basis, enabling dynamic responses or actions on the backend.

  • How does Dialogflow's natural language processing contribute to generating responses?

    -Dialogflow's natural language processing extracts information which can then be used to generate dynamic responses or trigger actions on the backend during a conversation.

  • What is the role of the Google Calendar API in integrating Dialogflow with a calendar system?

    -The Google Calendar API is used to enable the Dialogflow agent to interact with Google Calendar, allowing it to check for scheduling conflicts and set up appointments.

  • How do you enable the Google Calendar API for a Google Cloud Project?

    -You navigate to APIs & Services in the Google Cloud Platform console, find Google Calendar API, and enable it for your cloud project.

  • What is a service account key in the context of Google Cloud Platform?

    -A service account key is a credential that allows a service account to authenticate and act on behalf of your Dialogflow agent when interacting with Google Cloud services.

  • Why is it necessary to create a new calendar in Google Calendar?

    -Creating a new calendar is necessary to have a dedicated space for the appointments scheduled by the Dialogflow agent, ensuring they are separate from personal or other events.

  • How do you grant the Dialogflow agent permission to manage events in the Google Calendar?

    -You grant permission by adding the client email from the service account key to the new calendar and setting the permission to 'Make changes to events'.

  • What is the purpose of the 'package.json' and 'index.js' files in setting up fulfillment?

    -The 'package.json' file lists the project dependencies, while 'index.js' contains the code that handles the fulfillment logic, including creating calendar events and checking for conflicts.

  • How do you deploy the fulfillment code in Dialogflow?

    -After setting up the code in 'index.js' and defining the dependencies in 'package.json', you deploy the fulfillment by clicking 'Deploy' at the bottom of the fulfillment page in Dialogflow.

  • What does enabling the webhook in the Dialogflow intent do?

    -Enabling the webhook in the Dialogflow intent allows the agent to call the fulfillment function when that intent is triggered, thus connecting the user's request to the backend logic.

  • How can you test if the Dialogflow agent is correctly integrated with Google Calendar?

    -You can test the integration by querying the Dialogflow agent to schedule an appointment and checking if the appointment is added to the calendar and if conflicts are handled correctly.

Outlines

00:00

🤖 Integrating Dialogflow with Backend Systems

In this segment, host Priyanka Vergadia introduces viewers to the process of integrating a Dialogflow agent with backend systems such as databases, calendars, or CRMs. The concept of fulfillment is explained as a piece of code deployed as a webhook, allowing the Dialogflow agent to call business logic on a per-intent basis. The example of an appointment scheduler chatbot is used to demonstrate how to implement fulfillment for scheduling appointments. The process includes setting up the agent to identify the user's intent, providing a static response, and integrating with a calendar to check for scheduling conflicts. Detailed steps are provided for setting up the Google Calendar API, creating service account keys, and configuring permissions for the calendar. The segment concludes with instructions on deploying the fulfillment code and testing the chatbot's ability to schedule appointments and handle conflicts.

05:00

🔑 Summary of Dialogflow and Google Calendar Integration

This paragraph summarizes the key learnings from the video. The main points include enhancing the appointment scheduler chatbot by creating a fulfillment through the inline editor in Dialogflow, enabling the Google Calendar API for the Google Cloud Platform (GCP) project, and using the API credentials to connect the fulfillment Cloud Function with Google Calendar. The summary also mentions the testing of the agent to confirm its ability to create appointments on the calendar and handle scheduling conflicts. The host encourages viewers to watch the next episode for more insights into conversational AI and invites them to like and subscribe to the channel for similar content.

Mindmap

Keywords

💡Dialogflow

Dialogflow is a Google-owned natural language understanding platform that allows developers to design and integrate conversational interfaces into mobile apps, web applications, devices, bots, and more. In the video, Dialogflow is used to create a chatbot that can interact with users and understand their intent to schedule appointments.

💡Fulfillment

Fulfillment in Dialogflow refers to a piece of code that is deployed as a webhook, allowing the Dialogflow agent to call the business logic on a per-intent basis. It is crucial for integrating a chatbot with backend systems. In the script, fulfillment is set up to enable the chatbot to interact with Google Calendar and schedule appointments.

💡Backend

A backend system refers to the server, database, or application that powers a website or application. In the context of the video, the backend system is Google Calendar, which the Dialogflow agent needs to connect to in order to schedule appointments.

💡Google Cloud Project ID

Google Cloud Project ID is a unique identifier for a project in Google Cloud Platform (GCP). It is used to manage APIs, services, and resources. In the video, the Project ID is used to enable the Google Calendar API for the Dialogflow agent.

💡APIs and Services

APIs (Application Programming Interfaces) and Services refer to the protocols and tools for building software applications. In the video, APIs and Services in GCP are used to enable the Google Calendar API, which is necessary for the Dialogflow agent to access and modify calendar events.

💡Service Account Key

A Service Account Key in GCP is a credential that allows a service account to make API calls. In the video, a service account key is created and used to grant the Dialogflow agent access to the Google Calendar API.

💡JSON

JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write and for machines to parse and generate. In the script, a JSON file is downloaded which contains the service account key, and this file is used to authenticate the Dialogflow agent with the Google Calendar API.

💡Calendar ID

A Calendar ID is a unique identifier for a calendar in Google Calendar. In the video, the Calendar ID is used in the fulfillment code to specify which Google Calendar the Dialogflow agent should interact with when scheduling appointments.

💡Inline Editor

The Inline Editor in Dialogflow is a feature that allows developers to write and deploy fulfillment code directly within the Dialogflow console. It is used in the video to set up the fulfillment for the appointment scheduler chatbot.

💡Webhook

A Webhook is a method of augmenting or altering the behavior of a web page, or web application, with custom callbacks. In Dialogflow, enabling a webhook allows the agent to send and receive data to and from the fulfillment service during a conversation.

💡Intent

In Dialogflow, an Intent is a purpose or goal expressed by a user. It is used to match user input to the agent's actions. In the video, the 'Schedule Appointment' intent is used to trigger the fulfillment code that interacts with Google Calendar to schedule appointments.

Highlights

Introduction to integrating Dialogflow agents with backend systems like databases, calendars, or CRMs.

Explanation of fulfillment as a piece of code deployed as a webhook.

Fulfillment allows Dialogflow agents to call business logic on a per intent basis.

Demonstration of using Dialogflow's natural language processing to generate dynamic responses.

Guide on setting up an appointment scheduler chatbot with fulfillment.

Instructions on enabling Google Calendar API for a Google Cloud Project.

Process of creating a service account key for the Google Calendar API.

Details on sharing a Google Calendar with a service account.

Setting up fulfillment in the Dialogflow console.

How to use the inline editor in Dialogflow for fulfillment.

Importance of copying dependencies from package.json to fulfillment.

Guide on replacing the Calendar ID in the index.js file.

Explanation of the 'Make appointment' function's role in user responses.

Details on the 'create calendar event' function handling entities and creating calendar invites.

Instructions on deploying the fulfillment in Dialogflow.

Enabling webhook in the Schedule Appointment intent for testing.

Testing the Dialogflow agent with appointment requests.

Demonstration of how the agent handles scheduling conflicts.

Summary of enhancing the appointment scheduler chatbot with fulfillment.

Encouragement to watch the next episode for more on conversational AI.

Transcripts

play00:00

PRIYANKA VERGADIA: Welcome to Deconstructing Chatbots.

play00:02

I'm Priyanka Vergadia.

play00:03

And in this episode, we will learn

play00:05

how to integrate a Dialogflow agent with a back end

play00:08

system like a database, calendar, or a CRM.

play00:11

[MUSIC PLAYING]

play00:19

Any chatbot you build will need to connect to a back end

play00:22

to transfer information to and from the business logic.

play00:26

Within Dialogflow, we are able to make that connection using

play00:29

fulfillment.

play00:31

Fulfillment is a piece of code which is deployed as a web hook

play00:34

and lets your Dialogflow agent call the business

play00:37

logic on a per intent basis.

play00:40

During a conversation, this allows

play00:43

you to use the information extracted from Dialogflow's

play00:47

natural language processing to generate a dynamic response

play00:51

or to trigger action on your back end.

play00:54

Let's take our appointment scheduler chatbot

play00:57

from previous episodes and implement a fulfillment

play00:59

for scheduling appointments.

play01:02

Well, currently, our agent identifies the user's intent

play01:05

of scheduling an appointment and provides

play01:07

a static response indicating that the appointment is set up.

play01:11

Now, in a real world scenario, we

play01:13

need to set up that appointment on a calendar

play01:16

and also check for any scheduling conflicts, which

play01:19

requires us to integrate with the calendar.

play01:22

So let's jump into our Dialogflow console

play01:24

and see how it is all set up.

play01:26

Click on the gear icon near your agent name to open Settings.

play01:31

Look at the Google Cloud Project ID

play01:33

and click on it to open the project in GCP console.

play01:37

Navigate to the hamburger menu icon

play01:40

and locate APIs and Services.

play01:44

Click on Enable APIs and Services

play01:47

and look for Google Calendar API.

play01:50

Once you find it, enable the API on your cloud project.

play01:54

Now under the same APIs and Services within Credentials,

play01:59

click on Create credentials dropdown

play02:01

to select Service account key.

play02:04

Under Create service account key,

play02:06

select the New service account from the dropdown

play02:09

and enter an account name.

play02:11

Make sure JSON is the key type and then click Create.

play02:15

In the popup, select Create without role.

play02:18

A JSON file will be downloaded to your computer.

play02:21

And you will need this later, so take note of its location.

play02:25

Before we close it out though, copy the client email.

play02:33

Now open Google Calendar.

play02:35

And on the left, click the plus sign and select New Calendar.

play02:39

Enter AppointmentCalendar for the name of the calendar

play02:42

and select Create Calendar.

play02:45

Next, go to the AppointmentCalendar

play02:47

that will appear on the left.

play02:49

Click Add People and paste the email

play02:52

copied from that JSON file.

play02:54

Then select Make changes to events in the Permission

play02:57

dropdown and click Send.

play03:01

At this point, we are ready to go back to our Dialogflow agent

play03:04

and set the fulfillment.

play03:06

Click on Fulfillment and enable the inline editor.

play03:11

Check out the link in the description

play03:13

below to get the required code for package.json and index.js.

play03:18

Open package.json file and copy and paste the dependencies

play03:21

into fulfillment.

play03:23

Do the same for index.js as well.

play03:33

Grab the Calendar ID from the Google Calendar.

play03:35

We just create it and replace that in index.js.

play03:41

Next, copy the contents of the JSON file downloaded

play03:44

in the Service Account Setup section

play03:46

and paste it into the empty object, ServiceAccount.

play03:50

Check out the rest of the code.

play03:52

Make appointment function contains the responses

play03:55

to the user.

play03:57

And create calendar event function

play03:59

takes care of grabbing the entities like date, time,

play04:02

and appointment type, and creates the calendar invite.

play04:06

It also looks for the calendar conflicts

play04:08

and throws exceptions.

play04:11

Once you're done, click Deploy at the bottom of the page.

play04:14

Now, we have one more thing to do before we can start testing.

play04:19

Click on Intents and go to the Schedule Appointment intent.

play04:22

Scroll down to Fulfillment and enable webhook and save.

play04:27

Now we're ready to test.

play04:29

In the simulator on the right, query your Dialogflow agent

play04:32

with something like, set an appointment at 4:00

play04:35

PM tomorrow.

play04:36

And then respond to the follow up queries.

play04:39

After getting the required information,

play04:41

you will see that the appointment is added

play04:44

to the appointment calendar.

play04:46

You can verify that if you ask for another appointment

play04:50

at the same time slot, your agent will respond back

play04:53

with an appropriate message since that slot is not free.

play04:59

All right.

play05:00

So that was a lot.

play05:01

Let's summarize what we learned today.

play05:03

We enhanced our appointment scheduler chatbot

play05:06

by creating a fulfillment through inline editor,

play05:09

enabled Google Calendar API for the GCP project

play05:13

and used those APIs credentials to connect

play05:16

our fulfillment Cloud Function with Google Calendar.

play05:20

And finally, we were able to test

play05:22

our agent by creating appointment

play05:24

request on the calendar.

play05:27

Don't miss the next episode of Deconstructing Chatbots

play05:30

to learn more about conversational AI.

play05:33

Please like and subscribe to our channel for more such content.

play05:36

[MUSIC PLAYING]

Rate This

5.0 / 5 (0 votes)

Étiquettes Connexes
Chatbot IntegrationDialogflow TutorialBackend SystemsGoogle Calendar APICloud FunctionsAppointment SchedulerAI ConversationWebhook SetupCalendar ConflictsFulfillment Code
Besoin d'un résumé en anglais ?