ניהול המותגים

כל הנציגים שייכים למותג (עסק, ארגון או קבוצה). לפני שיוצרים סוכן, צריך ליצור מותג בעלות. המותגים הם רק ארגוניים ועוזרים לקבץ סוכנים קשורים.

קטעי הקוד בדף הזה נלקחו מדוגמאות Java ודוגמאות Node.js.

יצירת מותג

אפשר ליצור מותג חדש. פרטים נוספים זמינים במאמרים brands וbrands.create.

cURL

curl -v -X POST "https://businesscommunications.googleapis.com/v1/brands" \
  -H "Content-Type: application/json" \
  -H "User-Agent: curl/business-messaging" \
  -H "`oauth2l header --json rbm-developer-service-account-credentials.json businesscommunications`" \
  -d "{
    'name': 'Test Brand',
    'displayName': 'Test Brand'
  }"
הקוד הזה הוא קטע מתוך דוגמה ל-RBM Management API.

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

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

הקוד הזה מחזיר את שם המותג החדש (displayName) ומזהה ייחודי (name) שהוקצה למותג:

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

אחזור מותג

אפשר לאחזר מידע על מותג באמצעות המזהה הייחודי שלו (name). פרטים נוספים זמינים במאמר brands.get.

cURL

curl -v "https://businesscommunications.googleapis.com/v1/$BRAND_ID" \
  -H "Content-Type: application/json" \
  -H "User-Agent: curl/business-messaging" \
  -H "`oauth2l header --json rbm-developer-service-account-credentials.json businesscommunications`"
הקוד הזה הוא קטע מתוך דוגמה ל-RBM Management API.

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

הקוד הזה מחזיר את פרטי המותג:

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

רשימת מותגים

אתם יכולים לאחזר רשימה של כל המותגים שיצרתם. פרטים נוספים זמינים במאמר brands.list.

cURL

curl -v "https://businesscommunications.googleapis.com/v1/brands" \
  -H "Content-Type: application/json" \
  -H "User-Agent: curl/business-messaging" \
  -H "`oauth2l header --json rbm-developer-service-account-credentials.json businesscommunications`"
הקוד הזה הוא קטע מתוך דוגמה ל-RBM Management API.

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

הקוד הזה מחזיר רשימה של כל המותגים שלכם:

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

שינוי שם של מותג

אתם יכולים לשנות את השם המוצג של המותג. פרטים נוספים זמינים במאמר brands.patch.

אפשר לשנות את השם המוצג של המותג באמצעות הפעולה 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'
}