Google Cloud Big Data and Machine Learning Blog

Innovation in data processing and machine learning technology

How to integrate Dialogflow with Chatbase for easier bot analytics

Thursday, November 16, 2017

By Viknesh Krishnan, Chatbase Software Engineer, and Ksenia Gelfenbeyn, Dialogflow Product Manager

Dialogflow (formerly API.AI) is the end-to-end platform by Google for building great cross-platform conversational experiences. One important aspect that contributes to such experiences is for bot builders to use data analytics to monitor bot health and also better understand its interactions with users.

Chatbase, a cloud service that helps builders more easily analyze and optimize bots, is complementary to Dialogflow. Using them in combination helps builders create world-class bots via Dialogflow’s powerful libraries, and then continually track and optimize them using Chatbase. (Chatbase works with any type of bot, voice or text, and is available at no charge.)

All Dialogflow users get an automated set of basic Chatbase analytics (including Session Metrics) directly from their console. For a full set of analytics graphs and data (including Active User Metrics, Top Handled/Not Handled Messages, Funnels, and Cohorts), Dialogflow users also need to use the Chatbase API.

In this tutorial, you'll get a basic introduction to that API. Using the command line, you'll make Chatbase API calls to track this boring, but illustrative, conversation between a bot and human:

Human: Hello, bot!
Bot: Hi there, human. What do you want to talk about?
Human: I want to chat about the weather.
Bot: Sorry, I do not know how to do that. Can we pick another topic?

What you'll learn:

  • When to set "intent"
  • When to set "not_handled"
  • How to properly set "user_id"
  • How to properly set "type"
What you'll need:
  • A command line with CURL installed
  • Access to a Chatbase account (at no charge)

Step 1: Generate an API key

Head to https://chatbase.com/bots and login with your user information. On the Bots page, click on the '+ Add a bot' button to enter your bot information:

After completing this and subsequent steps you'll receive an API key you can use to get started with Chatbase. The key will be a universally unique identifier of 32 alphanumeric characters in this format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

Use your key as you complete the steps of this tutorial. For demonstration purposes, we’ll use CURL on the command line to send messages to the Generic API. However, when done, you'll want to use another method to send your API calls. You may want to use one of our Chatbase client libraries or our Facebook API depending on your specific implementation.

Step 2: Send a user message

Enter the following in your terminal, replacing the api_key field with the key you obtained in Step 1:

         curl -X POST \
           https://chatbase-area120.appspot.com/api/message \
           -H 'cache-control: no-cache' \
           -H 'content-type: application/json' \
           -d '{
           "api_key": "[your api key]",
           "type": "user",
           "platform": "our-curl-test-platform",
           "message": "Hello, bot!",
           "intent": "greeting",
           "version": "1.0",
           "user_id": "user-00"
         }'

The body of this request (everything in the curly-braces following the '-d' flag) is part of the payload that the Chatbase message endpoint can accept. By sending the message, "Hello, bot!," you successfully emulate a user interacting with your bot.

Your bot understands the user message to be a greeting. As a result, you set the intent of this message as "greeting." Setting intents, when known, is essential to optimizing your bot with Chatbase reports. Doing so enables you to quickly identify misinterpreted intents and message variations that should be grouped under an existing intent. Read more about intents here.

Step 3: Send the bot's reply

Enter the following in your terminal, replacing the api_key field with the key you obtained in Step 1:

         curl -X POST \
           https://chatbase-area120.appspot.com/api/message \
           -H 'cache-control: no-cache' \
           -H 'content-type: application/json' \
           -d '{
           "api_key": "[your api key]",
           "type": "agent",
           "platform": "our-curl-test-platform",
           "message": "Hi there, human. What do you want to talk about?",
           "version": "1.0",
           "user_id": "user-00"
         }'

By sending this message you emulated your bot's response, "Hi there, human. What do you want to talk about?"

Note that this message's "type" is set to "agent" (aka bot) rather than "user." Additionally, note that the user ID included here, "user-00," is the same one provided for the user message in Step 2. This indicates that these two messages are part of a contiguous conversation between one instance of our bot and one user. Read more here about why tracking user IDs correctly is critical.

Step 4: Send a not_handled user message

Enter the following in your terminal, replacing the api_key field with the key you obtained in Step 1:

         curl -X POST \
           https://chatbase-area120.appspot.com/api/message \
           -H 'cache-control: no-cache' \
           -H 'content-type: application/json' \
           -d '{
           "api_key": "[your api key]",
           "type": "user",
           "platform": "our-curl-test-platform",
           "message": "I want to chat about the weather.",
           "not_handled": "true",
           "version": "1.0",
           "user_id": "user-00"
         }'
Oh no! Your bot was unable to derive an intent from the user message asking about the weather and was therefore unable to understand it. As a result, you did not set the intent field with this call. However, importantly, you did include the "not_handled" field and set it to "true."

Set not_handled whenever your bot must respond with a generic reply that is not tailored to directly address the user message. Usually this occurs when your bot does not understand the user message and is unable to derive an intent. Alternatively, you might set not_handled when your bot does understand the message intent, but does not yet support a meaningful reply for that intent.

Chatbase reports are most useful when you provide accurate not_handled data. Read more about the importance of setting not_handled here.

Step 5: Send the bot's reply to the not_handled message

Enter the following in your terminal, replacing the api_key field with the key you obtained in Step 1:

         curl -X POST \
           https://chatbase-area120.appspot.com/api/message \
           -H 'cache-control: no-cache' \
           -H 'content-type: application/json' \
           -d '{
           "api_key": "[your api key]",
           "type": "agent",
           "platform": "our-curl-test-platform",
           "message": "Sorry, I do not know how to do that. Can we pick another topic?",
           "version": "1.0",
           "user_id": "user-00"
         }'

In this case, your bot sent a fallback, generic reply because it was unable to handle the user message. Note again that the user ID has remained the same throughout the conversation and that the "type" field has changed to "agent."

Next steps

Please note that certain metrics for messages may not immediately appear in the UI. Metrics will appear within 15 minutes of first sending messages to Chatbase when viewing reports set to show data for 'Today' or 'Yesterday' date periods. Metrics will appear within 1 hour of first sending messages to Chatbase when viewing reports set to show data for 'Last 7 Days' or 'Last 30 Days' date periods.

For answers to commonly asked questions about Dialogflow-Chatbase integration, see this doc. For a more in-depth tutorial about integrating an existing chatbot with Chatbase, explore this codelab.

  • Big Data Solutions

  • Product deep dives, technical comparisons, how-to's and tips and tricks for using the latest data processing and machine learning technologies.

  • Learn More

12 Months FREE TRIAL

Try BigQuery, Machine Learning and other cloud products and get $300 free credit to spend over 12 months.

TRY IT FREE