Menambahkan otomatisasi dengan Dialogflow

Dialogflow merupakan alat language understanding (NLU) yang memproses input pengguna, memetakannya ke dan merespons dengan balasan yang sesuai. Ada dua edisi Dialogflow. Dengan mengintegrasikan agen Business Messages dengan Dialogflow ES, Anda dapat dengan mudah membuat otomatisasi sederhana untuk mempercepat pengembangan agen. Menurut dan berintegrasi dengan Dialogflow CX, Anda dapat membuat otomatisasi lanjutan untuk percakapan yang kompleks.

Agen Business Messages mendukung integrasi langsung dengan

Untuk mengintegrasikan agen Business Messages dengan fitur Dialogflow lainnya ES atau Dialogflow CX, lihat dokumentasi masing-masing produk.

Saat pengguna mengirim pesan ke agen yang memiliki integrasi Dialogflow, Business Messages meneruskan pesan pengguna ke Dialogflow dan mengirimkan permintaan respons kepada agen melalui Objek dialogflowResponse. Anda dapat mengonfigurasi agen untuk secara otomatis mengirim respons Dialogflow kepada pengguna tanpa tindakan apa pun pada bagian. Lihat Respons otomatis untuk mengetahui detailnya.

Integrasi Dialogflow

Sebelum Anda dapat memanfaatkan otomatisasi berbasis Dialogflow melalui Business Messages, Anda harus mengaktifkan integrasi Dialogflow.

Prasyarat

Untuk memulai, Anda memerlukan

  • Business Messages agen
  • agen Dialogflow di region Global dengan bahasa dasar bahasa Inggris (id)

Jika Anda tidak memiliki agen Dialogflow, buatlah agen.

Dialogflow ES

Sebelum dapat mengaktifkan integrasi Dialogflow ES, Anda memerlukan ID project agen Dialogflow. Untuk menemukan project ID,

  1. Buka Konsol Dialogflow.
  2. Pilih agen Dialogflow yang ingin Anda hubungkan ke Business Messages, lalu klik ikon roda gigi di samping nama agen.
  3. Di bagian Project Google, catat nilai Project ID.

Dialogflow CX

Sebelum dapat mengaktifkan integrasi Dialogflow CX, Anda memerlukan ID agen dan project ID agen Dialogflow. Untuk menemukan ID ini,

  1. Buka Konsol Dialogflow CX.
  2. Pilih project Dialogflow Anda.
  3. Di pemilih agen, klik menu tambahan di samping agen Dialogflow Anda.
  4. Klik Copy name. Tindakan ini akan menyalin nama lengkap agen Anda di format berikut: projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID.
  5. Catat nilai project ID dan ID agen.

Membuat integrasi

  1. Dapatkan email akun layanan Dialogflow partner dari dialogflowServiceAccountEmail. Ganti PARTNER_ID dengan ID partner Anda.

    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)
    
  2. Salin email akun layanan. Akun ini menghubungkan Business Messages Anda dan agen Dialogflow.

  3. Di paket Google Cloud Konsol, memilih project Dialogflow Anda.

  4. Membuka IAM izin akses.

  5. Klik Tambahkan, lalu masukkan email akun layanan untuk Anggota baru.

  6. Untuk Select a role, pilih Dialogflow Console Agent Editor.

  7. Klik Add another role dan pilih Dialogflow API Client.

  8. Klik Simpan.

  9. Integrasikan project Dialogflow Anda dengan agen Business Messages.

    Ganti AUTO_RESPONSE_STATUS dengan DIAKTIFKAN atau DINONAKTIFKAN, bergantung apakah Anda ingin Business Messages merespons secara otomatis atau tidak pengguna dengan respons Dialogflow.

    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)
    

    Untuk opsi pemformatan dan nilai, lihat Integration

Perlu waktu sekitar dua menit untuk menghubungkan Business Messages dan Dialogflow. Kepada periksa status integrasi, dapatkan OperationInfo

Mengupdate integrasi

Untuk memperbarui setelan respons otomatis agen Anda, jalankan perintah berikut. Ganti AUTO_RESPONSE_STATUS dengan ENABLED atau NONAKTIF, bergantung pada apakah Anda ingin Business Messages otomatis atau tidak merespons pengguna dengan respons Dialogflow.

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
}'

Untuk opsi pemformatan dan nilai, lihat Integration

Beralih antaredisi Dialogflow

Agen Business Messages hanya dapat mendukung satu integrasi Dialogflow dalam satu waktu. Untuk beralih dari satu edisi Dialogflow ke edisi lainnya, Anda harus menghapus integrasi saat ini sebelum membuat yang baru.

Menghapus integrasi

Jika Anda perlu menghapus Dialogflow dari agen Business Messages, hapus integrasi dengan perintah berikut.

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)

Untuk opsi pemformatan dan nilai, lihat Integration

Mendapatkan informasi integrasi

Untuk mendapatkan informasi tentang integrasi, Anda dapat menggunakan Business Communications API, selama Anda memiliki nilai name integrasi.

Mendapatkan info untuk satu integrasi

Untuk mendapatkan informasi integrasi, jalankan perintah berikut.

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)

Untuk opsi pemformatan dan nilai, lihat Integration

Mencantumkan semua integrasi untuk agen

Jika tidak tahu nama integrasi, Anda bisa mendapatkan informasi untuk semua integrasi yang terkait dengan agen dengan menghapus INTEGRATION_ID dari URL permintaan GET.

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)

Untuk opsi pemformatan dan nilai, lihat Integration

Pencocokan intent

Setelah Anda mengaktifkan integrasi Dialogflow untuk agen Business Messages, dapat menggunakan intent terkonfigurasi project Dialogflow Anda untuk memahami dan menanggapi pertanyaan pengguna tanpa harus menulis kode. Untuk mempelajari lebih lanjut tentang lihat dokumentasi untuk Dialogflow ES dan Dialogflow CX.

Konfigurasikan intent Dialogflow Anda untuk setiap opsi percakapan yang ingin Anda pengguna melalui otomatisasi. Agen Business Messages mengandalkan Dialogflow untuk memahami pesan pengguna.

Saat memanggil Dialogflow API, Business Messages akan meneruskan payload pesan pengguna ke intent dan webhook fulfillment Anda. Saat pesan pengguna cocok dengan intent, Anda dapat mengakses payload ini dalam format Struct di Kolom business_messages_payload dalam QueryParameters.

Payload berisi semua kolom dari pesan pengguna kecuali DialogflowResponse.

Untuk Dialogflow CX, Business Messages juga meneruskan parameter sesi yang disebut channel dengan nilai google_business_messages ke intent Anda dan Anda dapat mereferensikannya dalam agen dengan format berikut: $session.params.channel.

Parameter ini dapat digunakan untuk menambahkan kondisional ke fulfillment Dialogflow untuk mendukung beberapa saluran dalam agen Dialogflow yang sama.

Untuk mengetahui informasi lebih lanjut tentang parameter kueri, lihat referensi Dialogflow ES dan Dialogflow CX.

Prasyarat

Saat membuat model NLU di dalam Dialogflow, Anda dapat mengonfigurasi berbagai jenis respons untuk intent. Business Messages mendukung respons Default, yang dapat mencakup hal berikut:

  • Teks
  • Payload kustom
  • Pengalihan agen langsung (khusus Dialogflow CX)

Payload kustom harus cocok dengan respons pesan JSON Business Messages yang valid objek. Saat mengonfigurasi respons payload kustom untuk intent, Business Messages mengabaikan kolom berikut:

  • name
  • messageId
  • representative

Lihat contoh respons berikut.

Teks dengan saran

{
  "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"
      }
    }
  ]
}

Kartu informasi

{
  "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
            }
          }
        }
      ]
    }
  }
}

Penyerahan tugas ke agen langsung

{
  "metadata": {}
}

Bot FAQ

Setelah mengaktifkan integrasi Dialogflow ES untuk agen Business Messages, Anda dapat membuat bot FAQ. Ketika Anda memberikan pertanyaan dan jawaban sebagai dokumen pengetahuan yang didukung. Business Messages dan Dialogflow membuat infrastruktur yang diperlukan untuk memahami dan menanggapi pertanyaan pengguna tanpa Anda harus menulis kode.

Untuk melihat cara kerja bot FAQ, chat dengan FAQ Business Messages Bot.

Prasyarat

Sebelum membuat bot FAQ, Anda perlu menyediakan pertanyaan dan jawaban sebagai dokumen pengetahuan (maks. 50 MB): file HTML atau file CSV yang tersedia untuk umum.

Umumnya, dokumen pengetahuan

  • Dapat menyertakan Markdown terbatas dalam jawaban, seperti yang ditentukan dalam Kalimat teks.
  • Memiliki ukuran maksimum 50 MB.
  • Tidak boleh melebihi 2.000 pasangan pertanyaan/jawaban.
  • Tidak mendukung pertanyaan duplikat dengan jawaban yang berbeda.

Untuk file HTML,

  • File dari URL publik harus sudah di-crawl oleh pengindeks penelusuran Google, agar mereka ada di indeks pencarian. Anda dapat memeriksanya dengan Search Console. Perhatikan bahwa pengindeks tidak membuat konten Anda tetap terbaru. Anda harus secara eksplisit memperbarui dokumen Anda bila konten sumber berubah.
  • Dialogflow akan menghapus tag HTML dari konten saat membuat respons. Karena sebaiknya hindari penggunaan tag HTML dan gunakan teks polos jika memungkinkan.
  • File dengan pasangan pertanyaan/jawaban tunggal tidak didukung.

Untuk {i>file<i} CSV,

  • File harus memiliki pertanyaan di kolom pertama dan jawaban di kolom kedua, tanpa menggunakan {i>header<i}.
  • File harus menggunakan koma sebagai pembatas.

Membuat bot FAQ

Untuk membuat bot FAQ, pertama-tama Anda membuat pusat informasi untuk menyimpan semua data bot, lalu tambahkan satu atau beberapa dokumen dengan pasangan pertanyaan/jawaban ke pusat informasi.

Membuat pusat informasi

Untuk membuat pusat informasi, jalankan perintah berikut. Ganti BRAND_ID, AGENT_ID, dan INTEGRATION_ID dengan nilai unik dari name dokumen. Ganti KNOWLEDGE_BASE_DISPLAY_NAME dengan string pengidentifikasi pilihan.

Setelah membuat pusat informasi, Anda dapat membuat dokumen yang ada di dalamnya.

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__"
      }
    ]
  }
}'

Untuk opsi pemformatan dan nilai, lihat DialogflowKnowledgebase

Membuat dokumen pengetahuan

Untuk membuat dokumen pengetahuan, jalankan perintah berikut.

Tambahkan dokumen ke daftar dokumen yang ada, atau buat daftar baru jika tidak ada belum ada. Daftar dokumen yang ada harus menyertakan name dokumen dalam permintaan.

File HTML publik

Ganti variabel berikut:

  • BRAND_ID, AGENT_ID, dan INTEGRATION_ID dengan nilai unik dari name integrasi
  • KNOWLEDGE_BASE_DISPLAY_NAME dan DOCUMENT_DISPLAY_NAME dengan mengidentifikasi {i>string<i} pilihan Anda
  • PUBLIC_URL dengan pengetahuan URL publik dokumen

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__"
          }
        ]
      }
    ]
  }
}'

File CSV lokal

Ganti variabel berikut:

  • BRAND_ID, AGENT_ID, dan INTEGRATION_ID dengan nilai unik dari name integrasi
  • KNOWLEDGE_BASE_DISPLAY_NAME dan DOCUMENT_DISPLAY_NAME dengan mengidentifikasi {i>string<i} pilihan Anda
  • CSV_RAW_BYTES dengan CSV file sebagai string berenkode base64

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__"
          }
        ]
      }
    ]
  }
}'

Untuk opsi pemformatan dan nilai, lihat DialogflowKnowledgebase

Perlu waktu sekitar dua menit untuk menambahkan dokumen ke pusat informasi. Untuk memeriksa status dokumen, dapatkan informasi OperationInfo

Menghapus dokumen pengetahuan

Jika Anda perlu menghapus pasangan pertanyaan/jawaban dari agen Business Messages, menghapus dokumen pengetahuan yang berisi mereka dengan perintah berikut.

Jalankan perintah berikut untuk menghapus satu dokumen yang ada. Ganti BRAND_ID, AGENT_ID, dan INTEGRATION_ID dengan nilai unik dari name dokumen. Ganti KNOWLEDGE_BASE_DISPLAY_NAME dengan string yang sesuai.

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__"
      }
    ]
  }
}'

Untuk opsi pemformatan dan nilai, lihat DialogflowKnowledgebase

Respons otomatis

Jika Anda mengaktifkan respons otomatis selama integrasi Dialogflow, Pesan merespons pengguna secara otomatis melalui Dialogflow. Bisnis Anda Agen Message merespons dengan kecocokan tingkat keyakinan tertinggi. Dengan Integrasi Dialogflow ES, jika ada kecocokan dengan jawaban FAQ dan niat kustom, Business Messages akan merespons dengan pencocokan yang memiliki tingkat kepercayaan.

Business Messages menandai semua pesan yang ditanggapi otomatis sebagai berasal dari BOT perwakilan. Jika agen Anda mendukung agen langsung, Business Messages menangguhkan respons otomatis setelah REPRESENTATIVE_JOINED peristiwa dan melanjutkan respons otomatis setelah peristiwa REPRESENTATIVE_LEFT. Lihat Handoff dari bot hingga agen langsung.

Respons otomatis dengan jawaban FAQ

Dengan integrasi Dialogflow ES, jika jawaban FAQ memiliki tingkat keyakinan tertinggi Business Messages akan memetakan jawaban atas pesan teks. Jika ada terkait, tetapi jawaban berbeda, pesan akan menampilkan jawab" saran. Jika tidak, pesan akan menyertakan pertanyaan dan saran balasan yang menanyakan apakah pesan tersebut memenuhi permintaan pengguna.

Merespons otomatis dengan respons intent

Respons intent dapat menyertakan satu atau beberapa respons berikut.

Jika respons niat memiliki kecocokan tingkat keyakinan tertinggi, hal berikut berlaku.

  • Jika respons memiliki minimal satu nilai Teks, Business Messages akan memetakannya nilai pada pesan teks.
  • Jika respons memiliki setidaknya satu Payload kustom dengan kolom Bisnis yang valid Struktur objek JSON Message, Business Messages membuat pesan menggunakan yang menyediakan objek JSON.
  • Jika respons memiliki setidaknya satu respons serah terima agen Langsung, lihat Respons otomatis dengan permintaan agen langsung.

Karena Dialogflow dapat menyertakan beberapa respons dalam satu kecocokan intent, Business Messages mengirimkan setiap Pengiriman Teks, Payload kustom, atau Agen langsung sebagai pesan terpisah. Jika ada beberapa pesan dalam satu intent cocok, tetapi beberapa di antaranya salah format, Business Messages hanya mengirim pesan yang valid pesan sebagai respons otomatis.

Merespons secara otomatis dengan permintaan agen langsung

Dialogflow CX mendukung serah terima langsung agen yang dihasilkan. Ini menandakan bahwa percakapan harus diserahkan kepada manusia representatif, dan memungkinkan Anda meneruskan metadata kustom untuk materi yang prosedur standar. Jika respons niat memiliki kecocokan tingkat keyakinan tertinggi, dan itu menyertakan penyerahan ke agen Langsung, Business Messages mengirimkan peristiwa yang diminta agen langsung ke webhook Anda. Untuk menangani peristiwa ini, lihat Menyerahkan dari bot ke agen langsung.

Merespons secara otomatis dengan pesan penggantian

Jika Dialogflow tidak mendapatkan kecocokan tingkat keyakinan tinggi, Business Messages akan mengirimkan respons penggantian. Penggantian ditangani secara berbeda di Dialogflow ES dan Dialogflow CX.

Dialogflow ES

Untuk bot FAQ, jika tidak ada kecocokan dengan jawaban FAQ, Business Messages mengirimkan pesan penggantian bahwa tidak dapat menemukan jawaban.

Untuk intent yang dikonfigurasi, jika tidak ada kecocokan dengan respons intent, Pesan mengirim respons intent penggantian. Anda dapat menggunakan teks fallback yang disediakan oleh Dialogflow, atau mengonfigurasi dengan teks tambahan dan payload kustom.

Berikut contoh respons intent penggantian yang webhook Anda dapat menerima:

{
  "intentResponses": [
    {
      "intentName": "projects/df-integration/agent/intents/12345",
      "intentDisplayName": "Default Fallback Intent",
      "intentDetectionConfidence": "1.0",
      "fulfillmentMessages": [
        {
          "text": "One more time?"
        }
      ]
    }
  ]
}

Dialogflow akan mengisi otomatis intent_name dan intent_display_name.

Dialogflow CX

Dialogflow CX menangani respons intent penggantian sebagai peristiwa bawaan. Jika tidak ada kecocokan dengan respons intent, Business Messages akan mengirimkan pesan penggantian dari peristiwa default Tidak ada kecocokan di Dialogflow. Anda dapat menggunakan teks penggantian yang disediakan oleh Dialogflow, atau mengonfigurasi penggantian dengan teks tambahan, payload kustom, dan opsi pengalihan ke agen langsung.

Berikut adalah contoh respons intent penggantian yang webhook dapat menerima:

{
  "intentResponses": [
    {
      "intentName": "sys.no-match-default",
      "intentDisplayName": "Default Fallback Intent",
      "intentDetectionConfidence": "0.3",
      "fulfillmentMessages": [
        {
          "text": "I missed that, say that again?"
        }
      ]
    }
  ]
}

Business Messages melakukan hard code intent_name dan intent_display_name.

Kolom khusus Dialogflow

Setelah Anda mengaktifkan integrasi Dialogflow, pengguna akan mengirim pesan ke agen menerima sertakan dialogflowResponse . Webhook Anda menerima payload untuk semua pesan pengguna terlepas dari apakah Business Messages otomatis merespons pesan di nama Anda. Untuk memeriksa respons otomatis, lihat nilai respons autoResponded dan memutuskan apakah Anda perlu merespons pengguna.

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",
  }],
},
...
Kolom Deskripsi
queryText Teks kueri percakapan asli. Jika ejaan otomatis koreksi diaktifkan untuk model Dialogflow, queryText berisi input pengguna yang dikoreksi.
intentName ID unik dari intent yang cocok.
intentDisplayName Nama intent yang cocok.
intentDetectionConfidence Rating keyakinan numerik dalam pertandingan antara queryText dan intentName.
text Pesan balasan.
jsonPayload Respons payload kustom. String ini cocok dengan kolom payload yang ditentukan dalam Dialogflow. Jika payload tidak memiliki JSON Business Messages yang valid struktur objek, error menjelaskan masalah.
error Deskripsi error dengan pesan fulfillment intent.
userQuestion Pertanyaan yang diajukan pengguna, sebagaimana diuraikan oleh Dialogflow.
faqQuestion Pertanyaan dari Dialogflow yang cocok dengan pertanyaan pengguna.
faqAnswer Jawaban dari Dialogflow cocok dengan pertanyaan pengguna.
matchConfidenceLevel Tingkat kepercayaan dalam kecocokan antara userQuestion dan faqQuestion.
matchConfidence Tingkat keyakinan numerik pada kecocokan antara userQuestion dan faqQuestion.
autoResponded Apakah Business Messages merespons secara otomatis atau tidak pengguna dengan jawaban dari Dialogflow.
message Payload respons otomatis.
responseSource Sumber respons otomatis. Lihat 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",
  }],
},
...
Kolom Deskripsi
queryText Teks kueri percakapan asli. Jika ejaan otomatis koreksi diaktifkan untuk model Dialogflow, queryText berisi input pengguna yang dikoreksi.
intentName ID unik dari intent yang cocok.
intentDisplayName Nama intent yang cocok.
intentDetectionConfidence Rating keyakinan numerik dalam pertandingan antara queryText dan intentName.
text Pesan balasan.
jsonPayload Respons payload kustom. String ini cocok dengan kolom payload yang ditentukan dalam Dialogflow. Jika payload tidak memiliki JSON Business Messages yang valid struktur objek, error menjelaskan masalah.
error Deskripsi error dengan pesan fulfillment intent.
liveAgentHandoff Metadata kustom untuk prosedur serah terima agen langsung Anda.
autoResponded Apakah Business Messages merespons secara otomatis atau tidak pengguna dengan jawaban dari Dialogflow.
message Payload respons otomatis.
responseSource Sumber respons otomatis. Lihat ResponseSource