Wszyscy agenci należą do marki (firmy, organizacji lub grupy). Zanim będzie można utworzyć agenta, trzeba utworzyć własną markę. Marki są czysto organizacyjne, aby ułatwiać grupowanie powiązanych agentów.
Fragmenty kodu widoczne na tej stronie pochodzą z przykładów w języku Java i przykładów Node.js.
Tworzenie marki
Marka ma displayName
i unikalny identyfikator 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());
Ten kod zwraca informacje o nowej marce i unikalny identyfikator przypisany do niej:
{
name: 'brands/17456b6b-65dc-4e35-b128-fd3047664ddf',
displayName: 'My new brand'
}
Pobierz markę
Markę można pobrać za pomocą jej unikalnego identyfikatora (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); });
Java
Brand brand = api.getBrand(brandId); logger.info("Brand: " + brand);
Ten kod zwraca informacje o marce:
{
name: 'brands/17456b6b-65dc-4e35-b128-fd3047664ddf',
displayName: 'My new brand'
}
Wyświetlenie listy marek
Możesz pobrać listę wszystkich utworzonych do tej pory marek.
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())); }
Ten kod zwraca listę wszystkich Twoich marek:
{
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'
}
]
}
Zmienianie nazwy marki
Wyświetlaną nazwę marki można zmienić za pomocą operacji 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); });
Ten kod zwraca zaktualizowane informacje o marce:
{
name: 'brands/40bd963f-ff92-425c-b273-8f0892d2d017',
displayName: 'My brands new name'
}