Se il brand rappresentato da un agente ha sedi fisiche, puoi associarlo le sedi con l'agente affinché gli utenti possano inviare messaggi a sedi specifiche Business Messages. Business Messages identifica le sedi in base all'ID luogo.
Con gli ID luogo, puoi identificare la località fisica a cui gli utenti inviano messaggi e che determinare la linea d'azione migliore per rispondere all'utente.
Devi rivendicare la proprietà di sedi fisiche tramite Profilo dell'attività prima di poter associare le sedi a un agente Business Messages.
Gestione di più sedi
Se il brand fa parte di una catena, devi aggiungere tutte le sedi di quella catena in cui disponi dell'autorizzazione per attivare la messaggistica. Per verificare tutte le sedi della catena, creerai un singolo verifica per una località. Una volta verificata la sede, e verificare le altre località associate che hai aggiunto.
Dopo la verifica, se aggiungi altre sedi, dovrai richiedere di nuovo la verifica della posizione.
Per visualizzare le sedi associate al tuo agente, consulta Elenca tutte le sedi per un
brand e filtra i risultati in base ai valori agent
.
Crea una località
Per aggiungere una sede a un agente, invia una richiesta all'Attività
Comunicazioni
dell'API
per creare la località del brand e associarlo all'agente aggiungendo il relativo
name
alla località.
Prerequisiti
Prima di creare una sede, devi raccogliere alcuni elementi:
- Percorso della chiave dell'account di servizio del progetto Google Cloud sulla macchina di sviluppo
name
del brand, come viene visualizzato nell'API Business Communications (per ad esempio "brands/12345").Se non conosci l'attributo
name
del brand, consulta:brands.list
name
dell'agente, come visualizzato nell'API Business Communications (per ad esempio "brands/12345/agents/67890").Se non conosci il
name
dell'agente, consulta Elenca tutti gli agenti per un brand.ID luogo della sede
Identifica l'ID luogo di una sede con l'ID luogo Finder. Se la località è un'area coperta dal servizio attività anziché un singolo indirizzo, utilizza l'ID sede dell'attività al domicilio del cliente. Ricerca .
La lingua in cui opera solitamente la sede, specificata da un lingua ISO 639-1 a due caratteri codice
Crea la località
Una volta raccolte le informazioni, puoi creare il luogo. In un nel terminale, esegui questo comando.
Sostituisci le variabili evidenziate con i valori identificati in
Prerequisiti. Sostituisci BRAND_ID con la parte di
il valore name
del brand che segue "brands/". Ad esempio, se name
è
"brands/12345", l'ID brand è "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(); } } }Questo codice si basa sul Attività commerciale Java Libreria client di comunicazione.
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)
Per le opzioni di formattazione e valore, consulta
brands.locations.create
Dopo aver creato la sede, l'API Business Communications identifica altri le località associate e crea quelle per lo stesso brand e agente.
Informazioni sul negozio
Quando crei una sede, l'API Business Communications restituisce il
valori della località, tra cui name
e testUrls
.
Archivia name
in una posizione a cui puoi accedere. Devi avere name
per aggiornare la posizione.
Eseguire il test di una località
Ogni agente ha URL di test che ti consentono di vedere come una conversazione con l'agente appare agli utenti e ti offre la possibilità di verificare i tuoi messaggi dell'infrastruttura.
Un TestUrl
ha gli attributi url
e surface
.
Per testare un URL di posizione con un dispositivo iOS, utilizza l'URL di test con un valore di superficie
di SURFACE_IOS_MAPS
. Apertura dell'URL su un dispositivo iOS su cui è installata l'app Google Maps
installato apre una conversazione completamente funzionale con l'agente associato.
I dispositivi Android hanno due URL di test. URL con un valore surface
pari a
SURFACE_ANDROID_MAPS
apri conversazioni in Google Maps e rappresenta
punti di ingresso conversazionali visualizzati in Google Maps.
URL con un valore surface
di SURFACE_ANDROID_WEB
conversazioni aperte in
una vista conversazionale sovrapposta e rappresentano tutti gli altri punti di ingresso.
Quando si apre la piattaforma di conversazione,
conversazione include tutte le informazioni di branding che gli utenti vedono, e
quando invii un messaggio all'agente, il webhook riceve
messaggio,
compreso il payload JSON completo che puoi aspettarti quando comunichi con gli utenti.
Le informazioni sulla posizione vengono visualizzate nel campo context
.
Per aprire l'URL di test di una sede, tocca un link o utilizza l'agente Business Messages Avvio app. Copia in corso... e incollare o comunque accedere manualmente a un URL di test non funziona delle misure di sicurezza del browser.
Ottieni informazioni sulla posizione
Per ricevere informazioni su un luogo, ad esempio locationTestUrl
, puoi ottenere
le informazioni dall'API Business Communications, a patto che tu disponga dei
valore name
della località.
Ricevere informazioni su un singolo luogo
Per ottenere informazioni sulla posizione, esegui questo comando. Sostituisci
BRAND_ID e LOCATION_ID con i valori univoci da
name
delle località.
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(); } } }Questo codice si basa sul Attività commerciale Java Libreria client di comunicazione.
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)
Per le opzioni di formattazione e valore, consulta
brands.locations.get
Elencare tutte le sedi per un brand
Se non conosci il name
delle sedi, puoi ottenere informazioni per tutti gli agenti
associate a un brand omettendo il valore LOCATION_ID da un comando GET
URL di richiesta.
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"); ListQuesto codice si basa sul Attività commerciale Java Libreria client di comunicazione.locations = request.execute().getLocations(); locations.stream().forEach(location -> { try { System.out.println(location.toPrettyString()); } catch (IOException e) { e.printStackTrace(); } }); } catch (Exception e) { e.printStackTrace(); } } }
Python
"""This code gets all locations where a brand is available. Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/list This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ from oauth2client.service_account import ServiceAccountCredentials from businesscommunications.businesscommunications_v1_client import BusinesscommunicationsV1 from businesscommunications.businesscommunications_v1_messages import ( BusinesscommunicationsBrandsLocationsListRequest, Location ) # Edit the values below: BRAND_ID = 'EDIT_HERE' SCOPES = ['https://www.googleapis.com/auth/businesscommunications'] SERVICE_ACCOUNT_FILE = './service_account_key.json' credentials = ServiceAccountCredentials.from_json_keyfile_name( SERVICE_ACCOUNT_FILE, scopes=SCOPES) client = BusinesscommunicationsV1(credentials=credentials) locations_service = BusinesscommunicationsV1.BrandsLocationsService(client) location_name = 'brands/' + BRAND_ID + '/locations' locations = locations_service.List( BusinesscommunicationsBrandsLocationsListRequest(name=location_name) ) print(locations)
Per le opzioni di formattazione e valore, consulta
brands.locations.list
Aggiornare una posizione
Per aggiornare una sede, devi eseguire una richiesta PATCH con l'attività API Communications. Quando effettui la chiamata API, includi i nomi dei i campi che stai modificando come valori di "updateMask" parametro URL.
Ad esempio, se aggiorni i campi defaultLocale e agent, "updateMask" Il parametro URL è "updateMask=defaultLocale,agent".
Per le opzioni di formattazione e valore, consulta
brands.locations.patch
Se non conosci il name
di una sede, consulta Elenca tutte le sedi per un
brand.
Esempio: aggiornare le impostazioni internazionali predefinite
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(); } } }Questo codice si basa sul Attività commerciale Java Libreria client di comunicazione.
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)
Eliminare una località
Quando elimini un agente, Business Messages elimina tutti i dati sulla posizione. Economia Messaggi non elimina i messaggi inviati dall'agente relativi alla località sono in transito o archiviati sul dispositivo di un utente. I messaggi indirizzati agli utenti non dati sulla posizione.
Le richieste di eliminazione non vanno a buon fine se hai tentato di verificare una o più volte. Per eliminare una sede che hai verificato o ha tentato di verificare, contattaci. Devi prima firmare con un Account Google Business Messages. Per creare un account, consulta Registrati presso l'attività Messaggi.
Per eliminare una località, esegui questo comando. Sostituisci BRAND_ID
e LOCATION_ID con i valori univoci da name
della località.
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(); } } }Questo codice si basa sul Attività commerciale Java Libreria client di comunicazione.
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)
Per le opzioni di formattazione e valore, consulta
brands.locations.delete
Passaggi successivi
Ora che hai un agente con le sedi, puoi definire il tuo messaggio l'addestramento.