エージェントが代理人を務めるブランドに実店舗がある場合は、 ユーザーが特定の場所にメッセージを送信できるように ビジネス メッセージ。ビジネス メッセージは、場所 ID によって場所を特定します。
場所 ID を使用すると、ユーザーがメッセージを送信した物理的な場所を識別して、 最適なアクションを判断します
物理的な場所の所有権の申請は、 ビジネス プロフィール ビジネス情報をビジネス メッセージ エージェントに関連付ける前にご確認ください。
複数のビジネス情報を管理する
ブランドがチェーンに属する場合は、そのチェーンの拠点をすべて追加する必要があります。 メッセージ機能を有効にする権限があります。チェーン内のすべてのビジネスのオーナー確認を行うには、 1 つのデータソースを 確認 リクエストする方法も学びます。場所の確認が完了すると 追加した他の関連するビジネス情報の確認
オーナー確認後、さらに場所を追加する場合は、リクエストする必要があります。 もう一度ご確認ください。
エージェントに関連付けられたビジネス情報を表示するには、エージェントに関連付けられたビジネス情報の一覧を取得する
ブランドを指定し、agent
値で結果をフィルタします。
ビジネス情報を作成する
エージェントにビジネス情報を追加するには、ビジネス
通信
API
ブランドの拠点を作成してエージェントを関連付けます。
ロケーションに name
値。
前提条件
ビジネスを作成する前に、以下の準備が必要です。
- 開発マシン上の GCP プロジェクトのサービス アカウント キーのパス
ブランドの
name
。Business Communications API( 例: 「brands/12345」)ブランドの
name
がわからない場合は、以下をご覧ください。brands.list
。エージェントの
name
。Business Communications API( 例: 「brands/12345/agents/67890」)エージェントの
name
がわからない場合は、エージェントの全エージェントを一覧表示する ブランド。ビジネスのプレイス ID
場所の ID を場所 ID で特定する Finder。 場所がサービス提供地域 ビジネス 1 つの住所ではなく、非店舗型ビジネスのプレイス ID ファインダー してください。
そのビジネスが通常運用されている言語 / 地域。 2 文字の ISO 639-1 言語 コード
ビジネス情報を作成する
情報を入力したら、次はビジネス情報を作成します。新しい 次のコマンドを実行します。
ハイライト表示された変数を、
前提条件。BRAND_ID は、
「brands/」に続くブランドの name
値。たとえば、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 ビジネス 通信クライアント ライブラリ。
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 から
location の値(name
、testUrls
など)。
アクセスできる場所に name
を保存してください。位置情報を更新するには name
が必要です。
場所をテストする
各エージェントには、そのエージェントとの会話がどのように行われたかを確認できるテスト URL があります。 メッセージを検証できます。 説明します。
TestUrl
url
属性と surface
属性がある。
iOS デバイスで場所の URL をテストするには、サーフェス値を含むテスト URL を使用します
/SURFACE_IOS_MAPS
。Google マップ アプリをインストールした iOS デバイスで URL を開く
関連付けられているエージェントと完全に機能する会話が開始されます。
Android デバイスには 2 つのテスト URL があります。surface
の値が
SURFACE_ANDROID_MAPS
を使用して Google マップで会話を開き、
Google マップに表示される会話型のエントリ ポイント。
surface
の値が SURFACE_ANDROID_WEB
の開いているスレッドの URL
オーバーレイの会話ビューが表示され、他のすべてのエントリ ポイントを表します。
会話サーフェスが開いたら、
ユーザーに表示されるすべてのブランド情報を含む会話
エージェントにメッセージを送信すると、Webhook は
メッセージ、
(ユーザーとやり取りするときに想定される完全な JSON ペイロードを含む)が記述されています。
位置情報が context
フィールドに表示されます。
ビジネスのテスト URL を開くには、リンクをタップするか、ビジネス メッセージ エージェントを使用します ランチャー。コピーしています テスト URL に貼り付けたり手動で移動したりしても機能しません。理由は次のとおりです。 多種多様です
位置情報を取得する
locationTestUrl
などの場所に関する情報を取得するには、次を取得します。
Business Communications API からの情報を
ロケーションの name
値。
特定の場所の情報を取得する
位置情報を取得するには、次のコマンドを実行します。置換
BRAND_ID と LOCATION_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 ビジネス 通信クライアント ライブラリ。
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 から LOCATION_ID 値を省略することで、ブランドと関連付けることができます。
リクエスト URL を入力します。
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このコードは Java ビジネス 通信クライアント ライブラリ。locations = request.execute().getLocations(); locations.stream().forEach(location -> { try { System.out.println(location.toPrettyString()); } catch (IOException e) { e.printStackTrace(); } }); } catch (Exception e) { e.printStackTrace(); } } }
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
。
ビジネス情報を更新する
ビジネス情報を更新するには、そのビジネスに対して PATCH リクエストを行います。 通信 API。API 呼び出しを行う際、各モジュールの名前を "updateMask" の値として編集中のフィールドURL パラメータ。
たとえば、defaultLocale フィールドと agent フィールドを更新すると、 updateMaskURL パラメータは「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 ビジネス 通信クライアント ライブラリ。
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)
ビジネス情報を削除する
エージェントを削除すると、ビジネス メッセージからすべての位置情報が削除されます。ビジネス メッセージによって、現在地に関連してエージェントが送信したメッセージは ユーザーのデバイスに保存されているデータ またはデータユーザーへのメッセージは 位置情報。
削除のリクエストを 複数回指定することもできますオーナー確認を済ませたビジネス情報を削除する 確認しようとした場合 お問い合わせください(事前に署名 ビジネス メッセージの Google アカウントを使用する必要があります。アカウント登録の方法については、以下をご覧ください。 Business に登録 メッセージをご覧ください)。
ロケーションを削除するには、次のコマンドを実行します。BRAND_ID を交換
LOCATION_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 ビジネス 通信クライアント ライブラリ。
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
。
次のステップ
エージェントで位置情報を指定したら、次はメッセージ機能を設計します。 フローをご覧ください。