Thêm vị trí

Nếu thương hiệu mà nhân viên hỗ trợ đại diện cho bạn có địa điểm thực tế, thì bạn có thể liên kết các vị trí đó với nhân viên hỗ trợ để người dùng có thể nhắn tin cho các vị trí cụ thể bằng Business Messages. Tính năng Business Messages xác định các vị trí theo Mã địa điểm.

Với mã địa điểm, bạn có thể xác định vị trí thực tế mà người dùng thông báo và xác định hành động tốt nhất để phản hồi người dùng.

Bạn phải xác nhận quyền sở hữu các địa điểm thực tế thông qua Trang doanh nghiệp trước khi có thể liên kết các địa điểm với một đại lý Business Messages.

Quản lý nhiều vị trí

Nếu thương hiệu là một phần của chuỗi, thì bạn phải thêm tất cả các vị trí cho chuỗi đó để có thể bật tính năng nhắn tin. Để xác minh tất cả vị trí trong chuỗi, bạn sẽ tạo một yêu cầu xác minh duy nhất cho một vị trí. Sau khi xác minh vị trí đó, chúng tôi sẽ tự động xác minh những vị trí liên kết khác mà bạn đã thêm.

Sau khi xác minh, nếu bạn thêm vị trí bổ sung, bạn sẽ cần yêu cầu xác minh lại vị trí.

Để xem các vị trí liên kết với nhân viên hỗ trợ, hãy xem phần Liệt kê tất cả các vị trí của một thương hiệu và lọc kết quả theo giá trị agent.

Tạo vị trí

Để thêm vị trí vào một nhân viên hỗ trợ, bạn cần gửi yêu cầu bằng API truyền thông doanh nghiệp để tạo vị trí thương hiệu và liên kết nhân viên hỗ trợ đó bằng cách thêm giá trị name của nhân viên hỗ trợ vào vị trí.

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

Trước khi tạo vị trí, bạn cần thu thập một số mục:

Tạo vị trí

Sau khi thu thập thông tin, bạn sẽ tạo vị trí cho ứng dụng. Ở một thiết bị đầu cuối, hãy chạy lệnh sau.

Thay thế các biến được đánh dấu bằng các giá trị mà bạn đã xác định trong Điều kiện tiên quyết. Thay thế BRAND_ID bằng một phần trong giá trị name của thương hiệu đứng sau "brands/". Ví dụ: nếu name là "brands/12345", thì mã thương hiệu là "12345".

URL


# This code creates a location where a brand is available.
# Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/create

# Replace the __BRAND_ID__ and __PLACE_ID__
# Make sure a service account key file exists at ./service_account_key.json

curl -X POST "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/locations" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/business-communications" \
-H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \
-d '{
  "placeId": "__PLACE_ID__",
  "agent": "brands/__BRAND_ID__/agents/__AGENT_ID__",
  "defaultLocale": "en",
}'

Node.js


/**
 * This code snippet creates a location.
 * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/create
 *
 * 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 PLACE_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 brandName = 'brands/' + BRAND_ID;
  const agentName = 'brands/' + BRAND_ID + 'agents/' + AGENT_ID;

  if (authClient) {
    const locationObject = {
      placeId: PLACE_ID,
      agent: agentName,
      defaultLocale: 'en',
    };

    // setup the parameters for the API call
    const apiParams = {
      auth: authClient,
      parent: brandName,
      resource: locationObject,
    };

    bcApi.brands.locations.create(apiParams, {}, (err, response) => {
      if (err !== undefined && err !== null) {
        console.dir(err);
      } else {
        // Location 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();

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.Location;
import com.google.common.collect.ImmutableMap;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.UUID;

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 brandName = "brands/BRAND_ID";

      BusinessCommunications.Brands.Locations.Create request = builder
          .build().brands().locations().create(brandName,
              new Location()
                  .setDefaultLocale("LOCALE")
                  .setAgent("FULL_AGENT_NAME")
                  .setPlaceId("PLACE_ID"));

      Location location = request.execute();

      System.out.println(location.toPrettyString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Mã này dựa trên thư viện ứng dụng Truyền thông doanh nghiệp của Java.

Python


"""This code creates a location where a brand is available.

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

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 (
    BusinesscommunicationsBrandsLocationsCreateRequest,
    Location
)

# Edit the values below:
BRAND_ID = 'EDIT_HERE'
AGENT_ID = 'EDIT_HERE'
PLACE_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)

locations_service = BusinesscommunicationsV1.BrandsLocationsService(client)

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

location = locations_service.Create(BusinesscommunicationsBrandsLocationsCreateRequest(
        location=Location(
            agent=agent_name,
            placeId=PLACE_ID,
            defaultLocale='en'
        ),
        parent=brand_name
    ))

print(location)

Để biết các tùy chọn định dạng và giá trị, hãy xem brands.locations.create.

Sau khi bạn tạo vị trí, API Business Messages xác định các vị trí liên kết khác và tạo vị trí cho cùng một thương hiệu và đại lý.

Thông tin cửa hàng

Khi bạn tạo một vị trí, API Business Messages trả về các giá trị của vị trí, bao gồm cả nametestUrls.

Lưu trữ name ở một nơi mà bạn có thể truy cập. Bạn cần có name để cập nhật vị trí.

Thử nghiệm một vị trí

Mỗi nhân viên hỗ trợ có các URL thử nghiệm cho phép bạn xem cách cuộc trò chuyện với nhân viên hỗ trợ đó hiển thị cho người dùng và cho bạn cơ hội xác minh cơ sở hạ tầng nhắn tin.

TestUrl có thuộc tính urlsurface. Để kiểm tra URL vị trí trên thiết bị iOS, hãy sử dụng URL thử nghiệm có giá trị bề mặt là SURFACE_IOS_MAPS. Việc mở URL trên thiết bị iOS đã cài đặt ứng dụng Google Maps sẽ mở ra một cuộc trò chuyện đầy đủ chức năng với nhân viên hỗ trợ liên kết.

Thiết bị Android có 2 URL kiểm thử. Các URL có giá trị surface cuộc trò chuyện mở SURFACE_ANDROID_MAPS trong Google Maps và đại diện cho các điểm truy cập xuất hiện trong Google Maps. Các URL có giá trị surfaceSURFACE_ANDROID_WEB cuộc trò chuyện đang mở trong chế độ xem cuộc trò chuyện lớp phủ và đại diện cho tất cả điểm truy cập khác.

Sau khi giao diện trò chuyện mở ra, cuộc trò chuyện sẽ bao gồm tất cả thông tin thương hiệu mà người dùng sẽ thấy, và khi bạn gửi tin nhắn cho nhân viên hỗ trợ, webhook của bạn sẽ nhận được tin nhắn, bao gồm cả trọng tải JSON đầy đủ mà bạn có thể mong đợi khi giao tiếp với người dùng. Thông tin vị trí xuất hiện trong trường context.

Để mở URL thử nghiệm của một vị trí, hãy nhấn vào đường liên kết hoặc sử dụng Trình chạy tác nhân của Business Messages. Bạn không thể sao chép và dán hoặc điều hướng theo cách thủ công đến một URL thử nghiệm do các biện pháp bảo mật của trình duyệt.

Nhận thông tin vị trí

Để nhận thông tin về một vị trí, chẳng hạn như locationTestUrl, bạn có thể lấy thông tin từ API Business Messages, miễn là bạn có giá trị name của vị trí đó.

Tìm thông tin về một vị trí

Để nhận thông tin vị trí, hãy chạy lệnh sau. Thay thế BRAND_IDLOCATION_ID bằng các giá trị duy nhất từ name của vị trí.

URL


# This code gets the location where a brand is available.
# Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/get

# Replace the __BRAND_ID__ and __LOCATION_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__/locations/__LOCATION_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 the location of a brand.
 * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/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 BRAND_ID = 'EDIT_HERE';
const LOCATION_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();

  if (authClient) {
    const apiParams = {
      auth: authClient,
      name: 'brands/' + BRAND_ID + '/locations/' + LOCATION_ID,
    };

    bcApi.brands.locations.get(apiParams, {}, (err, response) => {
      if (err !== undefined && err !== null) {
        console.dir(err);
      } else {
        // Location 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.Location;
import com.google.common.collect.ImmutableMap;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.UUID;

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();

      BusinessCommunications.Brands.Locations.Get request = builder
          .build().brands().locations().get("brands/BRAND_ID/locations/LOCATION_ID");

      Location location = request.execute();

      System.out.println(location.toPrettyString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Mã này dựa trên thư viện ứng dụng Truyền thông doanh nghiệp của Java.

Python


"""This code gets the location where a brand is available.

Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/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 (
    BusinesscommunicationsBrandsLocationsGetRequest,
    Location
)

# Edit the values below:
BRAND_ID = 'EDIT_HERE'
LOCATION_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)

locations_service = BusinesscommunicationsV1.BrandsLocationsService(client)

location_name = 'brands/' + BRAND_ID + '/locations/' + LOCATION_ID

location = locations_service.Get(
        BusinesscommunicationsBrandsLocationsGetRequest(name=location_name)
    )

print(location)

Để biết các tùy chọn định dạng và giá trị, hãy xem brands.locations.get.

Liệt kê tất cả các vị trí của một thương hiệu

Nếu không biết name của các vị trí, bạn có thể nhận thông tin cho tất cả tác nhân liên kết với một thương hiệu bằng cách bỏ qua giá trị LOCATION_ID khỏi URL yêu cầu GET.

URL


# This code gets all locations where a brand is available.
# Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/list

# Replace the __BRAND_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__/locations/" \
-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 the locations of a brand.
 * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/list
 *
 * 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 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();

  if (authClient) {
    const apiParams = {
      auth: authClient,
      parent: 'brands/' + BRAND_ID,
    };

    bcApi.brands.locations.list(apiParams, {}, (err, response) => {
      if (err !== undefined && err !== null) {
        console.dir(err);
      } else {
        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.Location;
import com.google.common.collect.ImmutableMap;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.UUID;

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();

      BusinessCommunications.Brands.Locations.List request
          = builder.build().brands().locations().list("brands/BRAND_ID");

      List locations = request.execute().getLocations();
      locations.stream().forEach(location -> {
        try {
          System.out.println(location.toPrettyString());
        } catch (IOException e) {
          e.printStackTrace();
        }
      });
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Mã này dựa trên thư viện ứng dụng Truyền thông doanh nghiệp của Java.

Python


"""This code gets all locations where a brand is available.

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

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 (
    BusinesscommunicationsBrandsLocationsListRequest,
    Location
)

# Edit the values below:
BRAND_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)

locations_service = BusinesscommunicationsV1.BrandsLocationsService(client)

location_name = 'brands/' + BRAND_ID + '/locations'

locations = locations_service.List(
        BusinesscommunicationsBrandsLocationsListRequest(name=location_name)
    )

print(locations)

Để biết các tùy chọn định dạng và giá trị, hãy xem brands.locations.list.

Cập nhật địa điểm

Để cập nhật vị trí, bạn thực hiện yêu cầu PATCH với API giao tiếp của doanh nghiệp. Khi thực hiện lệnh gọi API, bạn sẽ bao gồm tên của các trường bạn đang chỉnh sửa dưới dạng giá trị cho tham số URL "updateMask".

Ví dụ: nếu bạn cập nhật các trường defaultLocale và các tác nhân mặc định, thì tham số URL "updateMask" sẽ là "updateMask=defaultLocale,agent".

Để biết các tùy chọn định dạng và giá trị, hãy xem brands.locations.patch.

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

Ví dụ: Cập nhật ngôn ngữ mặc định

URL


# This code updates the default locale of an agent.
# Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/patch

# Replace the __BRAND_ID__ and __LOCATION_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__/locations/__LOCATION_ID__?updateMask=defaultLocale" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/business-communications" \
-H "$(oauth2l header --json ./service_account_key.json businesscommunications)" \
-d '{
  "defaultLocale": "en"
}'

Node.js


/**
 * This code snippet updates the defaultLocale of a Business Messages agent.
 * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/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 LOCATION_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();

  if (authClient) {
    const locationObject = {
      defaultLocale: 'en'
    };

    const apiParams = {
      auth: authClient,
      name: 'brands/' + BRAND_ID + '/locations/' + LOCATION_ID,
      resource: locationObject,
      updateMask: 'defaultLocale',
    };

    bcApi.brands.locations.patch(apiParams, {}, (err, response) => {
      if (err !== undefined && err !== null) {
        console.dir(err);
      } else {
        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.Location;
import com.google.common.collect.ImmutableMap;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.UUID;

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();

      BusinessCommunications.Brands.Locations.Patch request =
          builder.build().brands().locations().patch("brands/BRAND_ID/locations/LOCATION_ID",
            new Location()
                .setDefaultLocale("en"));

      request.setUpdateMask("defaultLocale");

      Location location = request.execute();

      System.out.println(location.toPrettyString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Mã này dựa trên thư viện ứng dụng Truyền thông doanh nghiệp của Java.

Python


"""This code updates the default locale of an agent.

Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/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 (
    BusinesscommunicationsBrandsLocationsPatchRequest,
    Location
)

# Edit the values below:
BRAND_ID = 'EDIT_HERE'
LOCATION_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)

locations_service = BusinesscommunicationsV1.BrandsLocationsService(client)

location = Location(defaultLocale='US')

location_name = 'brands/' + BRAND_ID + '/locations/' + LOCATION_ID

updated_location = locations_service.Patch(
        BusinesscommunicationsBrandsLocationsPatchRequest(
            location=location,
            name=location_name,
            updateMask='defaultLocale'
        )
    )

print(updated_location)

Xóa vị trí

Khi bạn xoá một nhân viên hỗ trợ, Business Messages sẽ xoá tất cả dữ liệu vị trí. Tính năng Business Messages không xoá các tin nhắn do nhân viên hỗ trợ gửi liên quan đến vị trí đang chuyển đến hoặc được lưu trữ trên thiết bị của người dùng. Thông báo cho người dùng không phải là dữ liệu vị trí.

Yêu cầu xoá không thành công nếu bạn đã cố gắng xác minh vị trí một hoặc nhiều lần. Để xoá một vị trí mà bạn đã xác minh hoặc tìm cách xác minh, hãy hãy liên hệ với chúng tôi. (Trước tiên, bạn phải đăng nhập bằng Tài khoản Google Business Messages. Để đăng ký tài khoản, hãy xem phần Đăng ký bằng Business Messages.)

Để xóa vị trí, hãy chạy lệnh sau. Thay thế BRAND_IDLOCATION_ID bằng các giá trị duy nhất từ name của vị trí.

URL


# This code deletes a location where a brand is available.
# Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/delete

# Replace the __BRAND_ID__ and __LOCATION_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__/locations/__LOCATION_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 a location.
 * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/delete
 *
 * 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 LOCATION_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();

  if (authClient) {
    const apiParams = {
      auth: authClient,
      name: 'brands/' + BRAND_ID + '/locations/' + LOCATION_ID,
    };

    bcApi.brands.locations.delete(apiParams, {}, (err, response) => {
      if (err !== undefined && err !== null) {
        console.dir(err);
      } else {
        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.common.collect.ImmutableMap;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.UUID;

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();

      BusinessCommunications.Brands.Locations.Delete request = builder.build().brands().locations()
          .delete("brands/BRAND_ID/locations/LOCATION_ID");

      System.out.println(request.execute().toPrettyString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
Mã này dựa trên thư viện ứng dụng Truyền thông doanh nghiệp của Java.

Python


"""This code deletes a location where a brand is available.

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

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 (
    BusinesscommunicationsBrandsLocationsDeleteRequest,
    LocationEntryPointConfig,
    Location
)

# Edit the values below:
BRAND_ID = 'EDIT_HERE'
LOCATION_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)

locations_service = BusinesscommunicationsV1.BrandsLocationsService(client)

location_name = 'brands/' + BRAND_ID + '/locations/' + LOCATION_ID

location = locations_service.Delete(BusinesscommunicationsBrandsLocationsDeleteRequest(
        name=location_name
    ))

print(location)

Để biết các tùy chọn định dạng và giá trị, hãy xem brands.locations.delete.

Các bước tiếp theo

Bây giờ, khi đã có một nhân viên hỗ trợ về vị trí, bạn có thể thiết kế quy trình nhắn tin.