Business Messages agents support direct integrations with
- Dialogflow ES: intent matching and FAQ bots
- Dialogflow CX: intent matching and live agent handoff
To integrate a Business Messages agent with other features of Dialogflow ES or Dialogflow CX, refer to each product's documentation.
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. You can configure agents to
automatically send Dialogflow's response to the user without any action on your
part. See Auto-responses
for details.
Dialogflow integration
Before you can leverage Dialogflow-based automation through Business Messages, you need to enable the Dialogflow integration.
Prerequisites
To get started, you need
- a Business Messages agent
- a Dialogflow agent in the Global region with a root language of English (en)
If you don't have a Dialogflow agent, create one.
Dialogflow ES
Before you can enable a Dialogflow ES integration, you need your Dialogflow agent's project ID. To locate the project ID,
- Navigate to the Dialogflow Console.
- Select the Dialogflow agent you want to connect to Business Messages, then click the gear icon next to the agent name.
- Under Google Project, note the Project ID value.
Dialogflow CX
Before you can enable a Dialogflow CX integration, you need your Dialogflow agent's project ID and agent ID. To locate these IDs,
- Navigate to the Dialogflow CX Console.
- Select your Dialogflow project.
- In the agent selector, click the overflow menu next to your Dialogflow agent.
- Click Copy name. This copies the full name of your agent in the
following format:
projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID
. - Note the project ID and agent ID values.
Create the integration
Get the partner's Dialogflow service account email from
dialogflowServiceAccountEmail
. Replace PARTNER_ID with your partner ID.cURL
# This code gets the partner. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/partners/get # Replace the __PARTNER_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X GET \ "https://businesscommunications.googleapis.com/v1/partners/__PARTNER_ID__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)"
Node.js
/** * This code snippet gets a partner. * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/partners/get * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const PARTNER_ID = 'EDIT_HERE'; const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); const partnerName = 'partners/' + PARTNER_ID; if (authClient) { // Setup the parameters for the API call const apiParams = { auth: authClient, name: partnerName, }; bcApi.partners.get(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent found console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
Python
"""This code gets a partner. Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/partners/get This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( Agent, BusinesscommunicationsPartnersGetRequest, ) # Edit the values below: PARTNER_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) partners_service = BusinesscommunicationsV1.PartnersService(client) partner_name = 'partners/' + PARTNER_ID partner = partners_service.Get(BusinesscommunicationsPartnersGetRequest( name=partner_name )) print(partner)
Copy the service account email. This account connects your Business Messages and Dialogflow agents.
In the Google Cloud Console, select your Dialogflow project.
Navigate to IAM permissions.
Click Add, and enter the service account email for New members.
For Select a role, select Dialogflow Console Agent Editor.
Click Add another role and select Dialogflow API Client.
Click Save.
Integrate your Dialogflow project with your Business Messages agent.
Replace AUTO_RESPONSE_STATUS with ENABLED or DISABLED, depending on whether or not you want Business Messages to automatically respond to users with Dialogflow responses.
Dialogflow ES
cURL
# This code creates a Dialogflow ES integration. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_es # Replace the __BRAND_ID__, __AGENT_ID__, __DIALOGFLOW_ES_PROJECT_ID__ and __AUTO_RESPONSE_STATUS__ # Make sure a service account key file exists at ./service_account_key.json curl -X POST \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -d '{ "dialogflowEsIntegration": { "dialogflowProjectId": "__DIALOGFLOW_ES_PROJECT_ID__", "autoResponseStatus": "__AUTO_RESPONSE_STATUS__" } }'
Node.js
/** * This code snippet creates a Dialogflow ES integration. * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_es * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const AGENT_ID = 'EDIT_HERE'; const DIALOGFLOW_ES_PROJECT_ID = 'EDIT_HERE' const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); const uuidv4 = require('uuid').v4; // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); const agentName = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID; if (authClient) { const integrationObject = { dialogflowEsIntegration: { dialogflowProjectId: DIALOGFLOW_ES_PROJECT_ID, autoResponseStatus: 'ENABLED' } }; // Setup the parameters for the API call const apiParams = { auth: authClient, parent: agentName, resource: integrationObject }; bcApi.brands.agents.integrations.create(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent created console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
Python
"""This code snippet creates a Dialogflow ES integration. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_es This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsAgentsIntegrationsCreateRequest, DialogflowEsIntegration ) # Edit the values below: BRAND_ID = 'EDIT_HERE' AGENT_ID = 'EDIT_HERE' DIALOGFLOW_ES_PROJECT_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) integrations_service = BusinesscommunicationsV1.BrandsAgentsIntegrationsService(client) agent_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID integration = integrations_service.Create(BusinesscommunicationsBrandsAgentsIntegrationsCreateRequest( integration=DialogflowEsIntegration( autoResponseStatus=DialogflowEsIntegration.AutoResponseStatusValueValuesEnum.ENABLED, dialogflowProjectId=DIALOGFLOW_ES_PROJECT_ID ), parent=agent_name )) print(integration)
Dialogflow CX
cURL
# This code creates a Dialogflow CX integration. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_cx # Replace the __BRAND_ID__, __AGENT_ID__, __DIALOGFLOW_CX_PROJECT_ID__, __DIALOGFLOW_CX_AGENT_ID__ and __AUTO_RESPONSE_STATUS__ # Make sure a service account key file exists at ./service_account_key.json curl -X POST \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -d '{ "dialogflowCxIntegration": { "dialogflowProjectId": "__DIALOGFLOW_CX_PROJECT_ID__", "dialogflowAgentId": "__DIALOGFLOW_CX_AGENT_ID__", "autoResponseStatus": "__AUTO_RESPONSE_STATUS__" } }'
Node.js
/** * This code snippet creates a Dialogflow CX integration. * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_cx * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const AGENT_ID = 'EDIT_HERE'; const DIALOGFLOW_CX_AGENT_ID = 'EDIT_HERE' const DIALOGFLOW_CX_PROJECT_ID = 'EDIT_HERE' const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); const uuidv4 = require('uuid').v4; // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); const agentName = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID; if (authClient) { const integrationObject = { dialogflowCxIntegration: { dialogflowProjectId: DIALOGFLOW_CX_PROJECT_ID, dialogflowAgentId: DIALOGFLOW_CX_AGENT_ID, autoResponseStatus: 'ENABLED' } }; // Setup the parameters for the API call const apiParams = { auth: authClient, parent: agentName, resource: integrationObject }; bcApi.brands.agents.integrations.create(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent created console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
Python
"""This code snippet creates a Dialogflow CX integration. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#dialogflow_cx This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsAgentsIntegrationsCreateRequest, DialogflowCxIntegration ) # Edit the values below: BRAND_ID = 'EDIT_HERE' AGENT_ID = 'EDIT_HERE' DIALOGFLOW_CX_AGENT_ID = 'EDIT_HERE' DIALOGFLOW_CX_PROJECT_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) integrations_service = BusinesscommunicationsV1.BrandsAgentsIntegrationsService(client) agent_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID integration = integrations_service.Create(BusinesscommunicationsBrandsAgentsIntegrationsCreateRequest( integration=DialogflowCxIntegration( autoResponseStatus=DialogflowCxIntegration.AutoResponseStatusValueValuesEnum.ENABLED, dialogflowAgentId=DIALOGFLOW_CX_AGENT_ID, dialogflowProjectId=DIALOGFLOW_CX_PROJECT_ID ), parent=agent_name )) print(integration)
For formatting and value options, see
Integration
.
It takes about two minutes to connect Business Messages and Dialogflow. To
check the status of the integration, get the integration's
OperationInfo
.
Update the integration
To update your agent's auto-response setting, run the following command. Replace AUTO_RESPONSE_STATUS with ENABLED or DISABLED depending on whether or not you want Business Messages to automatically respond to users with Dialogflow responses.
Dialogflow ES
cURL
# This code updates the Dialogflow association. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/updateDialogflowAssociation # Replace the __BRAND_ID__ and __AGENT_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/dialogflowAssociation?updateMask=enableAutoResponse" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "enableAutoResponse": true }'
Dialogflow CX
cURL
# This code updates the Dialogflow association. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/updateDialogflowAssociation # Replace the __BRAND_ID__ and __AGENT_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/dialogflowAssociation?updateMask=enableAutoResponse" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "enableAutoResponse": true }'
For formatting and value options, see
Integration
.
Switch between Dialogflow editions
A Business Messages agent can only support one Dialogflow integration at a time. To switch from one Dialogflow edition to another, you need to remove the current integration before creating the new one.
Delete the integration
If you need to remove Dialogflow from your Business Messages agent, delete the integration with the following command.
cURL
# This code deletes an integration. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#delete_the_integration # Replace the __BRAND_ID__, __AGENT_ID__ and __INTEGRATION_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X DELETE \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)"
Node.js
/** * This code snippet deletes an integration. * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#delete_the_integration * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const AGENT_ID = 'EDIT_HERE'; const INTEGRATION_ID = 'EDIT_HERE'; const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); const uuidv4 = require('uuid').v4; // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); const integrationName = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID + '/integrations/' + INTEGRATION_ID; if (authClient) { // Setup the parameters for the API call const apiParams = { auth: authClient, name: integrationName, }; bcApi.brands.agents.integrations.delete(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent created console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
Python
"""This code snippet deletes an integration. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#delete_the_integration This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsAgentsIntegrationsDeleteRequest ) # Edit the values below: BRAND_ID = 'EDIT_HERE' AGENT_ID = 'EDIT_HERE' INTEGRATION_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) integrations_service = BusinesscommunicationsV1.BrandsAgentsIntegrationsService(client) integration_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID + '/integrations/' + INTEGRATION_ID integration = integrations_service.Delete(BusinesscommunicationsBrandsAgentsIntegrationsDeleteRequest( name=integration_name )) print(integration)
For formatting and value options, see
Integration
.
Get integration information
To get information about an integration, you can use the Business Communications
API, as long as you have the integration’s name
value.
Get info for a single integration
To get integration information, run the following command.
cURL
# This code gets information about an integration. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#get_info_for_a_single_integration # Replace the __BRAND_ID__, __AGENT_ID__ and __INTEGRATION_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X GET \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)"
Node.js
/** * This code snippet gets information about an integration. * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#get_info_for_a_single_integration * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const AGENT_ID = 'EDIT_HERE'; const INTEGRATION_ID = 'EDIT_HERE'; const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); const uuidv4 = require('uuid').v4; // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); const integrationName = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID + '/integrations/' + INTEGRATION_ID; if (authClient) { // Setup the parameters for the API call const apiParams = { auth: authClient, name: integrationName, }; bcApi.brands.agents.integrations.get(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent created console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
Python
"""This code snippet gets information about an integration. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#get_info_for_a_single_integration This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsAgentsIntegrationsDeleteRequest ) # Edit the values below: BRAND_ID = 'EDIT_HERE' AGENT_ID = 'EDIT_HERE' INTEGRATION_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) integrations_service = BusinesscommunicationsV1.BrandsAgentsIntegrationsService(client) integration_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID + '/integrations/' + INTEGRATION_ID integration = integrations_service.Get(BusinesscommunicationsBrandsAgentsIntegrationsDeleteRequest( name=integration_name )) print(integration)
For formatting and value options, see
Integration
.
List all integrations for an agent
If you don’t know the integration’s name, you can get information for all integrations associated with an agent by omitting the INTEGRATION_ID value from a GET request URL.
cURL
# This code lists all integrations for an agent. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#list_all_integrations_for_an_agent # Replace the __BRAND_ID__ and __AGENT_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X GET \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)"
Node.js
/** * This code snippet lists all integrations for an agent. * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#list_all_integrations_for_an_agent * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const AGENT_ID = 'EDIT_HERE'; const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); const uuidv4 = require('uuid').v4; // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); if (authClient) { // Setup the parameters for the API call const apiParams = { auth: authClient, parent: 'brands/' + BRAND_ID + '/agents/' + AGENT_ID, }; bcApi.brands.agents.integrations.list(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Agent created console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
Python
"""This code snippet lists all integrations for an agent. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#list_all_integrations_for_an_agent This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsAgentsIntegrationsListRequest ) # Edit the values below: BRAND_ID = 'EDIT_HERE' AGENT_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) integrations_service = BusinesscommunicationsV1.BrandsAgentsIntegrationsService(client) agent_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID integration = integrations_service.List( BusinesscommunicationsBrandsAgentsIntegrationsListRequest(parent=agent_name) ) print(integration)
For formatting and value options, see
Integration
.
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. To learn more about intents, see the documentation for Dialogflow ES and Dialogflow CX.
Configure your Dialogflow intents for every conversational option you intend to support through automation. Business Messages agents rely on Dialogflow to understand user messages.
When calling the Dialogflow APIs, Business Messages passes the
user message payload
to your intents and your fulfillment webhook. When a user message is matched
with an intent, you can access this payload in Struct
format in the
business_messages_payload
field within QueryParameters
.
The payload contains all fields from the user message except for DialogflowResponse
.
For Dialogflow CX, Business Messages also passes a session parameter called channel
with value google_business_messages
to your intents and you can reference it in your agent with the following format: $session.params.channel
.
This parameter can be used to add conditionals to your Dialogflow fulfillments in order to support multiple channels in the same Dialogflow agent.
For more on query parameters, see the Dialogflow ES and Dialogflow CX references.
Prerequisites
When creating NLU models within Dialogflow, you can configure different response types for an intent. Business Messages supports the Default response, which can include the following:
- Text
- Custom payload
- Live agent handoff (Dialogflow CX only)
A custom payload must match a valid Business Messages JSON message response object. When configuring custom payload responses for an intent, Business Messages ignores the following fields:
name
messageId
representative
See the following sample responses.
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"
}
}
]
}
}
}
}
Rich card carousel
{
"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
}
}
}
]
}
}
}
Live agent handoff
{
"metadata": {}
}
FAQ bots
After you enable a Dialogflow ES 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.
To see an FAQ bot in action, chat with the Business Messages FAQ Bot.
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 doesn't 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
To create an FAQ bot, you first create a knowledge base to store all of the bot's data, then add one or more documents with question/answer pairs to your knowledge base.
Create a knowledge base
To create a knowledge base, run the following command. Replace
BRAND_ID, AGENT_ID, and INTEGRATION_ID
with the unique values from the document's name
. Replace
KNOWLEDGE_BASE_DISPLAY_NAME with an identifying string of your
choice.
After you create a knowledge base you can create documents within it.
cURL
# This code creates a knowledge base. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#create-knowledge-base # Replace the __BRAND_ID__, __AGENT_ID__, __INTEGRATION_ID__ and __KNOWLEDGE_BASE_DISPLAY_NAME__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__?updateMask=dialogflowEsIntegration.dialogflowKnowledgeBases" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "dialogflowEsIntegration": { "dialogflowKnowledgeBases": [ { "displayName": "__KNOWLEDGE_BASE_DISPLAY_NAME__" } ] } }'
For formatting and value options, see
DialogflowKnowledgebase
.
Create a knowledge document
To create a knowledge document, run the following command.
Add the document to the list of existing documents, or create a new list if none
exists yet. A list of existing documents should include the document's name
value in the request.
Public HTML file
Replace the following variables:
- BRAND_ID, AGENT_ID, and INTEGRATION_ID
with the unique values from the integration's
name
- KNOWLEDGE_BASE_DISPLAY_NAME and DOCUMENT_DISPLAY_NAME with identifying strings of your choice
PUBLIC_URL with the knowledge document's public URL
cURL
# This code creates a knowledge base document from an HTML document and adds it to the knowledge base. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#create-document # Replace the __BRAND_ID__, __AGENT_ID__, __INTEGRATION_ID__, __KNOWLEDGE_BASE_DISPLAY_NAME__, __DOCUMENT_DISPLAY_NAME__ and __PUBLIC_URL__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__?updateMask=dialogflowEsIntegration.dialogflowKnowledgeBases" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "dialogflowEsIntegration": { "dialogflowKnowledgeBases": [ { "displayName": "__KNOWLEDGE_BASE_DISPLAY_NAME__", "documents": [ { "displayName": "__DOCUMENT_DISPLAY_NAME__", "faqUrl": "__PUBLIC_URL__" } ] } ] } }'
Local CSV file
Replace the following variables:
- BRAND_ID, AGENT_ID, and INTEGRATION_ID
with the unique values from the integration's
name
- KNOWLEDGE_BASE_DISPLAY_NAME and DOCUMENT_DISPLAY_NAME with identifying strings of your choice
CSV_RAW_BYTES with the CSV file as a base64-encoded string
cURL
# This code creates a knowledge base document from a CSV document and adds it to the knowledge base. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#create-document # Replace the __BRAND_ID__, __AGENT_ID__, __INTEGRATION_ID__, __KNOWLEDGE_BASE_DISPLAY_NAME__, __DOCUMENT_DISPLAY_NAME__ and __CSV_RAW_BYTES__ # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__?updateMask=dialogflowEsIntegration.dialogflowKnowledgeBases" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "dialogflowEsIntegration": { "dialogflowKnowledgeBases": [ { "displayName": "__KNOWLEDGE_BASE_DISPLAY_NAME__", "documents": [ { "displayName": "__DOCUMENT_DISPLAY_NAME__", "rawContent": "__CSV_RAW_BYTES__" } ] } ] } }'
For formatting and value options, see
DialogflowKnowledgebase
.
It takes about two minutes to add a document to a knowledge base. To check the
status of the document, get the integration's
OperationInfo
.
Delete a knowledge document
If you need to remove question/answer pairs from your Business Messages agent, delete the knowledge document that contains them with the following command.
Run the following command to delete a single existing document. Replace
BRAND_ID, AGENT_ID, and INTEGRATION_ID
with the unique values from the document's name
. Replace
KNOWLEDGE_BASE_DISPLAY_NAME with the appropriate string.
cURL
# This code deletes a knowledge base document. # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/integrate/dialogflow?method=api#delete_a_knowledge_document # Replace the __BRAND_ID__, __AGENT_ID__, __INTEGRATION_ID__ and __KNOWLEDGE_BASE_DISPLAY_NAME__ # To delete all knowledge bases, set dialogflowKnowledgeBases to an empty list. Otherwise, the list should contain all existing knowledgebases except the one you would like to remove. # Make sure a service account key file exists at ./service_account_key.json curl -X PATCH \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/agents/__AGENT_ID__/integrations/__INTEGRATION_ID__?updateMask=dialogflowEsIntegration.dialogflowKnowledgeBases" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \ -d '{ "dialogflowEsIntegration": { "dialogflowKnowledgeBases": [ { "displayName": "__KNOWLEDGE_BASE_DISPLAY_NAME__" } ] } }'
For formatting and value options, see
DialogflowKnowledgebase
.
Auto-responses
If you enable auto-response during the Dialogflow integration, Business Messages automatically responds to the user via Dialogflow. Your Business Messages agent responds with the highest confidence level match. With a Dialogflow ES integration, if there are matches to both an FAQ answer and a custom intent, Business Messages responds with the match that has the highest confidence level.
Business Messages marks all auto-responded messages as coming from BOT
representatives. 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.
Auto-respond with an FAQ answer
With a Dialogflow ES integration, 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, the message displays a "View another answer" suggestion. If not, the message includes a question and suggested replies asking if the message satisfied the user's request.
Auto-respond with an intent response
Intent responses can include one or more of the following responses.
- Dialogflow ES: Text, Custom payload
- Dialogflow CX: Text, Custom payload, Live agent handoff
If an intent response has the highest confidence level match, the following applies.
- If the response has at least one Text value, Business Messages maps this value to a text message.
- If the response has at least one Custom payload with a valid Business Messages JSON object structure, Business Messages creates a message using the provided JSON object.
- If the response has at least one Live agent handoff response, see Auto-respond with a live agent request.
Because Dialogflow can include multiple responses within one intent match, Business Messages sends each Text, Custom payload, or Live agent handoff response as a separate message. If there are multiple messages in an intent match, but some of them are malformed, Business Messages only sends valid messages as auto-responses.
Auto-respond with a live agent request
Dialogflow CX supports the Live agent handoff response. It signals that the conversation should be handed off to a human representative, and it lets you pass custom metadata for your handoff procedure. If an intent response has the highest confidence level match, and it includes a Live agent handoff, Business Messages sends a live agent requested event to your webhook. To handle this event, see Handoff from bot to live agent.
Auto-respond with a fallback message
If Dialogflow doesn't get a high confidence level match, Business Messages sends a fallback response. Fallbacks are handled differently in Dialogflow ES and Dialogflow CX.
Dialogflow ES
For FAQ bots, if there's no match to an FAQ answer, Business Messages sends a fallback message that it couldn't find an answer.
For configured intents, if there's no match to an intent response, Business Messages sends a fallback intent response. You can use the fallback text provided by Dialogflow, or configure the fallback with additional text and custom payloads.
Here's an example of a fallback intent response that your webhook can receive:
{
"intentResponses": [
{
"intentName": "projects/df-integration/agent/intents/12345",
"intentDisplayName": "Default Fallback Intent",
"intentDetectionConfidence": "1.0",
"fulfillmentMessages": [
{
"text": "One more time?"
}
]
}
]
}
Dialogflow pre-populates intent_name
and intent_display_name
.
Dialogflow CX
Dialogflow CX handles fallback intent responses as built-in events. If there's no match to an intent response, Business Messages sends a fallback message from the No-match default event in Dialogflow. You can use the fallback text provided by Dialogflow, or configure the fallback with additional text, custom payloads, and live agent handoff options.
Here's an example of a fallback intent response that your webhook can receive:
{
"intentResponses": [
{
"intentName": "sys.no-match-default",
"intentDisplayName": "Default Fallback Intent",
"intentDetectionConfidence": "0.3",
"fulfillmentMessages": [
{
"text": "I missed that, say that again?"
}
]
}
]
}
Business Messages hard-codes intent_name
and intent_display_name
.
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 of
whether or not Business Messages automatically responded to the message on your
behalf. To check for an auto-response, see the value of the
autoResponded
field and decide if you need to respond to the user.
Dialogflow ES
... "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.
This string matches the custom
payload defined in Dialogflow.
If the payload does not have a valid Business Messages JSON
object structure, error describes the issue. |
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 to the user with an answer from Dialogflow. |
message |
The payload of the autoresponse. |
responseSource
|
The source of the autoresponse. See
ResponseSource . |
Dialogflow CX
... "dialogflowResponse": { "queryText": "TEXT", "intentResponse": { "intentName": "INTENT_ID", "intentDisplayName": "INTENT_NAME", "intentDetectionConfidence": "CONFIDENCE_NUMERIC", "fulfillmentMessages": [{ "text": "FULFILLMENT_TEXT", "jsonPayload": "JSON", "error": "ERROR_STATUS", "liveAgentHandoff": { "metadata": {} } }], "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.
This string matches the custom
payload defined in Dialogflow.
If the payload does not have a valid Business Messages JSON
object structure, error describes the issue. |
error |
A description of an error with an intent fulfillment message. |
liveAgentHandoff |
Custom metadata for your live agent handoff procedure. |
autoResponded
|
Whether or not Business Messages automatically responded to the user with an answer from Dialogflow. |
message |
The payload of the autoresponse. |
responseSource
|
The source of the autoresponse. See
ResponseSource . |