Wenn die Marke, die ein Agent repräsentiert, physische Standorte hat, können Sie die Standorte mit dem Agent, sodass Nutzer Nachrichten an bestimmte Standorte Business Messages. Business Messages identifiziert Standorte anhand der Orts-ID.
Mit Orts-IDs können Sie feststellen, an welchen physischen Standort ein Nutzer Nachrichten sendet und die beste Vorgehensweise für die Reaktion auf die Nutzenden zu ermitteln.
Sie müssen Anspruch auf physische Standorte erheben über Unternehmensprofil bevor Sie Standorte mit einem Business Messages-Agent verknüpfen können.
Mehrere Standorte verwalten
Wenn die Marke zu einer Kette gehört, müssen Sie alle Standorte dieser Kette hinzufügen, Sie sind berechtigt, die Nachrichtenfunktion zu aktivieren. So bestätigen Sie alle Standorte in der Kette: erstellen Sie ein Single bestätigen für einen Standort. Sobald wir diesen Standort bestätigt haben, bestätigen Sie die anderen verknüpften Standorte, die Sie hinzugefügt haben.
Wenn Sie nach der Bestätigung weitere Standorte hinzufügen, müssen Sie die Standortbestätigung noch einmal.
Informationen zum Ansehen der mit Ihrem Agent verknüpften Standorte finden Sie unter Alle Standorte für einen
brand und filtern Sie die Ergebnisse nach ihren agent-Werten.
Standort erstellen
Wenn Sie einem Agent einen Standort hinzufügen möchten, senden Sie eine Anfrage beim Unternehmensprofil
Kommunikation
API
um den Markenstandort zu erstellen und den Agent zu verknüpfen, indem Sie die
name-Wert für den Standort.
Vorbereitung
Bevor Sie einen Standort erstellen, müssen Sie einige Dinge zusammentragen:
- Pfad zum Dienstkontoschlüssel Ihres GCP-Projekts auf Ihrem Entwicklungscomputer
nameder Marke, wie sie in der Business Communications API angezeigt wird (für Beispiel: „brands/12345“Wenn du die
nameder Marke nicht kennst, schau nachbrands.listnamedes Agenten, wie in der Business Communications API angezeigt (für Beispiel: „brands/12345/agents/67890“Wenn Sie den
namedes Agents nicht kennen, lesen Sie Alle Agents für einen brand [Marke].Orts-ID des Standorts
Die Orts-ID eines Standorts anhand der Orts-ID ermitteln Finder. Wenn es sich bei dem Standort um ein Einzugsgebiet handelt Unternehmen statt einer einzelnen Adresse, verwenden Sie die ID des Einzugsgebiets Finder .
Die Sprache, in der der Standort normalerweise tätig ist, angegeben durch einen zweistellige Sprache gemäß ISO 639-1 Code
Standort erstellen
Sobald Sie diese Informationen zusammengetragen haben, können Sie den Ort erstellen. In einer Terminal, führen Sie den folgenden Befehl aus.
Ersetzen Sie die markierten Variablen durch die Werte, die Sie in
Voraussetzungen. Ersetzen Sie BRAND_ID durch den Teil von
Der name-Wert der Marke, der auf „brands/“ folgt. Beispiel: name ist
„brands/12345“ lautet die Marken-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();
}
}
}
Dieser Code basiert auf dem
Java Business
Kommunikations-ClientbibliothekPython
"""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)
Informationen zu Formatierungs- und Wertoptionen finden Sie unter
brands.locations.create
Nachdem Sie den Standort erstellt haben, identifiziert die Business Communications API andere verknüpfter Standorte und erstellt Standorte für dieselbe Marke und denselben Agent.
Geschäftsinformationen
Wenn Sie einen Standort erstellen, gibt die Business Communications API den Wert
Werte des Standorts, einschließlich name und testUrls
Speichern Sie name an einem Ort, auf den Sie Zugriff haben. Du benötigst name, um den Standort zu aktualisieren.
Standort testen
Für jeden Agent gibt es Test-URLs, über die Sie sehen können, wie eine Unterhaltung mit diesem Agent funktioniert wird Nutzern angezeigt und Sie haben die Möglichkeit, und Infrastruktur.
Eine TestUrl
hat das Attribut url und surface.
Wenn Sie eine Standort-URL mit einem iOS-Gerät testen möchten, verwenden Sie die Test-URL mit einem Oberflächenwert
von SURFACE_IOS_MAPS. URL auf einem iOS-Gerät mit der Google Maps App öffnen
wird eine voll funktionsfähige Unterhaltung mit dem zugehörigen Agent geöffnet.
Android-Geräte haben zwei Test-URLs. URLs mit dem surface-Wert
SURFACE_ANDROID_MAPS offene Unterhaltungen in Google Maps und stellen
konversationelle Einstiegspunkte, die in Google Maps angezeigt werden.
URLs mit dem Wert surface von SURFACE_ANDROID_WEB offenen Unterhaltungen in
eine dialogorientierte Ansicht einblenden und alle anderen Einstiegspunkte darstellen.
Sobald sich die Konversationsoberfläche öffnet,
Konversation enthält alle Branding-Informationen, die die Nutzenden sehen, und
Wenn Sie eine Nachricht an den Agent senden, empfängt Ihr Webhook die
Nachricht,
einschließlich der vollständigen JSON-Nutzlast, die Sie bei der Kommunikation mit Nutzern erwarten können.
Die Standortinformationen werden im Feld context angezeigt.
Um die Test-URL eines Standorts zu öffnen, tippen Sie auf einen Link oder verwenden Sie den Business Messages-Agent Launcher-Taste: Wird kopiert das Einfügen oder manuelle Aufrufen einer Test-URL funktioniert nicht, der Browsersicherheit.
Standortinformationen abrufen
Um Informationen zu einem Standort zu erhalten, z. B. die locationTestUrl, können Sie
die Informationen aus der Business Communications API abzurufen, sofern Sie die
name-Wert des Standorts
Informationen zu einem einzelnen Standort abrufen
Führen Sie den folgenden Befehl aus, um Standortinformationen abzurufen. Ersetzen
BRAND_ID und LOCATION_ID durch die eindeutigen Werte aus dem
name des Standorts.
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();
}
}
}
Dieser Code basiert auf dem
Java Business
Kommunikations-ClientbibliothekPython
"""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)
Informationen zu Formatierungs- und Wertoptionen finden Sie unter
brands.locations.get
Alle Standorte für eine Marke auflisten
Wenn du die name des Standorts nicht kennst, kannst du Informationen für alle Kundenservicemitarbeiter abrufen
die mit einer Marke verknüpft sind, indem der Wert LOCATION_ID in einer GET-Anfrage weggelassen wird.
-Anforderungs-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 locations = request.execute().getLocations();
locations.stream().forEach(location -> {
try {
System.out.println(location.toPrettyString());
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
Dieser Code basiert auf dem
Java Business
Kommunikations-ClientbibliothekPython
"""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)
Informationen zu Formatierungs- und Wertoptionen finden Sie unter
brands.locations.list
Standort aktualisieren
Um einen Standort zu aktualisieren, führen Sie eine PATCH-Anfrage beim Communications API Beim API-Aufruf geben Sie die Namen der Felder, die Sie bearbeiten, als Werte für „updateMask“ URL-Parameter.
Wenn Sie beispielsweise die Felder „defaultLocale“ und „agent“ aktualisieren, gilt Folgendes: „updateMask“ URL-Parameter ist „updateMask=defaultLocale,agent“.
Informationen zu Formatierungs- und Wertoptionen finden Sie unter
brands.locations.patch
Falls Sie die name eines Standorts nicht kennen, finden Sie weitere Informationen unter Alle Standorte für einen
brand [Marke].
Beispiel: Standardsprache aktualisieren
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();
}
}
}
Dieser Code basiert auf dem
Java Business
Kommunikations-ClientbibliothekPython
"""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)
Standort löschen
Wenn Sie einen Agent löschen, werden alle Standortdaten in Business Messages gelöscht. Geschäftlich Messages löscht keine Nachrichten, die von Ihrem Agent gesendet wurden, die mit dem Standort zusammenhängen, auf dem Gerät eines Nutzers gespeichert sind. Nachrichten an Nutzer sind nicht Standortdaten.
Löschanfragen schlagen fehl, wenn Sie versucht haben, Ihren Standort ein- oder mehrmals. So löschen Sie einen bestätigten Standort oder versucht haben, dies zu bestätigen, kontaktieren Sie uns. Sie müssen zunächst unterschreiben mit einem Business Messages-Google-Konto. Informationen zur Registrierung eines Kontos finden Sie unter Bei Unternehmen registrieren Nachrichten)
Führen Sie den folgenden Befehl aus, um einen Standort zu löschen. BRAND_ID ersetzen
und LOCATION_ID durch die eindeutigen Werte aus dem name des Standorts.
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();
}
}
}
Dieser Code basiert auf dem
Java Business
Kommunikations-ClientbibliothekPython
"""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)
Informationen zu Formatierungs- und Wertoptionen finden Sie unter
brands.locations.delete
Nächste Schritte
Da Sie nun einen Agent mit Standorten haben, können Sie Ihre Werbebotschaft gestalten.