Quản lý thương hiệu

Tất cả nhân viên đều thuộc một thương hiệu (doanh nghiệp, tổ chức hoặc nhóm). Trước khi có thể tạo một đại lý, bạn cần tạo một thương hiệu sở hữu. Thương hiệu chỉ là một tính năng giúp bạn sắp xếp các nhân viên hỗ trợ có liên quan với nhau.

Các đoạn mã trên trang này được lấy từ mẫu Javamẫu Node.js.

Tạo thương hiệu

Bạn có thể tạo một thương hiệu mới. Để biết thêm thông tin, hãy xem brandsbrands.create.

Node.js

const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper.createBrand('My new brand').then((response) => {
	console.log('The new brand is:');
	console.log(response.data);
}).catch((err) => {
	console.log(err);
});

Java.js

String displayName = flags.getOrDefault("brand_name", "Test brand: " + now.getSecond());
Brand brand = api.createBrand(displayName);
logger.info("New brand id: " + brand.getName());

Mã này trả về tên thương hiệu mới (displayName) và giá trị nhận dạng duy nhất (name) được chỉ định cho thương hiệu:

{
  name: 'brands/17456b6b-65dc-4e35-b128-fd3047664ddf',
  displayName: 'My new brand'
}

Truy xuất thương hiệu

Bạn có thể truy xuất thông tin về một thương hiệu bằng mã nhận dạng duy nhất của thương hiệu đó (name). Để biết thêm thông tin chi tiết, hãy xem brands.get.

Node.js

const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper.getBrand(brandId).then((response) => {
  console.log('Brand details are:');
  console.log(response.data);
}).catch((err) => {
  console.log(err);
});

Java

Brand brand = api.getBrand(brandId);
logger.info("Brand: " + brand);

Mã này trả về thông tin thương hiệu:

{
  name: 'brands/17456b6b-65dc-4e35-b128-fd3047664ddf',
  displayName: 'My new brand'
}

Liệt kê thương hiệu

Bạn có thể truy xuất danh sách tất cả thương hiệu mà bạn đã tạo. Để biết thêm thông tin, hãy xem brands.list.

Node.js

const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper.listBrands().then((response) => {
  console.log('Current brands available are:');
  console.log(response.data);
}).catch((err) => {
  console.log(err);
});

Java

List<Brand> brands = api.listBrands().stream().sorted(Comparator.comparing(Brand::getName))
  .collect(Collectors.toList());
logger.info(String.format("Found %d brands", brands.size()));
for (Brand brand : brands) {
  logger.info(String.format("Brand [%s]: '%s'", brand.getName(), brand.getDisplayName()));
}

Mã này trả về danh sách tất cả thương hiệu của bạn:

{
  brands: [
    {
      name: 'brands/1deb6297-8a57-474a-a02c-48529a3de0a0',
      displayName: 'My brand'
    },
    {
      name: 'brands/3b607982-8c06-467a-96b8-020ddc26ac83',
      displayName: 'My second brand'
    },
    {
      name: 'brands/40bd963f-ff92-425c-b273-8f0892d2d017',
      displayName: 'My thrd brand'
    }
  ]
}

Đổi tên thương hiệu

Bạn có thể thay đổi tên hiển thị của thương hiệu. Để biết thêm thông tin, hãy xem brands.patch.

Bạn có thể thay đổi tên hiển thị của thương hiệu bằng cách sử dụng toán tử patch:

Node.js

const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper
  .patchBrand(brand.name, 'My brand new name').then((response) => {
    console.log(response.data);
});

Mã này trả về thông tin thương hiệu đã cập nhật:

{
  name: 'brands/40bd963f-ff92-425c-b273-8f0892d2d017',
  displayName: 'My brands new name'
}