Bắt đầu cuộc trò chuyện

Trong các cuộc trò chuyện với nhân viên hỗ trợ của Business Messages, tin nhắn chào mừng sẽ đặt giọng điệu tương tác. API này cũng cho người dùng biết tác nhân có thể làm gì, từ đó định hình câu hỏi và kỳ vọng của người dùng.

Nhân viên hỗ trợ sẽ gửi tin nhắn chào mừng mỗi khi người dùng mở một cuộc trò chuyện. Tác nhân tác nhân cũng có thể hiển thị câu bắt đầu cuộc trò chuyện để hướng dẫn người dùng về các đường dẫn đã biết hoặc thường gặp.

Nếu người dùng cố gắng bắt đầu một cuộc trò chuyện ngoài giờ hoạt động của nhân viên hỗ trợ, thì nhân viên hỗ trợ sẽ hiển thị tin nhắn ngoại tuyến mà bạn có thể sử dụng để chia sẻ các kênh thay thế hoặc đề xuất các bước tiếp theo. Bằng cách tận dụng các chế độ cài đặt này, bạn có thể tăng độ tin cậy và khả năng hữu dụng của nhân viên hỗ trợ.

Câu mở đầu cuộc trò chuyện

Chế độ cài đặt cấp nhân viên hỗ trợ và cấp vị trí

Bạn có thể chỉ định các chế độ cài đặt trò chuyện ở cấp của nhân viên hỗ trợ hoặc vị trí.

  • Cấp nhân viên hỗ trợ: Các chế độ cài đặt trò chuyện này áp dụng cho mọi cuộc trò chuyện với nhân viên hỗ trợ trên mọi điểm truy cập.

    Thông báo chào mừng ở cấp nhân viên hỗ trợ có thể bắt đầu với nội dung "Cảm ơn bạn đã liên hệ với Bbridgepoint Runners..." Câu mở đầu cuộc trò chuyện có thể tập trung vào thông tin hoặc các hành động trong phạm vi công ty.

  • Cấp vị trí: Các chế độ cài đặt này sẽ ghi đè các chế độ cài đặt ở cấp tác nhân và chỉ áp dụng cho các cuộc trò chuyện có vị trí đó qua điểm truy cập PLACESHEETMAPS.

    Thông báo chào mừng ở cấp vị trí có thể bắt đầu với nội dung "Cảm ơn bạn đã liên hệ với Bbridgepoint Runners trên Amphitheatre Pkwy..." Các câu bắt đầu cuộc trò chuyện có thể tập trung vào các tác vụ hoặc thông tin dựa trên vị trí. Một thông báo ngoại tuyến có thể đề cập đến thời điểm địa điểm mở cửa vào lần tiếp theo.

Ngôn ngữ

Nhân viên hỗ trợ và vị trí có thể chỉ định các chế độ cài đặt riêng cho mọi ngôn ngữ mà họ hỗ trợ. Ví dụ: một nhân viên hỗ trợ có thể chỉ định một tin nhắn chào mừng bằng tiếng Anh cho ngôn ngữ "en" và có cùng một tin nhắn chào mừng bằng tiếng Tây Ban Nha cho ngôn ngữ "es". Business Messages sẽ phân giải sự trùng khớp giữa ngôn ngữ được báo cáo của thiết bị người dùng và ngôn ngữ mà một nhân viên hỗ trợ hoặc vị trí có bất kỳ chế độ cài đặt trò chuyện nào.

Ngôn ngữ khớp được báo cáo trong trường resolvedLocale của mỗi thông báo. Bạn có thể chỉ định defaultLocale của một tác nhân hoặc vị trí. Các trọng số này sẽ phân giải việc so khớp ngôn ngữ. Vui lòng xem nội dung Bản địa hoá và ngôn ngữ.

Business Messages sử dụng ngôn ngữ đã phân giải để xác định chế độ cài đặt trò chuyện nào sẽ áp dụng.

Tin nhắn chào mừng

Tin nhắn đầu tiên trong cuộc trò chuyện giữa nhân viên hỗ trợ và người dùng là tin nhắn chào mừng của nhân viên hỗ trợ. Tin nhắn chào mừng tự động xuất hiện sau khi người dùng bắt đầu một cuộc trò chuyện mới. Một tin nhắn chào mừng sẽ đặt ra kỳ vọng của người dùng khi tương tác với nhân viên hỗ trợ. Để chỉnh sửa tin nhắn chào mừng, hãy xem phần Cập nhật chế độ cài đặt trò chuyện.

Câu mở đầu cuộc trò chuyện

Mặc dù tin nhắn chào mừng phù hợp bao gồm chức năng của nhân viên hỗ trợ ở cấp độ cao và có kết thúc mở, nhưng những câu mở đầu cuộc trò chuyện phù hợp sẽ hướng người dùng đến các câu hỏi thường gặp hoặc chức năng đã biết.

Cụm từ bắt đầu cuộc trò chuyện sẽ xuất hiện dưới dạng các câu trả lời đề xuất được xếp chồng theo chiều dọc và nằm ngay sau tin nhắn chào mừng. Khi người dùng nhấn vào một điều kiện bắt đầu cuộc trò chuyện, tác nhân đó sẽ nhận được nội dung định sẵn và dữ liệu đăng lại mà bạn đã thiết lập khi chỉ định điều kiện khởi động.

Nếu một tác nhân hỗ trợ chức năng tự động cho một số yêu cầu nhất định, thì nội dung bắt đầu cuộc trò chuyện có thể ánh xạ đến các yêu cầu đó, cho phép bạn dựa vào các thông tin đầu vào đã biết để tự động hoá và gửi câu hỏi của người dùng ở dạng tự do đến các nhân viên hỗ trợ đang sẵn sàng trả lời.

Một nhân viên hỗ trợ có thể có tối đa 5 người bắt đầu cuộc trò chuyện và mỗi điều kiện khởi động có thể có tối đa 35 ký tự.

Để thêm hoặc chỉnh sửa cụm từ bắt đầu cuộc trò chuyện, hãy xem phần Cập nhật chế độ cài đặt cuộc trò chuyện.

Tin nhắn ngoại tuyến

Khi người dùng bắt đầu cuộc trò chuyện với một nhân viên hỗ trợ ngoài giờ hoạt động của nhân viên hỗ trợ đó (do MessagingAvailability xác định), người dùng sẽ nhận được tin nhắn ngoại tuyến của nhân viên hỗ trợ đó. Chỉ xem xét phạm vi cung cấp đại diện do con người cung cấp khi kích hoạt thông báo ngoại tuyến. Các nhân viên hỗ trợ chỉ có người đại diện cho bot luôn gửi tin nhắn chào mừng. Tin nhắn ngoại tuyến hay

  • Chia sẻ lý do nhân viên hỗ trợ không làm việc
  • Hướng dẫn người dùng các bước tiếp theo thích hợp hoặc các kênh liên hệ thay thế
  • Khớp với giọng điệu của tin nhắn chào mừng và câu mở đầu cuộc trò chuyện

Tin nhắn không thành công khi không có mạng

"Rất tiếc, chúng tôi đã đóng cửa."

Thư phù hợp khi không có mạng

"Chúng tôi hiện đóng cửa nhưng chúng tôi sẽ làm việc lại lúc 8 giờ sáng mai. Nếu bạn cần hỗ trợ khẩn cấp, hãy liên hệ với bộ phận Hỗ trợ theo số +12223334444 hoặc support@gtb.com."

Để chỉnh sửa tin nhắn ngoại tuyến, hãy xem phần Cập nhật chế độ cài đặt trò chuyện.

Cập nhật chế độ cài đặt trò chuyện

Để quản lý tin nhắn chào mừng hoặc các câu bắt đầu cuộc trò chuyện, bạn cần đưa ra yêu cầu PATCH bằng Business Communications API để cập nhật trường conversationalSettings của một nhân viên hỗ trợ hoặc vị trí.

Khi cập nhật trường conversationalSettings, bạn phải cung cấp giá trị cho tất cả các trường trong đối tượng ConversationalSetting. Yêu cầu cập nhật sẽ ghi đè nội dung của tất cả các trường mà bạn chỉnh sửa, bao gồm cả bất kỳ trường con nào. Ví dụ: nếu bạn yêu cầu sửa đổi tin nhắn chào mừng nhưng không thêm cụm từ bắt đầu cuộc trò chuyện, thì yêu cầu này sẽ xoá mọi cụm từ bắt đầu cuộc trò chuyện trước đó.

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

Trước khi cập nhật các chế độ cài đặt trò chuyện, bạn cần có các mục sau:

  • Đường dẫn đến khoá tài khoản dịch vụ của dự án GCP trên máy phát triển của bạn
  • Ngôn ngữ mà bạn muốn cập nhật chế độ cài đặt
  • Đối với các chế độ cài đặt ở cấp nhân viên hỗ trợ, nhân viên hỗ trợ name (ví dụ: "brands/12345/agents/67890")

    Nếu bạn không biết name của tác nhân, hãy xem phần Liệt kê tất cả các nhân viên hỗ trợ cho một thương hiệu.

  • Đối với chế độ cài đặt cấp vị trí, hãy chọn vị trí name (ví dụ: "brands/12345/locations/67890")

    Nếu bạn không biết name của vị trí, hãy xem bài viết Liệt kê tất cả các vị trí cho một thương hiệu.

  • Ngôn ngữ cần cập nhật, dưới dạng mã ngôn ngữ ISO 639-1 gồm hai ký tự

  • Tin nhắn chào mừng mới

  • URL chính sách quyền riêng tư

  • (Không bắt buộc) Nội dung dành cho người bắt đầu cuộc trò chuyện

  • (Không bắt buộc) Dữ liệu đăng lại để bắt đầu cuộc trò chuyện

  • (Không bắt buộc) Thư ngoại tuyến mới

Nếu bạn không biết các giá trị conversationalSettings hiện tại, hãy xem phần Nhận thông tin về nhân viên hỗ trợNhận thông tin vị trí.

Gửi yêu cầu cập nhật

Để cập nhật nhân viên hỗ trợ hoặc vị trí, hãy chạy lệnh sau. Thay thế biến bằng các giá trị bạn đã xác định trong Điều kiện tiên quyết.

Nếu bạn không muốn bắt đầu cuộc trò chuyện, hãy bỏ qua conversationStarters và tất cả các trường con của nó.

Chế độ cài đặt ở cấp nhân viên hỗ trợ

cURL


# This code updates the conversational settings of a Business Messages agent.
# Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/patch

# Replace the __BRAND_ID__, __AGENT_ID__ and __LOCALE__
# 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__?updateMask=businessMessagesAgent.conversationalSettings.__LOCALE__" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/business-communications" \
-H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \
-d '{
  "businessMessagesAgent": {
    "conversationalSettings": {
      "__LOCALE__": {
        "welcomeMessage": {
          "text": "My first welcome message"
        },
        "offlineMessage": {
          "text": "My first offline message"
        },
        "privacyPolicy": {
          "url": "https://www.your-company-website.com/privacy"
        },
        "conversationStarters": [
          {
            "suggestion": {
              "reply": {
                "text": "Suggestion 1",
                "postbackData": "post_back_suggestion_1"
              }
            }
          }
        ]
      }
    }
  }
}'

Node.js


/**
 * This code snippet updates the conversationalSettings of a Business Messages agent.
 * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/patch
 *
 * 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 LOCALE = 'en';
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 agentName = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID;

  if (authClient) {
    // Setup the parameters for the API call
    const apiParams = {
      auth: authClient,
      name: agentName,
      updateMask: 'businessMessagesAgent.conversationalSettings.' + LOCALE,
      resource: {
        businessMessagesAgent: {
          conversationalSettings: {
            [LOCALE]: {
              privacyPolicy: { url: 'https://www.your-company-website.com/privacy' },
              welcomeMessage: { text: 'My updated welcome message' },
              offlineMessage: { text: 'My updated offline message' },
              conversationStarters: [
                {
                  suggestion: {
                    reply: {
                      'text': 'Suggestion 2',
                     'postbackData': 'post_back_suggestion_2',
                    },
                  },
                }
              ],
            },
          }
        }
      }
    };

    bcApi.brands.agents.patch(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();

Java

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.businesscommunications.v1.BusinessCommunications;
import com.google.api.services.businesscommunications.v1.model.*;
import com.google.common.collect.ImmutableMap;
import java.io.FileInputStream;
import java.util.Arrays;

class Main {
  /**
   * Initializes credentials used by the Business Communications API.
   */
  private static BusinessCommunications.Builder getBusinessCommunicationsBuilder() {
    BusinessCommunications.Builder builder = null;
    try {
      GoogleCredential credential = GoogleCredential
            .fromStream(new FileInputStream("PATH_TO_SERVICE_ACCOUNT_KEY"));

      credential = credential.createScoped(Arrays.asList(
          "https://www.googleapis.com/auth/businesscommunications"));

      credential.refreshToken();

      HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
      JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();

      // Create instance of the Business Communications API
      builder = new BusinessCommunications
          .Builder(httpTransport, jsonFactory, null)
          .setApplicationName(credential.getServiceAccountProjectId());

      // Set the API credentials and endpoint
      builder.setHttpRequestInitializer(credential);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return builder;
  }

  public static void main(String args[]) {
    try {
      // Create client library reference
      BusinessCommunications.Builder builder = getBusinessCommunicationsBuilder();

      String agentName = "brands/BRAND_ID/agents/AGENT_ID";

      Agent agent = new Agent().setBusinessMessagesAgent(
          new BusinessMessagesAgent().setConversationalSettings(ImmutableMap.of("LOCALE",
              new ConversationalSetting()
                  .setPrivacyPolicy(new PrivacyPolicy().setUrl("PRIVACY_POLICY_URL"))
                  .setWelcomeMessage(new WelcomeMessage().setText("WELCOME_MESSAGE"))
                  .setOfflineMessage(new OfflineMessage().setText("OFFLINE_MESSAGE"))
                  .setConversationStarters(Arrays.asList(
                      new ConversationStarters().setSuggestion(new Suggestion()
                          .setReply(new SuggestedReply()
                              .setText("REPLY_TEXT")
                              .setPostbackData("POSTBACK_DATA"))),
                      )))));

      BusinessCommunications.Brands.Agents.Patch request = builder
          .build().brands().agents().patch(agentName, agent);

      request.setUpdateMask("businessMessagesAgent.conversationalSettings.LOCALE");

      Agent updatedAgent = request.execute();
      System.out.println(updatedAgent.toPrettyString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Mã này dựa trên thư viện khách hàng Java Business Communications.

Python


"""This code updates the conversational settings of a Business Messages agent.

Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/patch

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,
    BusinessMessagesAgent,
    ConversationStarters,
    ConversationalSetting,
    OfflineMessage,
    PrivacyPolicy,
    WelcomeMessage,
    NegativeBotFeedbackMessage,
    BusinesscommunicationsBrandsAgentsPatchRequest,
)

# 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)

agents_service = BusinesscommunicationsV1.BrandsAgentsService(client)

agent_name = 'brands/' + BRAND_ID + '/agents/' + AGENT_ID

agent=Agent(
                businessMessagesAgent=BusinessMessagesAgent(
                        conversationalSettings=BusinessMessagesAgent.ConversationalSettingsValue(
                        additionalProperties=[BusinessMessagesAgent.ConversationalSettingsValue.AdditionalProperty(
                            key='en',
                            value=ConversationalSetting(
                                privacyPolicy=PrivacyPolicy(url='https://www.your-company-website.com/privacy'),
                                welcomeMessage=WelcomeMessage(text='Welcome to Business Messages'),
                            offlineMessage=OfflineMessage(text='This is an offline message'),
                                conversationStarters=[
                                    ConversationStarters(
                                        suggestion=Suggestion(
                                           reply=SuggestedReply(text='Option 1',
                                  postbackData='option_1')
                                        )
                                    )]
                                )
                            )
                        ]
                    )
                )
)

updated_agent = agents_service.Patch(
        BusinesscommunicationsBrandsAgentsPatchRequest(
            agent=agent,
            name=agent_name,
            updateMask='businessMessagesAgent.conversationalSettings.en'
        )
    )

print(updated_agent)

Cài đặt cấp vị trí


# This code updates the agent interaction of a bot and human representatives.
# Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/patch

# Replace the __BRAND_ID__, __AGENT_ID__, __LOCATION_ID__, __LOCALE__
# Make sure a service account key file exists at ./service_account_key.json

curl -X PATCH \
"https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/locations/__LOCATION_ID__?updateMask=conversationalSettings.__LOCALE__" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/business-communications" \
-H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \
-d '{
  "conversationalSettings": {
    "__LOCALE__": {
      "welcomeMessage": {
        "text": "My second welcome message"
      },
      "offlineMessage": {
        "text": "My second offline message"
      },
      "privacyPolicy": {
        "url": "https://www.your-company-website.com/privacy"
      },
      "conversationStarters": [
        {
          "suggestion": {
            "reply": {
              "text": "Suggestion 2",
              "postbackData": "post_back_suggestion_2"
            }
          }
        }
      ]
    }
  }
}'

Để biết thông tin về định dạng và giá trị, hãy xem brands.agents.patch, brands.locations.patchConversationalSetting.

Ví dụ

Chế độ cài đặt ở cấp nhân viên hỗ trợ

curl -X PATCH \
"https://businesscommunications.googleapis.com/v1/brands/BRAND_ID/agents/AGENT_ID?updateMask=businessMessagesAgent.conversationalSettings.en" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/business-communications" \
-H "$(oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY businesscommunications)" \
-d "{
    'businessMessagesAgent': {
        'conversationalSettings': {
            'en': {
                'welcomeMessage': {
                    'text': 'Thanks for contacting Growing Tree Bank. What can I help with today?',
                },
                'offlineMessage': {
                    'text': 'We\'re closed for the night. Please reach out to us again tomorrow.',
                },
                'privacyPolicy': {
                    'url': 'https://www.growingtreebank.com/privacy',
                },
                'conversationStarters': [
                    {
                        'suggestion': {
                            'reply': {
                                'text': 'Set up an account',
                                'postbackData': 'new-account',
                            },
                        },
                    },
                    {
                        'suggestion': {
                            'reply': {
                                'text': 'Look up account information',
                                'postbackData': 'account-lookup',
                            },
                        },
                    },
                ],
            },
        },
    },
}"

Cài đặt cấp vị trí

curl -X PATCH \
"https://businesscommunications.googleapis.com/v1/brands/12345/locations/67890?updateMask=conversationalSettings.en" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/business-communications" \
-H "$(oauth2l header --json /path/to/service/account/key businesscommunications)" \
-d "{
    'conversationalSettings': {
        'en': {
            'welcomeMessage': {
                'text': 'Thanks for contacting Growing Tree Bank on Amphitheatre Pkwy. What can I help with today?',
            },
            'offlineMessage': {
                'text': 'We\'re closed for the night. Please reach out to us again tomorrow.',
            },
            'privacyPolicy': {
                'url': 'https://www.growingtreebank.com/privacy',
            },
            'conversationStarters': [
                {
                    'suggestion': {
                        'reply': {
                            'text': 'What are your hours?',
                            'postbackData': 'hours',
                        },
                    },
                },
                {
                    'suggestion': {
                        'reply': {
                            'text': 'Set up an account',
                            'postbackData': 'new-account',
                        },
                    },
                },
                {
                    'suggestion': {
                        'reply': {
                            'text': 'Look up account information',
                            'postbackData': 'account-lookup',
                        },
                    },
                },
                {
                    'suggestion': {
                        'action': {
                            'text': 'Call us',
                            'postbackData': 'call',
                            'dialAction': {
                              'phoneNumber': '+12223334444',
                            },
                        },
                    },
                },
            ],
        },
    },
}"