地域を追加する

代理店が代理を務めるブランドに実店舗がある場合は、そのビジネス情報をエージェントに関連付けることで、ユーザーがビジネス メッセージで特定の店舗にメッセージを送信できます。ビジネス メッセージは、場所 ID によってビジネス情報を識別します。

場所 ID を使って、ユーザーがメッセージを発する場所を特定し、ユーザーへの対応方法を選択できます。

ビジネスをビジネス メッセージ エージェントに関連付ける前に、ビジネス プロフィールを使用して物理的なビジネスのオーナー権限を申請する必要があります。

複数のビジネス情報を管理する

ブランドがチェーンの一部である場合は、そのチェーンでメッセージを有効にする権限があるすべての場所を追加する必要があります。チェーン内のすべてのビジネスを確認するには、1 つのビジネスにつき 1 つの確認リクエストを行います。その場所の確認が完了すると、追加された他の関連する場所の確認が自動的に行われます。

オーナー確認後にビジネス情報を追加した場合、オーナー確認を再度リクエストする必要があります。

エージェントに関連付けられているロケーションを表示するには、ブランドのすべてのロケーションを一覧表示するを参照して、結果を agent の値でフィルタリングします。

ビジネス情報を作成する

ビジネス情報をエージェントに追加するには、Business Communications API を使用してリクエストを行い、ブランドのロケーションを作成し、そのエージェントの name 値をそのロケーションに追加します。

Prerequisites

ビジネス情報を作成する前に、いくつかの項目を収集する必要があります。

ビジネスの作成

情報を収集したら、ビジネスを作成します。ターミナルで次のコマンドを実行します。

ハイライト表示された変数は、前提条件で確認した値に置き換えます。BRAND_ID は、ブランドの name 値の「brands/」に続く部分に置き換えます。たとえば、name が「brands/12345」の場合、ブランド ID は「12345」です。

cURL


# 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();
    }
  }
}
このコードは、Java Business Communications クライアント ライブラリに基づいています。

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)

フォーマットと値のオプションについては、brands.locations.create をご覧ください。

ビジネスを作成すると、Business Communications API により、関連する他のビジネスを識別し、同じブランドとエージェントのビジネス情報が作成されます。

店舗情報

ビジネス情報を作成すると、Business Communications API は nametestUrls などのビジネス情報の値を返します。

name をアクセスできる場所に保管してください。ビジネス情報を更新するには、name が必要です。

場所をテストする

各エージェントにはテスト URL があります。この URL を使用することで、エージェントとの会話がユーザーにどのように表示されるかを確認できます。また、メッセージング インフラストラクチャを検証することもできます。

TestUrl には url 属性と surface 属性があります。iOS デバイスで地域 URL をテストするには、サーフェス URL が SURFACE_IOS_MAPS のテスト URL を使用します。Google マップ アプリをインストール済みの iOS デバイスで URL を開くと、関連するエージェントと完全に機能する会話が開きます。

Android デバイスには 2 つのテスト URL があります。surface の値が SURFACE_ANDROID_MAPS の Google マップでのオープンな会話 URL は、Google マップに表示される会話のエントリ ポイントを表します。surface の値が SURFACE_ANDROID_WEB の URL は、オーバーレイの会話ビューで開かれた会話で、他のすべてのエントリ ポイントを表します。

会話サーフェスが開くと、会話にはユーザーが目にするブランディング情報がすべて含まれており、エージェントにメッセージを送信すると、Webhook はユーザーとの通信時に想定される完全な JSON ペイロードを含むメッセージを受信しますcontext フィールドに位置情報が表示されます。

ビジネス情報のテスト URL を開くには、リンクをタップするか、ビジネス メッセージ エージェント ランチャーを使用します。ブラウザのセキュリティ対策のため、テスト URL をコピーして貼り付けるか、手動で移動することはできません。

位置情報の取得

locationTestUrl など、ビジネス情報に関する情報を取得するには、ビジネスの name 値があれば Business Business Communications API から情報を取得できます。

1 件のビジネス情報を取得する

位置情報を取得するには、次のコマンドを実行します。BRAND_IDLOCATION_ID を、ロケーションの name から取得した一意の値に置き換えます。

cURL


# 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();
    }
  }
}
このコードは、Java Business Communications クライアント ライブラリに基づいています。

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)

フォーマットと値のオプションについては、brands.locations.get をご覧ください。

ブランドのすべての拠点を一覧表示する

ビジネスの name が不明な場合、GET リクエスト URL から LOCATION_ID 値を省略すると、ブランドに関連付けられたすべてのエージェントの情報を取得できます。

cURL


# 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();
    }
  }
}
このコードは、Java Business Communications クライアント ライブラリに基づいています。

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)

フォーマットと値のオプションについては、brands.locations.list をご覧ください。

ビジネス情報を更新する

ビジネス情報を更新するには、Business Communications API で PATCH リクエストを実行します。API 呼び出しを行う場合は、編集するフィールドの名前を「updateMask」URL パラメータの値として指定します。

たとえば、defaultLocale と agent フィールドを更新する場合、「updateMask」URL パラメータは「updateMask=defaultLocale,agent」になります。

フォーマットと値のオプションについては、brands.locations.patch をご覧ください。

ビジネスの name が不明な場合は、ブランドのすべてのビジネス情報を一覧表示するをご覧ください。

例: デフォルトの言語 / 地域を更新する

cURL


# 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();
    }
  }
}
このコードは、Java Business Communications クライアント ライブラリに基づいています。

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)

ビジネス情報を削除する

エージェントを削除すると、ビジネス メッセージによってすべての位置情報が削除されます。ビジネス メッセージでは、ユーザーのデバイスに転送される、またはユーザーのデバイスに保存されている位置情報に関連するエージェントが送信したメッセージは削除されません。ユーザーへのメッセージは位置情報ではありません。

ビジネスのオーナー確認を 1 回以上行おうとすると、削除リクエストは失敗します。オーナー確認が済んでいるビジネスやオーナー確認を試みたビジネスを削除するには、。(まず、ビジネス メッセージの Google アカウントでログインする必要があります。アカウントに登録するには、ビジネス メッセージを使用して登録するをご覧ください)。

ロケーションを削除するには、次のコマンドを実行します。BRAND_IDLOCATION_ID は、ロケーションの name から取得した一意の値に置き換えます。

cURL


# 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();
    }
  }
}
このコードは、Java Business Communications クライアント ライブラリに基づいています。

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)

フォーマットと値のオプションについては、brands.locations.delete をご覧ください。

次のステップ

ロケーションを持つエージェントが作成されたので、メッセージング フローを設計できます。