Jika merek yang diwakili oleh agen memiliki lokasi fisik, Anda dapat mengaitkan lokasi dengan agen sehingga pengguna dapat mengirim pesan ke lokasi tertentu dengan Business Messages. Business Messages mengidentifikasi lokasi berdasarkan ID Tempat.
Dengan ID Tempat, Anda dapat mengidentifikasi lokasi fisik yang dikirimi pesan oleh pengguna dan menentukan tindakan terbaik untuk menanggapi pengguna.
Anda harus mengklaim kepemilikan lokasi fisik melalui Profil Bisnis sebelum Anda dapat mengaitkan lokasi dengan agen Business Messages.
Mengelola beberapa lokasi
Jika brand merupakan bagian dari jaringan bisnis, Anda harus menambahkan semua lokasi untuk jaringan bisnis tersebut Anda memiliki izin untuk mengaktifkan pesan. Untuk memverifikasi semua lokasi dalam jaringan bisnis, Anda akan membuat satu verifikasi permintaan untuk satu lokasi. Setelah kami memverifikasi lokasi tersebut, kami akan secara otomatis memverifikasi lokasi terkait lainnya yang telah Anda tambahkan.
Setelah verifikasi, jika Anda menambahkan lokasi lain, Anda harus meminta verifikasi lokasi lagi.
Untuk melihat lokasi yang terkait dengan agen Anda, lihat Membuat daftar semua lokasi untuk
merek dan memfilter hasilnya menurut nilai agent.
Membuat lokasi
Untuk menambahkan lokasi ke agen, Anda dapat membuat permintaan dengan
Komunikasi
API
untuk membuat lokasi merek dan mengaitkan agen dengan menambahkan
name ke lokasi.
Prasyarat
Sebelum membuat lokasi, Anda perlu mengumpulkan beberapa item:
- Jalur ke kunci akun layanan project GCP Anda di mesin pengembangan
namemerek, seperti yang muncul di Business Communications API (untuk misalnya, "brands/12345")Jika Anda tidak mengetahui
namemerek, lihatbrands.list.nameAgen, seperti yang muncul di Business Communications API (untuk contoh, "brands/12345/agents/67890")Jika Anda tidak mengetahui
nameagen, lihat Mencantumkan semua agen untuk brand.ID Tempat Lokasi
Identifikasi ID Tempat lokasi dengan ID Tempat Finder. Jika lokasinya adalah area layanan bisnis bukan satu alamat, gunakan ID Tempat Bisnis Area Layanan Pencari sebagai gantinya.
Lokal tempat lokasi biasanya beroperasi, yang ditentukan oleh bahasa ISO 639-1 yang terdiri dari dua karakter kode
Membuat lokasi
Setelah Anda mengumpulkan informasi, saatnya membuat lokasi. Di web, jalankan perintah berikut.
Ganti variabel yang ditandai dengan nilai yang Anda identifikasi di
Prasyarat. Ganti BRAND_ID dengan bagian dari
nilai name merek yang mengikuti "brands/". Misalnya, jika name adalah
"brands/12345", ID brand-nya adalah "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();
}
}
}
Kode ini didasarkan pada
Bisnis Java
Library klien komunikasi.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)
Untuk opsi pemformatan dan nilai, lihat
brands.locations.create
Setelah Anda membuat lokasi, Business Communications API akan mengidentifikasi lokasi terkait dan membuat lokasi untuk merek dan agen yang sama.
Informasi toko
Saat Anda membuat lokasi, Business Communications API akan menampilkan
nilai lokasi, termasuk name dan testUrls.
Simpan name di tempat yang dapat Anda akses. Anda perlu name untuk memperbarui lokasi.
Menguji lokasi
Setiap agen memiliki URL pengujian yang memungkinkan Anda melihat cara percakapan dengan agen tersebut ditampilkan kepada pengguna dan memberi Anda kesempatan untuk memverifikasi pesan infrastruktur IT.
TestUrl
memiliki atribut url dan surface.
Untuk menguji URL lokasi dengan perangkat iOS, gunakan URL pengujian dengan nilai platform
dari SURFACE_IOS_MAPS. Membuka URL di perangkat iOS yang memiliki aplikasi Google Maps
diinstal akan membuka percakapan yang berfungsi penuh dengan agen terkait.
Perangkat Android memiliki dua URL pengujian. URL dengan nilai surface
SURFACE_ANDROID_MAPS percakapan terbuka di Google Maps dan tampilkan
titik entri percakapan yang muncul di Google Maps.
URL dengan nilai surface dari SURFACE_ANDROID_WEB percakapan yang terbuka di
tampilan percakapan overlay dan mewakili semua titik entri lainnya.
Setelah platform percakapan terbuka,
mencakup semua informasi {i>branding<i} yang akan dilihat pengguna,
saat Anda mengirim pesan ke agen, webhook Anda menerima
pesan ini,
termasuk {i>payload<i} JSON lengkap yang dapat Anda harapkan
saat berkomunikasi dengan pengguna.
Informasi lokasi akan muncul di kolom context.
Untuk membuka URL pengujian lokasi, ketuk link atau gunakan Agen Business Messages Peluncur. Menyalin dan menempelkan atau menavigasi secara manual ke URL pengujian tidak akan berfungsi karena langkah-langkah keamanan browser.
Mendapatkan informasi lokasi
Untuk mendapatkan informasi tentang lokasi, seperti locationTestUrl, Anda bisa mendapatkan
informasi dari Business Communications API, asalkan Anda memiliki
nilai name lokasi.
Mendapatkan info untuk satu lokasi
Untuk mendapatkan informasi lokasi, jalankan perintah berikut. Ganti
BRAND_ID dan LOCATION_ID dengan nilai unik dari
name lokasi.
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();
}
}
}
Kode ini didasarkan pada
Bisnis Java
Library klien komunikasi.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)
Untuk opsi pemformatan dan nilai, lihat
brands.locations.get
Menampilkan daftar semua lokasi untuk merek
Jika tidak tahu name lokasi, Anda bisa mendapatkan informasi untuk semua agen
dikaitkan dengan merek dengan menghilangkan nilai LOCATION_ID dari GET
URL permintaan.
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();
}
}
}
Kode ini didasarkan pada
Bisnis Java
Library klien komunikasi.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)
Untuk opsi pemformatan dan nilai, lihat
brands.locations.list
Memperbarui lokasi
Untuk memperbarui lokasi, Anda melakukan permintaan PATCH dengan permintaan API Komunikasi. Saat melakukan panggilan API, Anda menyertakan nama kolom yang Anda edit sebagai nilai untuk "updateMask" Parameter URL.
Misalnya, jika Anda memperbarui kolom defaultLocale dan agen, "updateMask" Parameter URL-nya adalah "updateMask=defaultLocale,agent".
Untuk opsi pemformatan dan nilai, lihat
brands.locations.patch
Jika Anda tidak mengetahui name lokasi, lihat Buat daftar semua lokasi untuk
brand.
Contoh: Mengupdate lokalitas default
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();
}
}
}
Kode ini didasarkan pada
Bisnis Java
Library klien komunikasi.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)
Menghapus lokasi
Saat Anda menghapus agen, Business Messages akan menghapus semua data lokasi. Kelas bisnis Message tidak akan menghapus pesan yang dikirim oleh agen Anda terkait lokasi yang saat transit atau disimpan di perangkat pengguna. Pesan ke pengguna tidak data lokasi.
Permintaan penghapusan gagal jika Anda telah mencoba memverifikasi lokasi satu kali atau lebih. Untuk menghapus lokasi yang telah Anda verifikasi atau mencoba memverifikasi, hubungi kami. (Anda harus terlebih dahulu menandatangani dengan Akun Google Business Messages. Untuk mendaftarkan akun, lihat Daftar ke Business Message.)
Untuk menghapus lokasi, jalankan perintah berikut. Ganti BRAND_ID
dan LOCATION_ID dengan nilai unik dari name lokasi.
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();
}
}
}
Kode ini didasarkan pada
Bisnis Java
Library klien komunikasi.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)
Untuk opsi pemformatan dan nilai, lihat
brands.locations.delete
Langkah berikutnya
Sekarang setelah memiliki agen dengan lokasi, Anda dapat mendesain pesan alur.