Temsilcinin temsil ettiği markanın fiziksel konumları varsa, bunları Kullanıcıların belirli konumlara mesaj gönderebilmesi için temsilciyle konumlar Business Messages. Business Messages, konumları yer kimliğine göre tanımlar.
Yer kimlikleri ile, bir kullanıcının mesaj gönderdiği ve Kullanıcıya yanıt vermek için en doğru eylem planını belirleme.
Fiziksel konumların sahipliği için hak talebinde bulunmanız gerekir. İşletme Profili .
Birden fazla konumu yönetme
Marka bir zincire dahilse o zincirin şubelerine ait konumları mesajlaşmayı etkinleştirme izniniz var. Zincirdeki tüm konumları doğrulamak için: tek bir doğrula tek bir konum için istekte bulunabilirsiniz. Bu konum doğrulandıktan sonra otomatik olarak eklediğiniz diğer ilişkili konumları doğrulamanız gerekir.
Doğrulama işleminden sonra, başka konumlar eklerseniz bu işlemi tekrarlamanız gerekir. tekrar deneyin.
Temsilcinizle ilişkili konumları görmek için Bir öğenin tüm konumlarını listeleme başlıklı makaleyi inceleyin.
marka'yı seçin ve sonuçları agent değerlerine göre filtreleyin.
Konum oluşturun
Temsilciye konum eklemek için İşletme
İletişim
API
marka konumunu oluşturun ve temsilcinin konumunu ekleyerek temsilciyi ilişkilendirin
Konumun name değeri.
Ön koşullar
Konum oluşturmadan önce birkaç öğe toplamanız gerekir:
- Geliştirme makinenizdeki GCP projenizin hizmet hesabı anahtarına giden yol
Business Communications API'de göründüğü şekliyle markanın
nameöğesi (için örneğin, "markalar/12345")Markanın
namehizmetini bilmiyorsanızbrands.listTemsilcinin
namenumarası (Business Communications API'de göründüğü şekliyle) örneğin, "brands/12345/agents/67890")Temsilcinin
namenumarasını bilmiyorsanız brand [marka] özelliğini gönderin.Konumun Yer Kimliği
Bir konumun Yer Kimliğini Yer Kimliği Bul'u seçin. Konum bir hizmet bölgesiyse işletme tek bir adres yerine, Hizmet Bölgesi İşletme Yer Kimliği'ni kullanın Bulucu .
Konumun genellikle çalıştığı yerel ayar; iki karakterli ISO 639-1 dili kod
Konumu oluşturma
Bilgilerinizi topladıktan sonra sıra konumu oluşturmaya geliyor. aşağıdaki komutu çalıştırın.
Vurgulanan değişkenleri aşağıdaki tabloda tanımladığınız değerlerle değiştirin:
Ön koşullar. BRAND_ID yerine şununla değiştirin:
markanın "brands/" ile başlayan name değeri. Örneğin, name
"brands/12345" ise marka kimliği "12345"tir.
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();
}
}
}
Bu kod,
Java İşletmesi
İletişim istemci kitaplığı.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)
Biçimlendirme ve değer seçenekleri için bkz.
brands.locations.create.
Konumu oluşturmanızın ardından Business Communications API, konumla ilgili ilişkili konumları kullanarak aynı marka ve acente için konumlar oluşturur.
Mağaza bilgileri
Bir konum oluşturduğunuzda Business Communications API,
name ve testUrls dahil olmak üzere konumun değerlerine.
name, erişebileceğiniz bir yerde depolayın. Konumu güncellemek için name uygulamasına ihtiyacınız var.
Bir konumu test etme
Her temsilcinin, söz konusu temsilciyle yapılan görüşmenin performansını görmenizi sağlayan test URL'leri vardır gösterilir ve size mesajlarınızı doğrulama fırsatı sunar. geliştirmenin harika bir yoludur.
Bir TestUrl
url ve surface özelliklerine sahip.
Konum URL'sini bir iOS cihazla test etmek için yüzey değerine sahip test URL'sini kullanın
/ SURFACE_IOS_MAPS. URL'yi Google Haritalar uygulaması olan bir iOS cihazda açma
yüklendiğinde, ilişkili aracı ile tamamen işlevsel bir görüşme açılır.
Android cihazlarda iki test URL'si vardır. surface değeri olan URL'ler
Google Haritalar'da SURFACE_ANDROID_MAPS açık ileti dizisi ve temsilci
konuşmaya giriş noktaları ekleyebilirsiniz.
surface değeri SURFACE_ANDROID_WEB olan URL'ler şurada açık ileti dizileri:
ve diğer tüm giriş noktalarını temsil eder.
Konuşma yüzeyi açıldığında
kullanıcıların göreceği tüm marka bilgilerini içermesi ve
Temsilciye mesaj gönderdiğinizde, webhook'unuz
mesaj,
tam JSON yükü dahil, ancak bunlarla sınırlı değildir.
Konum bilgileri context alanında görünür.
Bir konumun test URL'sini açmak için bir bağlantıya dokunun veya Business Messages Agent'ı kullanın. Başlatıcı. Kopyalanıyor test URL'sine yapıştırmak veya manuel olarak gitmek işe yaramaz çünkü bir dizi güvenlik önlemi aldı.
Konum bilgilerini alma
locationTestUrl gibi bir konum hakkında bilgi almak için:
Business Communications API'dan gelen bilgileri (işletmenizle ilgili
konumun name değerine ayarlanır.
Tek bir konumla ilgili bilgi alma
Konum bilgilerini almak için aşağıdaki komutu çalıştırın. Değiştir
Şu kaynaktan benzersiz değerlere sahip BRAND_ID ve LOCATION_ID:
konumun 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();
}
}
}
Bu kod,
Java İşletmesi
İletişim istemci kitaplığı.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)
Biçimlendirme ve değer seçenekleri için bkz.
brands.locations.get.
Bir markanın tüm konumlarını listeleyin
Konumun name bilgilerini bilmiyorsanız tüm temsilcilerden bilgi alabilirsiniz
GET'den LOCATION_ID değerini atlayarak bir markayla ilişkilendirilir.
istek URL'si.
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();
}
}
}
Bu kod,
Java İşletmesi
İletişim istemci kitaplığı.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)
Biçimlendirme ve değer seçenekleri için bkz.
brands.locations.list.
Konum güncelleme
Konumu güncellemek için İşletme ile bir YAMA isteği gerçekleştirirsiniz Communications API. API çağrısını yaparken "updateMask" değeri olarak düzenlediğiniz alanlar URL parametresi.
Örneğin, defaultLocale ve agent alanlarını güncellerseniz "güncellemeMaskesi" URL parametresi "updateMask=defaultLocale,agent" şeklindedir.
Biçimlendirme ve değer seçenekleri için bkz.
brands.locations.patch.
Bir konumun name konumunu bilmiyorsanız
brand [marka] özelliğini gönderin.
Örnek: Varsayılan yerel ayarı güncelleme
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();
}
}
}
Bu kod,
Java İşletmesi
İletişim istemci kitaplığı.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)
Konum silme
Bir temsilciyi sildiğinizde Business Messages tüm konum verilerini siler. İş dünyası Mesajlar, temsilciniz tarafından gönderilen konumla ilgili olarak gönderilen mesajları silmez Kullanıcının cihazına aktarılan veya cihazda saklanan içerikler. Kullanıcılara gönderilen mesajlar konum verileri.
bir kez daha kontrol edebilirsiniz. Doğruladığınız bir konumu silmek için doğrulama girişiminde bulunuldu, . bize ulaşın. (İlk olarak Business Messages Google hesabıyla oturum açın. Bir hesaba kaydolmak için bkz. İşletme Profiline Kaydolun Mesajlar'ı tıklayın.)
Bir konumu silmek için aşağıdaki komutu çalıştırın. BRAND_ID adlı cihazı değiştirin
ve konumun name içindeki benzersiz değerlerle LOCATION_ID.
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();
}
}
}
Bu kod,
Java İşletmesi
İletişim istemci kitaplığı.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)
Biçimlendirme ve değer seçenekleri için bkz.
brands.locations.delete.
Sonraki adımlar
Konumu olan bir temsilciniz olduğuna göre mesajlarınızı tasarlayabilirsiniz görebilirsiniz.