Управляйте брендами, Управляйте брендами

Все агенты принадлежат бренду (бизнесу, организации или группе). Прежде чем создать агента, необходимо создать собственный бренд. Бренды носят чисто организационный характер и помогают группировать связанных агентов вместе.

Фрагменты кода на этой странице взяты из примеров Java и примеров Node.js.

Создать бренд

Бренд имеет displayName и уникальный идентификатор name .

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

Этот код возвращает новую информацию о бренде и уникальный идентификатор, присвоенный бренду:

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

Получить бренд

Бренд можно получить по его уникальному идентификатору ( name ).

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

Джава

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

Этот код возвращает информацию о бренде:

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

Список брендов

Вы можете получить список всех брендов, которые вы создали на данный момент.

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

Джава

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

Этот код возвращает список всех ваших брендов:

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

Переименуйте бренд

Отображаемое название бренда можно изменить с помощью операции 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);
});

Этот код возвращает обновленную информацию о бренде:

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