Thêm tính năng tự động hóa bằng Dialogflow

Dialogflow là một công cụ hiểu ngôn ngữ tự nhiên (NLU) giúp xử lý dữ liệu do người dùng nhập, liên kết ý định đó với ý định đã biết và phản hồi bằng các nội dung trả lời thích hợp. Có 2 phiên bản Dialogflow. Bằng cách 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 tính năng tự động hoá đơn giản để bắt đầu quá trình phát triển nhân viên hỗ trợ. Bằng cách tích hợp với Dialogflow CX, bạn có thể tạo tính năng tự động hoá nâng cao cho nhiều cuộc trò chuyện phức tạp hơn.

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

Để 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 nhân viên hỗ trợ tích hợp Dialogflow, Business Messages sẽ chuyển tin nhắn người dùng cho Dialogflow và gửi phản hồi của Dialogflow cho nhân viên hỗ trợ trong đối tượng dialogflowResponse của tin nhắn. Bạn có thể định cấu hình các tác nhân để tự động gửi phản hồi về Dialogflow cho người dùng mà không cần phải làm gì. Hãy xem bài viết Tự động trả lời để biết thông tin chi tiết.

Tích hợp Dialogflow

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

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

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

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

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

Dialogflow ES

Trước khi có thể bật công cụ tích hợp Dialogflow ES, bạn cần có mã dự án của tác nhân Dialogflow. Để tìm mã dự án,

  1. Chuyển đến Dialogflow Console.
  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 Google Project, hãy ghi nhớ giá trị Project ID (Mã dự án).

Dialogflow CX

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

  1. Chuyển đến Dialogflow CX Console.
  2. Chọn dự án Dialogflow của bạn.
  3. Trong bộ chọn nhân viên hỗ trợ, 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ợ theo định dạng sau: projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID.
  5. Hãy lưu ý các giá trị mã dự án và mã nhân viên hỗ trợ.

Tạo mục 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 từ dialogflowServiceAccountEmail. Thay thế PARTNER_ID bằng mã đối tác của bạn.

    URL

    
    # 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 các nhân viên hỗ trợ Business Messages và Dialogflow của bạn.

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

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

  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 Chọn vai trò, hãy chọn Trình chỉnh sửa tác nhân của bảng điều khiển Hộp thoại.

  7. Nhấp vào Thêm vai trò khác rồi chọn Ứng dụng API hộp thoại.

  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.

    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 phản hồi người dùng bằng các phản hồi Dialogflow hay không.

    Dialogflow ES

    URL

    
    # 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

    URL

    
    # 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 tùy chọn định dạng và giá trị, hãy xem Integration.

Sẽ mất khoảng hai phút để kết nối Business Messages và Dialogflow. Để kiểm tra trạng thái của công cụ tích hợp, hãy lấy OperationInfo của quá trình tích hợp.

Cập nhật mục liên kết tích hợp

Để cập nhật tùy chọn cài đặt tự động trả lờ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

Dialogflow ES

URL


# 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

URL


# 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 tùy chọn định dạng và giá trị, hãy xem Integration.

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

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

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

Nếu bạn cần xóa Dialogflow khỏi tác nhân Business Messages, hãy xóa phần tích hợp bằng lệnh sau.

URL


# 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 tùy chọn đị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ề một hoạt động tích hợp, bạn có thể sử dụng API Business Messages, miễn là bạn có giá trị name của hoạt động tích hợp.

Tìm thông tin về một hoạt động tích hợp duy nhất

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

URL


# 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 tùy chọn định dạng và giá trị, hãy xem Integration.

Liệt kê mọi chế độ tích hợp cho nhân viên hỗ trợ

Nếu không biết tên của tích hợp, bạn có thể nhận thông tin cho tất cả tích hợp liên kết với tác nhân bằng cách bỏ qua giá trị INTEGRATION_ID từ URL yêu cầu GET.

URL


# 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 tùy chọn định dạng và giá trị, hãy xem Integration.

Khớp ý định

Sau khi bạn bật tính năng tích hợp Dialogflow cho một nhân viên hỗ trợ của Business Messages, nhân viên hỗ trợ của bạn có thể 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 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 Dialogflow của bạn cho mọi tùy chọn trò chuyện mà bạn dự định hỗ trợ thông qua tính năng tự động hóa. Các tác nhân Business Messages dựa vào Dialogflow để hiểu được thông báo cho người dùng.

Khi gọi API Dialogflow, Business Messages sẽ chuyển trọng tải thông báo cho người dùng đến ý định của bạn và webhook thực hiện yêu cầu của bạn. Khi thông báo cho người dùng khớp với một ý định, bạn có thể truy cập vào trọng tải này theo định dạng Struct trong trường business_messages_payload của QueryParameters.

Trọng tải 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 chuyển một thông số phiên có tên là channel với giá trị google_business_messages đến ý định của bạn. Bạn có thể tham chiếu thông số này trong tác nhân của mình bằng định dạng sau: $session.params.channel.

Thông số này có thể dùng để thêm điều kiện vào cách thực hiện các quy trình hộp thoại nhằm hỗ trợ nhiều kênh trong cùng một nhân viên hỗ trợ dự án Dialogflow.

Để tìm hiểu thêm về các tham số truy vấn, hãy xem tài liệu tham khảo về Dialogflow ESDialogflow CX.

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

Khi tạo mô hình NLU trong Dialogflow, bạn có thể định cấu hình nhiều loại phản hồi cho một ý định. Business Messages hỗ trợ Phản hồi mặc định, có thể bao gồm:

  • Văn bản
  • Dung lượng tuỳ chỉnh
  • Chuyển đổi nhân viên hỗ trợ trực tiếp (Chỉ dành cho hộp thoại CX)

Trọng tải tuỳ chỉnh phải khớp với một đối tượng phản hồi thông báo JSON chứa Business Messages. Khi định cấu hình phản hồi trọng tải tuỳ chỉnh cho một ý định, Business Messages sẽ bỏ qua các trường sau:

  • name
  • messageId
  • representative

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

Chuyển đổi nhân viên hỗ trợ trực tiếp

{
  "metadata": {}
}

Câu hỏi thường gặp về bot

Sau khi bật công cụ tích hợp Dialogflow ES cho nhân viên hỗ trợ của Business Messages, bạn có thể tạo bot Câu hỏi thường gặp. Khi bạn cung cấp câu hỏi và câu trả lời dưới dạng tài liệu kiến thức được hỗ trợ, Business Messages và Dialogflow sẽ tạo một cơ sở hạ tầng cần thiết để 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ã.

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

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

Trước khi tạo bot trả lời các câu hỏi thường gặp, bạn cần các câu hỏi và câu trả lời của mình ở 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 Markdown hạn chế trong các câu trả lời, như được chỉ định trong Text text (Văn bản đa dạng thức).
  • Có kích thước tối đa là 50 MB.
  • Không được vượt quá 2000 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 có câu trả lời khác nhau.

Đối với tệp HTML,

  • Tệp từ các URL công khai phải được chỉ mục tìm kiếm của Google thu thập dữ liệu để các tệp đó tồn tại trong chỉ mục tìm kiếm. Bạn có thể kiểm tra vấn đề này bằng Google Search Console. Xin lưu ý rằng trình lập chỉ mục không cập nhật nội dung của bạn. Bạn phải cập nhật rõ ràng tài liệu khi nội dung nguồn thay đổi.
  • Dialogflow xóa các thẻ HTML khỏi nội dung khi tạo phản hồi. Do đó, tốt nhất là bạn nên tránh sử dụng thẻ HTML và sử dụng văn bản thuần tuý khi có thể.
  • Không hỗ trợ 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 tá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 cần tạo một cơ sở kiến thức để lưu trữ tất cả dữ liệu về bot, sau đó thêm một hoặc nhiều tài liệu có cặp câu hỏi/câu trả lời vào cơ sở kiến thức của bạn.

Tạo 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 bằng một chuỗi nhận dạng mà bạn chọn.

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

URL


# 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 tùy chọn định dạng và giá trị, hãy xem DialogflowKnowledgebase.

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

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

Thêm tài liệu này vào danh sách các tài liệu hiện có hoặc tạo danh sách mới nếu chưa có tài liệu nào. Danh sách tài liệu hiện có phải bao gồm giá trị name của tài liệu 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 tích hợp
  • KNOWLEDGE_BASE_DISPLAY_NAMEDOCUMENT_DISPLAY_NAME bằng cách xác định các chuỗi bạn chọn
  • PUBLIC_URL kèm theo URL công khai của tài liệu kiến thức

URL


# 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 cục 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 tích hợp
  • KNOWLEDGE_BASE_DISPLAY_NAMEDOCUMENT_DISPLAY_NAME bằng cách xác định các chuỗi bạn chọn
  • CSV_RAW_BYTES có tệp CSV dưới dạng chuỗi được mã hoá base64

URL


# 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 tùy chọn định dạng và giá trị, hãy xem DialogflowKnowledgebase.

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

Xóa tài liệu kiến thức

Nếu bạn cần xóa các cặp câu hỏi/câu trả lời khỏi tác nhân Business Messages, hãy xóa tài liệu kiến thức có chứa các câu hỏi đó 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 bằng chuỗi thích hợp.

URL


# 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 tùy chọn đị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 tự động trả lời trong quá trình tích hợp Dialogflow, thì Business Messages sẽ tự động trả lời người dùng thông qua Dialogflow. Nhân viên hỗ trợ về tin nhắn cho doanh nghiệp của bạn phản hồi với độ tin cậy cao nhất. Sau khi tích hợp Dialogflow ES, nếu có kết quả phù hợp với cả câu trả lời cho câu hỏi thường gặp và ý định tuỳ chỉnh, thì Business Messages sẽ phản hồi bằng kết quả trùng khớp có mức độ tin cậy cao nhất.

Tính năng Business Messages đánh dấu tất cả tin nhắn trả lời tự động là do BOT đạ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, thì Business Messages sẽ tạm ngưng câu trả lời tự động sau REPRESENTATIVE_JOINED sự kiện và tiếp tục trả lời tự động sau REPRESENTATIVE_LEFT sự kiện. Hãy xem phần Chuyển giao từ bot sang nhân viên hỗ trợ trực tiếp.

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

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

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

Các phản hồi có ý đị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ó độ tin cậy cao nhất khớp, thì nội dung sau đây sẽ á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 với một tin nhắn văn bản.
  • Nếu phản hồi có ít nhất một trọng tải Tuỳ chỉnh có cấu trúc đối tượng JSON cho Business Messages hợp lệ, thì Business Messages sẽ tạo một thông báo bằng cách sử dụng đối tượng JSON đã cung cấp.
  • Nếu nội dung phản hồi có ít nhất một phản hồi chuyển giao cho Nhân viên hỗ trợ trực tiếp, hãy xem phần Tự động trả lời khi có 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 câu trả lời trong một ý định trùng khớp, nên Business Messages sẽ gửi từng câu trả lời Văn bản, Tải trọng tùy chỉnh hoặc Chuyển tiếp nhân viên hỗ trợ dưới dạng một tin nhắn riêng. Nếu có nhiều thông báo trong một ý định trùng khớp, nhưng một số thông báo đó không đúng định dạng, thì Business Messages chỉ gửi các thông báo hợp lệ là thông tin phản hồi tự động.

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

Dialogflow CX hỗ trợ phản hồi Chuyển đổi nhân viên hỗ trợ trực tiếp. Nó cho biết rằng cuộc trò chuyện phải được chuyển giao cho một người đại diện cho con người, đồng thời cho phép bạn chuyển siêu dữ liệu tuỳ chỉnh cho quy trình chuyển giao của mình. Nếu một phản hồi ý định có mức độ tin cậy cao nhất khớp và bao gồm cả lượt chuyển giao cho nhân viên hỗ trợ trực tiếp, thì Business Messages sẽ gửi một sự kiện trực tiếp 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 phần Chuyển giao từ bot sang nhân viên hỗ trợ trực tiếp.

Tự động trả lời bằng tin nhắn dự phòng

Nếu Dialogflow không khớp với mức độ tin cậy cao, Business Messages sẽ gửi phản hồi dự phòng. Tính năng dự phòng được xử lý khác nhau trong Dialogflow ES và Hộp thoại 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, thì Business Messages sẽ gửi một tin nhắn dự phòng mà 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ó ý định nào khớp với phản hồi về ý định, thì Business Messages 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à trọng tải tùy chỉnh.

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

{
  "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ý các 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ả trùng khớp với ý kiến phản hồi về ý định, thì 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ể dùng văn bản dự phòng do Dialogflow cung cấp hoặc định cấu hình tính năng dự phòng bằng văn bản bổ sung, trọng tải tuỳ chỉnh và tuỳ chọn chuyển đổi nhân viên hỗ trợ trực tiếp.

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 được:

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