Add automation with Dialogflow

Dialogflow is a natural language understanding (NLU) tool that processes user input, maps it to known intents, and responds with appropriate replies. By integrating Dialogflow with your Business Messages agent, you can easily create simple automation to jumpstart your agent development.

Business Messages agents support direct integrations with

  • Dialogflow ES intent matching: custom intent detection and responses
  • Dialogflow ES FAQ bots: interactive FAQs generated from web pages or CSV files

When a user sends a message to an agent that has a Dialogflow integration, Business Messages passes the user message to Dialogflow and sends Dialogflow's response to the agent in the message's dialogflowResponse object.

Additionally, you can configure agents to automatically send Dialogflow's response to the user without any action on your part. If your agent supports live agents, Business Messages suspends automatic responses after REPRESENTATIVE_JOINED events and resumes automatic responses after REPRESENTATIVE_LEFT events. See Handoff from bot to live agent.

Dialogflow integration

Before you can leverage Dialogflow-based automation through Business Messages, you need to enable the Dialogflow integration.

Prerequisites

Before you get started, you need

  • a Business Messages agent.
  • a Dialogflow agent in the Global region. If you don't have a Dialogflow agent, create one.

Before you can enable Dialogflow integration for a Business Messages agent, you need your Dialogflow model's project ID. To locate your model's project ID,

  1. Navigate to the Dialogflow Console
  2. Select the Dialogflow model you want to connect to Business Messages, then click the gear icon next to the model's project name.
  3. Under Google Project, note the Project ID value.

Enable the integration

  1. In the Business Communications Developer Console, navigate to Integrations.
  2. For Dialogflow, click Enable integration.
  3. Click Connect existing model.
  4. Enter your Dialogflow agent's project ID.
  5. If you want Business Messages to automatically respond to users with Dialogflow responses, select Enable auto-response.
  6. Click Next.
  7. Copy the service account email. This account connects your Business Messages and Dialogflow agents.
  8. In the Google Cloud Console, select your Dialogflow project.
  9. Navigate to IAM permissions.
  10. Click Add, and enter the service account email for New members.
  11. For Select a role, select Dialogflow Console Agent Editor.
  12. Click Add another role and select Dialogflow API Client.
  13. Click Save.
  14. In the Business Communications Developer Console, click Next.
  15. Click Start integration.

It takes about two minutes to connect Business Messages and Dialogflow.

Intent matching

After you enable the Dialogflow integration for a Business Messages agent, your agent can use your Dialogflow project's configured intents to understand and respond to user questions without you having to write code.

Configure your Dialogflow intents for every conversational option you intend to support through automation. Business Messages agents rely on Dialogflow to understand user messages.

Prerequisites

When creating NLP models within Dialogflow, developers can configure different response types for an intent, which correspond to the integrations supported in Dialogflow ES. Business Messages supports responses via the Default response, which can consist of a Text Response and Custom Payloads. A custom payload must match a valid Business Messages JSON message response object.

When configuring Custom Payloads responses for an intent, Business Messages ignores the following fields:

  • name
  • messageId
  • representative

See the following examples.

Text with suggestions

{
  "text": "Hello World!",
  "fallback": "Hello World!\n\nReply with \"Hello\" or \"Hi!\"",
  "suggestions": [
    {
      "reply": {
        "text": "Hello",
        "postbackData": "hello-formal",
      },
    },
    {
      "reply": {
        "text": "Hi!",
        "postbackData": "hello-informal",
      },
    },
  ],
}

Rich card

{
  "fallback": "Hello, world!\nSent with Business Messages\n\nReply with \"Suggestion #1\" or \"Suggestion #2\"",
  "richCard": {
    "standaloneCard": {
      "cardContent": {
        "title": "Hello, world!",
        "description": "Sent with Business Messages.",
        "media": {
          "height": "TALL",
          "contentInfo":{
            "altText": "Google logo",
            "fileUrl": "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
            "forceRefresh": "false"
          }
        },
        "suggestions": [
          {
            "reply": {
              "text": "Suggestion #1",
              "postbackData": "suggestion_1"
            }
          },
          {
            "reply": {
              "text": "Suggestion #2",
              "postbackData": "suggestion_2"
            }
          }
        ]
      }
    }
  }
}
{
  "fallback": "Card #1\nThe description for card #1\n\nCard #2\nThe description for card #2\n\nReply with \"Card #1\" or \"Card #2\"",
  "richCard": {
    "carouselCard": {
      "cardWidth": "MEDIUM",
      "cardContents": [
        {
          "title": "Card #1",
          "description": "The description for card #1",
          "suggestions": [
            {
              "reply": {
                "text": "Card #1",
                "postbackData": "card_1"
              }
            }
          ],
          "media": {
            "height": "MEDIUM",
            "contentInfo": {
              "fileUrl": "https://my.files/cute-dog.jpg",
              "forceRefresh": "false",
            }
          }
        },
        {
          "title": "Card #2",
          "description": "The description for card #2",
          "suggestions": [
            {
              "reply": {
                "text": "Card #2",
                "postbackData": "card_2"
              }
            }
          ],
          "media": {
            "height": "MEDIUM",
            "contentInfo": {
              "fileUrl": "https://my.files/elephant.jpg",
              "forceRefresh": "false",
            }
          }
        }
      ]
    }
  }
}

FAQ bots

After you enable the Dialogflow integration for a Business Messages agent, you can create an FAQ bot. When you supply questions and answers as a supported knowledge document, Business Messages and Dialogflow create the necessary infrastructure to understand and respond to user questions without you having to write code.

Prerequisites

Before you create an FAQ bot, you need your questions and answers available as a knowledge document (max 50 MB): a publicly available HTML file or a CSV file.

Generally, knowledge documents

  • Can include limited Markdown in answers, as specified in Rich text.
  • Have a maximum size of 50 MB.
  • Shouldn't exceed 2000 question/answer pairs.
  • Don't support duplicate questions with different answers.

For HTML files,

  • Files from public URLs must have been crawled by the Google search indexer, so that they exist in the search index. You can check this with the Google Search Console. Note that the indexer does not keep your content fresh. You must explicitly update your document when the source content changes.
  • Dialogflow removes HTML tags from content when creating responses. Because of this, it's best to avoid HTML tags and use plain text when possible.
  • Files with a single question/answer pair aren't supported.

For CSV files,

  • Files must have questions in the first column and answers in the second, with no header.
  • Files must use commas as delimiters.

Create an FAQ bot

  1. In the Business Communications Developer Console, navigate to Integrations.
  2. Under Knowledge base (FAQ), click Create knowledge base.
  3. Enter a name for the knowledge base, then click Next.
  4. Select a Mime type.
  5. Add a knowledge document.
    • If you chose HTML for Mime type, enter the publicly accessible URL for your FAQ in URL.
    • If you chose CSV for Mime type, click Upload and select your CSV file.
  6. Click Add and finish.

To add additional documents to an FAQ bot, click the Add documents button.

Once you follow these steps, Business Messages includes the dialogflowResponse object in user messages it sends to your agent. If you enabled automatic response, Business Messages responds to the user with the question/answer pair that has the highest matchConfidence score when compared to the user's message.

Auto-responses

If a Business Messages agent is configured for auto-response and there are matches to both a custom intent and an FAQ answer, Business Messages responds to the user with the match that has the highest confidence level. Business Messages marks all auto-responded messages as coming from BOT representatives.

Auto-responding with an FAQ answer

If an FAQ answer has the highest confidence level, Business Messages maps the answer to a text message. If there is a related but different answer available to be viewed, the message displays a "View another answer" suggestion chip. If not, the message includes a question and suggested replies asking if the message answered the user's request.

Auto-responding with an intent response

If an intent response has the highest confidence level match, and it has at least one Default Text value, Business Messages maps this value to a text message. Because Dialogflow can contain multiple responses within one intent match, Business Messages sends each Default Text as a separate message.

If a Dialogflow custom intent has at least one Custom Payload with a valid Business Messages JSON object structure, Business Messages creates a message using the provided JSON object. Because Dialogflow can contain multiple responses within one intent match, Business Messages sends each Custom Payload as a separate message.

Note that responses can consist of both Default Text and Custom Payloads.

If there are multiple fulfillment messages in an intent match, but some of them are malformed, Business Messages only sends valid messages as auto-responses.

Auto-responding with fallback message

If a Business Messages agent is configured for auto-response, but Business Messages can't get a high confidence level match to an FAQ answer or an intent response from Dialogflow, Business Messages sends a fallback message that it couldn't find an answer.

Dialogflow-specific fields

After you enable the Dialogflow integration, user messages the agent receives include the dialogflowResponse object. Your webhook receives payloads for all user messages regardless whether or not Business Messages automatically responded to the message on your behalf.

...
"dialogflowResponse": {
  "queryText": "TEXT",
  "intentResponse": {
    "intentName": "INTENT_ID",
    "intentDisplayName": "INTENT_NAME",
    "intentDetectionConfidence": "CONFIDENCE_NUMERIC",
    "fulfillmentMessages": [{
      "text": "FULFILLMENT_TEXT",
      "jsonPayload": "JSON",
      "error": "ERROR_STATUS",
    }],
  "faqResponse": {
    "userQuestion": "USER_QUESTION",
    "answers": [{
      "faqQuestion": "FAQ_QUESTION",
      "faqAnswer": "FAQ_ANSWER",
      "matchConfidenceLevel": "CONFIDENCE_LEVEL",
      "matchConfidence": "CONFIDENCE_NUMERIC",
    }],
  },
  "autoResponded": "BOOLEAN",
  "autoRespondedMessages": [{
    "message": "MESSAGE_JSON",
    "responseSource": "SOURCE",
  }],
},
...
Field Description
queryText The original conversational query text. If automatic spelling correction is enabled for the Dialogflow model, queryText contains the corrected user input.
intentName The unique identifier of the matched intent.
intentDisplayName The name of the matched intent.
intentDetectionConfidence The numeric confidence rating in the match between queryText and intentName.
text A text response.
jsonPayload A custom payload response.
error A description of an error with an intent fulfillment message.
userQuestion The question the user asked, as parsed by Dialogflow.
faqQuestion A question from Dialogflow matched to the user's question.
faqAnswer An answer from Dialogflow matched to the user's question.
matchConfidenceLevel The level of confidence in the match between userQuestion and faqQuestion.
matchConfidence The numeric confidence rating in the match between userQuestion and faqQuestion.
autoResponded Whether or not Business Messages automatically responded the user with an answer from Dialogflow.
message The payload of the autoresponse.
responseSource The source of the autoresponse. See ResponseSource.