Integrating a Chatbot: Dialogflow

Creating a Dialogflow agent

Dialogflow is Google’s Chatbot framework. We will use Google’s online console to create a Dialogflow Agent, who will be able to respond to text queries (that could be entered by a user in a text field, but in our case, it will be what Pepper hears).

To build our agent, we will do two things:

  • Integrate a prebuilt agent - Dialogflow provides many of those, to ask about the weather, time, units, translations, for small talk, etc. - we will use the one for Jokes, as it does not require any extra services.
  • Define our own intents, which are input patterns and an associated response (for example one intent could match “Who are you?”, “What’s your name?”, “What is your name?”, “tell me your name” - different ways of asking basically the same question)

Importing a prebuilt agent.

Dialogflow will start by having you create a default agent - make sure you create it with English as a default language.

You won't actually use that default agent in this lesson; instead, you will import a prebuilt agent: "Jokes" (if it doesn't appear in the choices, check that your current agent is in English). See Import a prebuilt agent for more details on doing this.

There are many other prebuilt agents available, but many of them require extra integration with a fulfilment service.

Optionally: instead of importing a prebuilt agent, you can create your own agent (see create your first agent).

Add your own intents

It’s a good practice to give a simple custom “sanity check” intent, that allows you easily to check whether this specific agent is indeed loaded.

Create one with this question, that you will also use later on for automated tests:

-- Q: “Are you waterproof?”

-- A: “No, please keep me inside!”

screenshot of intent creation

This allows to easily make sure that your dialogue is active.

You can, of course, add more intents of your own, and their responses!

Try your agent out in the Dialoflow console, to make sure it answers well.

Get your API credentials file

You will need special credentials to allow your Android application to call your agent.

In order to do this, you should first create a new Service Account, that only has the rights to do API calls to your Dialogflow agent; you will then put this agent’s credentials in your file.

To do this, follow the steps in the section “Getting the Service Account key” of the Dialogflow document Setting up authentication (you don’t need to follow the other sections). Make sure to pick “Dialogflow API Client” as a role.

In the end, you should obtain a JSON file containing your credentials - save it somewhere as "credentials.json", you will need it later on.