Thêm quy trình tự động hoá bằng Dialogflow

Dialogflow là một tính năng công cụ hiểu ngôn ngữ (NLU) xử lý hoạt động đầu vào của người dùng, ánh xạ dữ liệu đó đến ý định và phản hồi bằng các câu trả lời thích hợp. Có 2 phiên bản của Dialogflow. Khi tích hợp nhân viên hỗ trợ Business Messages của bạn với Dialogflow ES, bạn có thể dễ dàng tạo quy trình tự động hoá đơn giản để bắt đầu phát triển nhân viên hỗ trợ. Theo tích hợp với Dialogflow CX, bạn có thể tạo tính năng tự động hoá nâng cao để các cuộc trò chuyện phức tạp.

Nhân viên hỗ trợ của Business Messages hỗ trợ tích hợp trực tiếp với

Cách tích hợp nhân viên hỗ trợ Business Messages với các tính năng khác của Dialogflow ES hoặc Dialogflow CX, hãy tham khảo tài liệu của từng sản phẩm.

Khi người dùng gửi tin nhắn cho một nhân viên hỗ trợ có tích hợp Dialogflow, Business Messages chuyển tin nhắn của người dùng cho Dialogflow và gửi tin nhắn của Dialogflow để phản hồi nhân viên hỗ trợ trong Đối tượng dialogflowResponse. Bạn có thể định cấu hình nhân viên hỗ trợ để tự động gửi phản hồi của Dialogflow cho người dùng mà không cần bạn phải làm gì với phần. Xem bài viết Trả lời tự động để biết thông tin chi tiết.

Công cụ tích hợp Dialogflow

Trước khi có thể tận dụng tính năng tự động hoá dựa trên Dialogflow thông qua Business Messages, bạn cần bật công cụ tích hợp Dialogflow.

Điều kiện tiên quyết

Để bắt đầu, bạn cần

  • một Business Messages tác nhân người dùng
  • một nhân viên hỗ trợ Dialogflow ở khu vực Toàn cầu có ngôn ngữ gốc là tiếng Anh (vi)

Nếu bạn chưa có nhân viên hỗ trợ Dialogflow, hãy tạo một nhân viên hỗ trợ.

Dialogflow ES

Để có thể bật công cụ tích hợp Dialogflow ES, bạn cần Mã dự án của nhân viên hỗ trợ dự án Dialogflow. Để tìm mã dự án,

  1. Chuyển đến Bảng điều khiểnDialogflow.
  2. Chọn nhân viên hỗ trợ Dialogflow mà bạn muốn kết nối với Business Messages. sau đó nhấp vào biểu tượng bánh răng bên cạnh tên nhân viên hỗ trợ.
  3. Trong phần Google Project (Dự án của Google), hãy ghi chú giá trị Project ID (Mã dự án).

Dialogflow CX

Để có thể bật công cụ tích hợp Dialogflow CX, bạn cần Mã dự án và mã nhân viên hỗ trợ của Dialogflow. Để tìm những mã này,

  1. Chuyển đến Bảng điều khiểnDialogflow CX.
  2. Chọn dự án Dialogflow của bạn.
  3. Trong bộ chọn tác nhân, hãy nhấp vào trình đơn mục bổ sung bên cạnh nhân viên hỗ trợ dự án Dialogflow.
  4. Nhấp vào Sao chép tên. Thao tác này sẽ sao chép tên đầy đủ của nhân viên hỗ trợ trong định dạng sau: projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID.
  5. Hãy lưu ý đến các giá trị mã dự án và mã nhân viên hỗ trợ.

Tạo liên kết tích hợp

  1. Nhận email tài khoản dịch vụ Dialogflow của đối tác dialogflowServiceAccountEmail. Thay thế PARTNER_ID bằng mã đối tác của bạn.

    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. Sao chép email tài khoản dịch vụ. Tài khoản này kết nối với Business Messages của bạn và nhân viên hỗ trợ Dialogflow.

  3. Trong Google Cloud Google Play Console, chọn dự án Dialogflow của bạn.

  4. Chuyển đến IAM quyền truy cập.

  5. Nhấp vào Thêm rồi nhập email tài khoản dịch vụ cho Thành viên mới.

  6. Đối với phần Select a role (Chọn vai trò), hãy chọn Dialogflow Console Agent Editor.

  7. Nhấp vào Add another role (Thêm vai trò khác) rồi chọn Dialogflow API Client.

  8. Nhấp vào Lưu.

  9. Tích hợp dự án Dialogflow với nhân viên hỗ trợ Business Messages của bạn.

    Thay thế AUTO_RESPONSE_STATUS bằng TẮT hoặc TẮT, tuỳ thuộc vào về việc bạn có muốn Business Messages tự động trả lời hay không người dùng có phản hồi 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)
    

    Để biết các lựa chọn về định dạng và giá trị, hãy xem Integration.

Hệ thống sẽ mất khoảng 2 phút để kết nối Business Messages và Dialogflow. Người nhận kiểm tra trạng thái tích hợp, lấy thông tin tích hợp OperationInfo.

Cập nhật chế độ tích hợp

Để cập nhật chế độ cài đặt tự động phản hồi của nhân viên hỗ trợ, hãy chạy lệnh sau. Thay thế AUTO_RESPONSE_STATUS bằng ĐÃ BẬT hoặc TẮT tuỳ thuộc vào việc bạn có muốn Business Messages tự động bật hay không phản hồi người dùng bằng phản hồi của 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
}'

Để biết các lựa chọn về định dạng và giá trị, hãy xem Integration.

Chuyển đổi giữa các phiên bản Dialogflow

Một nhân viên hỗ trợ Business Messages chỉ có thể hỗ trợ một công cụ tích hợp Dialogflow tại một thời điểm. Để chuyển từ phiên bản Dialogflow này sang phiên bản khác, bạn cần xoá phiên bản tích hợp hiện tại trước khi tạo tích hợp mới.

Xoá chế độ tích hợp

Nếu bạn cần xoá Dialogflow khỏi nhân viên hỗ trợ Business Messages, hãy xoá bằng lệnh sau.

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)

Để biết các lựa chọn về định dạng và giá trị, hãy xem Integration.

Nhận thông tin tích hợp

Để nhận thông tin về việc tích hợp, bạn có thể sử dụng Business Communications API, miễn là bạn có giá trị name của chế độ tích hợp.

Nhận thông tin cho một lần tích hợp đơn lẻ

Để nhận thông tin tích hợp, hãy chạy lệnh sau.

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)

Để biết các lựa chọn về định dạng và giá trị, hãy xem Integration.

Liệt kê tất cả thành phần tích hợp của một nhân viên hỗ trợ

Nếu không biết tên của nội dung tích hợp, bạn có thể tìm thông tin về tích hợp liên kết với một tác nhân bằng cách bỏ qua INTEGRATION_ID từ URL yêu cầu 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)

Để biết các lựa chọn về định dạng và giá trị, hãy xem Integration.

So khớp ý định

Sau khi bạn bật công cụ tích hợp Dialogflow cho một nhân viên hỗ trợ Business Messages, nhân viên hỗ trợ có thể sử dụng các ý định đã định cấu hình của dự án Dialogflow để hiểu và trả lời câu hỏi của người dùng mà không cần bạn phải viết mã. Để tìm hiểu thêm về ý định, hãy xem tài liệu về Dialogflow ESDialogflow CX.

Định cấu hình ý định của Dialogflow cho mọi lựa chọn trò chuyện mà bạn dự định nhắm đến thông qua công nghệ tự động hoá. Nhân viên hỗ trợ Business Messages dựa vào Dialogflow để hiểu được thông báo cho người dùng.

Khi gọi các API Dialogflow, Business Messages sẽ truyền tải trọng thông báo cho người dùng đối với ý định và webhook cho phương thức thực hiện của bạn. Khi thông báo cho người dùng trùng khớp có ý định, bạn có thể truy cập vào tải trọng này ở định dạng Struct trong Trường business_messages_payload trong QueryParameters.

Tải trọng chứa tất cả các trường từ thông báo cho người dùng, ngoại trừ DialogflowResponse.

Đối với Dialogflow CX, Business Messages cũng truyền một thông số phiên có tên là channel mang giá trị google_business_messages đến ý định của bạn. Bạn có thể tham chiếu thông số này trong nhân viên hỗ trợ theo định dạng sau: $session.params.channel.

Bạn có thể dùng tham số này để thêm điều kiện vào các phương thức thực hiện trong Dialogflow nhằm hỗ trợ nhiều kênh trong cùng một tác nhân Dialogflow.

Để biết thêm thông tin về tham số truy vấn, hãy xem tài liệu tham khảo Dialogflow ESDialogflow CX.

Điều kiện tiên quyết

Khi tạo các mô hình NLU trong Dialogflow, bạn có thể định cấu hình các mô hình khác nhau cho một ý định. Business Messages hỗ trợ Phản hồi mặc định, chẳng hạn như:

  • Văn bản
  • Tải trọng tuỳ chỉnh
  • Tính năng chuyển giao cho nhân viên hỗ trợ trực tiếp (chỉ dành cho Dialogflow CX)

Tải trọng tuỳ chỉnh phải khớp với nội dung phản hồi hợp lệ của tin nhắn JSON trong Business Messages đối tượng. Khi định cấu hình phản hồi tải trọng tuỳ chỉnh cho một ý định, Business Messages sẽ bỏ qua các trường sau:

  • name
  • messageId
  • representative

Hãy xem các phản hồi mẫu sau đây.

Văn bản có đề xuất

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

Thẻ thông tin chi tiết

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

Nhân viên hỗ trợ chuyển giao trực tiếp

{
  "metadata": {}
}

Bot giải đáp câu hỏi thường gặp

Sau khi bật tính năng tích hợp Dialogflow ES cho một nhân viên hỗ trợ Business Messages, bạn có thể tạo một bot Câu hỏi thường gặp. Khi bạn đưa ra câu hỏi và câu trả lời dưới dạng một tài liệu kiến thức được hỗ trợ, Business Messages và Dialogflow tạo cơ sở hạ tầng cần thiết để hiểu và trả lời các câu hỏi của người dùng mà không cần bạn phải viết mã.

Để xem bot câu hỏi thường gặp hoạt động, hãy trò chuyện với Câu hỏi thường gặp về Business Messages Bot.

Điều kiện tiên quyết

Trước khi tạo bot Câu hỏi thường gặp, bạn cần có sẵn câu hỏi và câu trả lời dưới dạng tài liệu kiến thức (tối đa 50 MB): tệp HTML có sẵn công khai hoặc tệp CSV.

Nhìn chung, tài liệu kiến thức

  • Có thể bao gồm một số hạn chế Markdown trong câu trả lời, như đã chỉ định trong thẻ Nhiều định dạng văn bản.
  • Có kích thước tối đa là 50 MB.
  • Không được vượt quá 2.000 cặp câu hỏi/câu trả lời.
  • Không hỗ trợ các câu hỏi trùng lặp với các câu trả lời khác nhau.

Đối với tệp HTML,

  • Tệp từ URL công khai phải được trình lập chỉ mục tìm kiếm của Google thu thập thông tin, để chúng tồn tại trong chỉ mục tìm kiếm. Bạn có thể kiểm tra điều này với Search Console. Xin lưu ý rằng trình lập chỉ mục không giúp nội dung của bạn luôn mới. Bạn phải thể hiện rõ ràng cập nhật tài liệu của bạn khi nội dung nguồn thay đổi.
  • Dialogflow xoá các thẻ HTML khỏi nội dung khi tạo phản hồi. Bởi vì trong trường hợp này, bạn nên tránh sử dụng thẻ HTML và sử dụng văn bản thuần tuý nếu có thể.
  • Không hỗ trợ các tệp có một cặp câu hỏi/câu trả lời.

Đối với tệp CSV,

  • Tệp phải có câu hỏi ở cột đầu tiên và câu trả lời ở cột thứ hai, không có tiêu đề.
  • Tệp phải sử dụng dấu phẩy làm dấu phân cách.

Tạo bot câu hỏi thường gặp

Để tạo bot Câu hỏi thường gặp, trước tiên, bạn phải tạo cơ sở kiến thức để lưu trữ tất cả của bot, sau đó thêm một hoặc nhiều tài liệu cùng với cặp câu hỏi/câu trả lời vào cơ sở kiến thức.

Xây dựng cơ sở kiến thức

Để tạo cơ sở kiến thức, hãy chạy lệnh sau. Thay thế BRAND_ID, AGENT_IDINTEGRATION_ID bằng các giá trị duy nhất từ name của tài liệu. Thay thế KNOWLEDGE_BASE_DISPLAY_NAME kèm theo chuỗi nhận dạng của lựa chọn.

Sau khi tạo cơ sở kiến thức, bạn có thể tạo tài liệu bên trong đó.

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

Để biết các lựa chọn về định dạng và giá trị, hãy xem DialogflowKnowledgebase.

Tạo tài liệu kiến thức

Để tạo tài liệu kiến thức, hãy chạy lệnh sau.

Thêm tài liệu vào danh sách tài liệu hiện có hoặc tạo danh sách mới nếu không có chưa tồn tại. Danh sách các tài liệu hiện có phải bao gồm name của giấy tờ giá trị trong yêu cầu.

Tệp HTML công khai

Thay thế các biến sau:

  • BRAND_ID, AGENT_IDINTEGRATION_ID với các giá trị duy nhất từ name của phép tích hợp
  • KNOWLEDGE_BASE_DISPLAY_NAMEDOCUMENT_DISPLAY_NAME bằng xác định chuỗi mà bạn chọn
  • PUBLIC_URL với kiến thức URL công khai của tài liệu

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

Tệp CSV trên thiết bị

Thay thế các biến sau:

  • BRAND_ID, AGENT_IDINTEGRATION_ID với các giá trị duy nhất từ name của phép tích hợp
  • KNOWLEDGE_BASE_DISPLAY_NAMEDOCUMENT_DISPLAY_NAME bằng xác định chuỗi mà bạn chọn
  • CSV_RAW_BYTES cho tệp CSV dưới dạng chuỗi được mã hoá 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__"
          }
        ]
      }
    ]
  }
}'

Để biết các lựa chọn về định dạng và giá trị, hãy xem DialogflowKnowledgebase.

Cần khoảng 2 phút để thêm một tài liệu vào cơ sở kiến thức. Để kiểm tra trạng thái của tài liệu, lấy thông số tích hợp OperationInfo.

Xoá tài liệu kiến thức

Nếu bạn cần xoá các cặp câu hỏi/câu trả lời khỏi nhân viên hỗ trợ Business Messages, xoá tài liệu kiến thức chứa chúng bằng lệnh sau.

Chạy lệnh sau để xoá một tài liệu hiện có. Thay thế BRAND_ID, AGENT_IDINTEGRATION_ID bằng các giá trị duy nhất từ name của tài liệu. Thay thế KNOWLEDGE_BASE_DISPLAY_NAME với chuỗi thích hợp.

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

Để biết các lựa chọn về định dạng và giá trị, hãy xem DialogflowKnowledgebase.

Trả lời tự động

Nếu bạn bật tính năng phản hồi tự động trong quá trình tích hợp Dialogflow, doanh nghiệp Ứng dụng Tin nhắn tự động trả lời người dùng thông qua Dialogflow. Doanh nghiệp của bạn Nhân viên hỗ trợ ứng dụng Tin nhắn phản hồi bằng mức độ tin cậy trùng khớp cao nhất. Có Tích hợp Dialogflow ES, nếu có kết quả trùng khớp với cả câu trả lời câu hỏi thường gặp và câu trả lời đối tượng có ý định tùy chỉnh, Business Messages phản hồi bằng kết quả phù hợp có mức độ tin cậy.

Business Messages đánh dấu tất cả các tin nhắn trả lời tự động là của BOT người đại diện. Nếu nhân viên hỗ trợ của bạn hỗ trợ nhân viên hỗ trợ trực tiếp, Business Messages tạm ngưng câu trả lời tự động sau ngày REPRESENTATIVE_JOINED sự kiện và tiếp tục trả lời tự động sau REPRESENTATIVE_LEFT sự kiện. Xem phần handoff từ bot thành nhân viên hỗ trợ.

Tự động trả lời bằng câu trả lời cho các câu hỏi thường gặp

Khi tích hợp Dialogflow ES, nếu câu trả lời Câu hỏi thường gặp có độ tin cậy cao nhất thì Business Messages liên kết câu trả lời với một tin nhắn văn bản. Nếu có có liên quan nhưng có câu trả lời khác, thông báo sẽ hiển thị thông báo "Xem câu trả lời khác trả lời" . Nếu không, tin nhắn sẽ bao gồm câu hỏi và gợi ý trả lời để hỏi xem thư có đáp ứng yêu cầu của người dùng hay không.

Tự động trả lời bằng phản hồi ý định

Phản hồi ý định có thể bao gồm một hoặc nhiều phản hồi sau đây.

Nếu một phản hồi ý định có mức độ tin cậy cao nhất phù hợp, thì sẽ được áp dụng.

  • Nếu câu trả lời có ít nhất một giá trị Văn bản, thì Business Messages sẽ liên kết giá trị này đến một tin nhắn văn bản.
  • Nếu phản hồi có ít nhất một tải trọng tuỳ chỉnh với một tệp Business hợp lệ Cấu trúc đối tượng JSON của ứng dụng Tin nhắn, Business Messages tạo một tin nhắn bằng cách sử dụng đối tượng JSON được cung cấp.
  • Nếu phản hồi có ít nhất một phản hồi chuyển giao cho nhân viên hỗ trợ đang hoạt động, hãy xem Tự động trả lời bằng yêu cầu của nhân viên hỗ trợ trực tiếp.

Vì Dialogflow có thể bao gồm nhiều phản hồi trong một lần so khớp ý định, Business Messages gửi từng Văn bản, Tải trọng tuỳ chỉnh hoặc Chuyển tiếp nhân viên hỗ trợ trực tiếp dưới dạng một tin nhắn riêng. Nếu có nhiều thông báo trong một ý định khớp, nhưng một số trong số đó không đúng định dạng, Business Messages chỉ gửi hợp lệ tin nhắn dưới dạng thư trả lời tự động.

Tự động trả lời bằng một yêu cầu của nhân viên hỗ trợ

Dialogflow CX hỗ trợ tính năng chuyển giao cho nhân viên hỗ trợ trực tiếp của bạn. Mã này báo hiệu rằng cuộc trò chuyện nên được chuyển giao cho một người đồng thời cho phép bạn truyền siêu dữ liệu tuỳ chỉnh để chuyển giao cho đối tác quy trình. Nếu một phản hồi ý định có mức độ tin cậy cao nhất và bao gồm tính năng chuyển giao cho nhân viên hỗ trợ trực tiếp, Business Messages sẽ gửi sự kiện do nhân viên hỗ trợ yêu cầu đến webhook của bạn. Để xử lý sự kiện này, hãy xem Chuyển từ bot sang nhân viên hỗ trợ trực tiếp.

Tự động trả lời bằng thông báo dự phòng

Nếu Dialogflow không nhận được kết quả trùng khớp có độ tin cậy cao, Business Messages sẽ gửi một phản hồi dự phòng. Dữ liệu dự phòng được xử lý theo cách khác trong Dialogflow ES và Dialogflow CX.

Dialogflow ES

Đối với bot Câu hỏi thường gặp, nếu không có kết quả nào phù hợp với câu trả lời cho Câu hỏi thường gặp, Business Messages sẽ gửi một thông báo dự phòng cho biết không thể tìm thấy câu trả lời.

Đối với các ý định đã định cấu hình, nếu không có kết quả phù hợp với phản hồi ý định, thì Thông báo sẽ gửi phản hồi ý định dự phòng. Bạn có thể sử dụng văn bản dự phòng do Dialogflow cung cấp hoặc định cấu hình dự phòng bằng văn bản bổ sung và các tải trọng tuỳ chỉnh.

Dưới đây là ví dụ về phản hồi ý định dự phòng mà webhook của bạn có thể nhận:

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

Dialogflow đã điền sẵn intent_nameintent_display_name.

Dialogflow CX

Dialogflow CX xử lý phản hồi ý định dự phòng dưới dạng sự kiện tích hợp. Nếu không có kết quả nào khớp với phản hồi ý định, Business Messages sẽ gửi một thông báo dự phòng từ sự kiện mặc định Không khớp trong Dialogflow. Bạn có thể sử dụng văn bản dự phòng do Dialogflow cung cấp hoặc định cấu hình văn bản dự phòng với văn bản bổ sung, tải trọng tuỳ chỉnh và các tuỳ chọn chuyển giao tác nhân trực tiếp.

Dưới đây là ví dụ về phản hồi của ý định dự phòng mà webhook có thể nhận:

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

Business Messages mã hoá cứng intent_nameintent_display_name.

Các trường dành riêng cho Dialogflow

Sau khi bạn bật công cụ tích hợp Dialogflow, người dùng sẽ nhắn tin cho nhân viên hỗ trợ nhận được bao gồm dialogflowResponse . Webhook của bạn nhận tải trọng cho tất cả thông báo của người dùng bất kể Business Messages có tự động trả lời tin nhắn trên thay mặt cho bạn. Để kiểm tra thư trả lời tự động, hãy xem giá trị của autoResponded và quyết định xem bạn có cần trả lời người dùng đó hay không.

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",
  }],
},
...
Trường Mô tả
queryText Văn bản truy vấn trò chuyện gốc. Nếu đánh vần tự động đã bật tính năng sửa cho mẫu Dialogflow, queryText có chứa thông tin đầu vào của người dùng đã sửa.
intentName Giá trị nhận dạng duy nhất của ý định được so khớp.
intentDisplayName Tên của ý định được so khớp.
intentDetectionConfidence Mức đánh giá độ tin cậy dạng số trong kết quả trùng khớp từ queryText đến intentName.
text Phản hồi bằng tin nhắn văn bản.
jsonPayload Phản hồi tải trọng tuỳ chỉnh. Chuỗi này khớp với tải trọng được xác định trong Dialogflow. Nếu tải trọng không có tệp JSON hợp lệ của Business Messages cấu trúc đối tượng, error sẽ mô tả vấn đề.
error Nội dung mô tả lỗi với thông báo thực hiện ý định.
userQuestion Câu hỏi mà người dùng đặt ra, như được Dialogflow phân tích cú pháp.
faqQuestion Một câu hỏi của Dialogflow khớp với câu hỏi của người dùng.
faqAnswer Một câu trả lời của Dialogflow khớp với câu hỏi của người dùng.
matchConfidenceLevel Mức độ tin cậy về trận đấu giữa userQuestionfaqQuestion.
matchConfidence Mức đánh giá độ tin cậy dạng số trong kết quả trùng khớp giữa userQuestionfaqQuestion.
autoResponded Liệu Business Messages có tự động trả lời hay không người dùng với câu trả lời từ Dialogflow.
message Tải trọng của phản hồi tự động.
responseSource Nguồn của thư trả lời tự động. Xem 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",
  }],
},
...
Trường Mô tả
queryText Văn bản truy vấn trò chuyện gốc. Nếu đánh vần tự động đã bật tính năng sửa cho mẫu Dialogflow, queryText có chứa thông tin đầu vào của người dùng đã sửa.
intentName Giá trị nhận dạng duy nhất của ý định được so khớp.
intentDisplayName Tên của ý định được so khớp.
intentDetectionConfidence Mức đánh giá độ tin cậy dạng số trong kết quả trùng khớp từ queryText đến intentName.
text Phản hồi bằng tin nhắn văn bản.
jsonPayload Phản hồi tải trọng tuỳ chỉnh. Chuỗi này khớp với tải trọng được xác định trong Dialogflow. Nếu tải trọng không có tệp JSON hợp lệ của Business Messages cấu trúc đối tượng, error sẽ mô tả vấn đề.
error Nội dung mô tả lỗi với thông báo thực hiện ý định.
liveAgentHandoff Siêu dữ liệu tuỳ chỉnh cho quy trình chuyển giao tác nhân trực tiếp.
autoResponded Liệu Business Messages có tự động trả lời hay không người dùng với câu trả lời từ Dialogflow.
message Tải trọng của phản hồi tự động.
responseSource Nguồn của thư trả lời tự động. Xem ResponseSource.