Si la marque représentée par un agent possède des établissements physiques, vous pouvez associer les lieux avec l'agent afin que les utilisateurs puissent envoyer des messages à des lieux spécifiques avec Business Messages. Business Messages identifie les établissements par leur ID de lieu.
Les ID de lieu vous permettent d'identifier l'emplacement physique auquel un utilisateur envoie un message déterminer le meilleur plan d’action pour répondre à l’utilisateur.
Vous devez revendiquer la propriété d'établissements physiques via Fiche d'établissement avant de pouvoir associer des établissements à un agent Business Messages.
Gérer plusieurs établissements
Si la marque appartient à une chaîne, vous devez ajouter tous les établissements de cette chaîne vous êtes autorisé à activer la messagerie. Pour faire valider tous les établissements de la chaîne, procédez comme suit : vous effectuerez une valider pour un établissement. Une fois que nous aurons validé cette adresse, nous valider les autres établissements associés que vous avez ajoutés.
Après la validation, si vous ajoutez d'autres zones géographiques, vous devrez demander la validation de l'établissement.
Pour afficher les emplacements associés à votre agent, consultez Répertorier tous les emplacements d'une
brand [marque] et filtrez les résultats en fonction de leurs valeurs agent
.
Créer un établissement
Pour ajouter un établissement à un agent, vous devez en faire la demande auprès de l'Entreprise
Communication
API
pour créer l'emplacement de la marque et associer l'agent en ajoutant son
name
à l'emplacement.
Prérequis
Avant de créer un établissement, vous devez rassembler quelques éléments:
- Chemin d'accès à la clé du compte de service de votre projet GCP sur votre ordinateur de développement
name
de la marque, tel qu'il apparaît dans l'API Business Communications (par Exemple : "marques/12345")Si vous ne connaissez pas l'
name
de la marque, consultezbrands.list
name
de l'agent, tel qu'il apparaît dans l'API Business Communications (par Exemple : "brands/12345/agents/67890")Si vous ne connaissez pas le
name
de l'agent, consultez Lister tous les agents pour une marque.ID de lieu de l'établissement
Identifiez l'identifiant de lieu d'un établissement grâce à l'ID de lieu Finder. Si l'emplacement est une zone desservie entreprise au lieu d'une adresse unique, utilisez l'identifiant de lieu d'établissement de service de zone Outil de recherche à la place.
Paramètres régionaux dans lesquels le lieu est généralement situé, spécifiés par un Langue ISO 639-1 à 2 caractères du code
Créer l'établissement
Une fois que vous avez recueilli vos informations, vous pouvez créer l'établissement. Dans un exécutez la commande suivante.
Remplacez les variables en surbrillance par les valeurs que vous avez identifiées dans
Conditions préalables. Remplacez BRAND_ID par la partie de
la valeur name
de la marque qui suit "brands/". Par exemple, si name
est
"brands/12345", l'ID de la marque est "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(); } } }Ce code est basé sur le Java Business Bibliothèque cliente de communication.
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)
Pour connaître les options de mise en forme et de valeur, consultez
brands.locations.create
Une fois l'établissement créé, l'API Business Communications identifie d'autres établissements associés, et crée des établissements pour la même marque et le même agent.
Informations sur le magasin
Lorsque vous créez un établissement, l'API Business Communications renvoie le
Valeurs du lieu, y compris name
et testUrls
.
Stockez name
dans un endroit auquel vous avez accès. Vous devez disposer de name
pour mettre à jour la position.
Tester un établissement
Chaque agent dispose d'URL de test qui vous permettent de voir comment une conversation avec cet agent est visible par les utilisateurs et vous permet de vérifier de l'infrastructure.
TestUrl
comporte les attributs url
et surface
.
Pour tester une URL de lieu avec un appareil iOS, utilisez l'URL de test avec une valeur de surface
sur SURFACE_IOS_MAPS
. Ouverture de l'URL sur un appareil iOS équipé de l'application Google Maps
installé ouvre une conversation entièrement fonctionnelle avec l'agent associé.
Les appareils Android disposent de deux URL de test. URL dont la valeur surface
est
SURFACE_ANDROID_MAPS
conversations ouvertes dans Google Maps et représentent
points d'entrée de conversation qui apparaissent dans Google Maps.
URL avec une valeur surface
de SURFACE_ANDROID_WEB
conversations ouvertes dans
une vue conversationnelle superposée
et représentent tous les autres points d'entrée.
Une fois la surface de conversation ouverte,
conversation comprend toutes les informations de marque
que les utilisateurs verraient et
Lorsque vous envoyez un message à l'agent, le webhook reçoit le message
message,
y compris la charge utile JSON complète à laquelle
vous pouvez vous attendre lorsque vous communiquez avec les utilisateurs.
Les informations de localisation s'affichent dans le champ context
.
Pour ouvrir l'URL de test d'un établissement, appuyez sur un lien ou utilisez l'agent Business Messages. Lanceur d'applications. Copie... et coller ou y accéder manuellement ne fonctionne pas, des mesures de sécurité des navigateurs.
Obtenir des informations de localisation
Pour obtenir des informations sur un lieu, comme le locationTestUrl
, vous pouvez obtenir
les informations de l'API Business Communications, à condition de disposer de la
la valeur name
de l'emplacement.
Obtenir des informations sur un seul établissement
Pour obtenir des informations de localisation, exécutez la commande suivante. Remplacer
BRAND_ID et LOCATION_ID par les valeurs uniques issues de
name
de l'établissement.
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(); } } }Ce code est basé sur le Java Business Bibliothèque cliente de communication.
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)
Pour connaître les options de mise en forme et de valeur, consultez
brands.locations.get
Répertorier tous les établissements associés à une marque
Si vous ne connaissez pas le name
du lieu, vous pouvez obtenir des informations pour tous les agents
associée à une marque en omettant la valeur LOCATION_ID d'une requête GET
URL de la requête.
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"); ListCe code est basé sur le Java Business Bibliothèque cliente de communication.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)
Pour connaître les options de mise en forme et de valeur, consultez
brands.locations.list
Mettre à jour un établissement
Pour mettre à jour un établissement, vous devez envoyer une demande PATCH à l'entreprise API Communications. Lorsque vous effectuez l'appel d'API, vous incluez les noms champs que vous modifiez en tant que valeurs pour "updateMask" paramètre d'URL.
Par exemple, si vous mettez à jour les champs "defaultLocale" et "agent", "updateMask" Le paramètre d'URL est "updateMask=defaultLocale,agent".
Pour connaître les options de mise en forme et de valeur, consultez
brands.locations.patch
Si vous ne connaissez pas la valeur name
d'un établissement, consultez la section Répertorier tous les établissements d'une
marque.
Exemple: Mettre à jour les paramètres régionaux par défaut
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(); } } }Ce code est basé sur le Java Business Bibliothèque cliente de communication.
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)
Supprimer un établissement
Lorsque vous supprimez un agent, Business Messages supprime toutes les données de localisation. Activité Messages ne supprime pas les messages envoyés par votre agent en rapport avec la position sont en transit vers ou stockés sur l'appareil d'un utilisateur. Les messages adressés aux utilisateurs ne sont pas données de localisation.
Les requêtes de suppression échouent si vous avez essayé de valider le un ou plusieurs emplacements. Pour supprimer un établissement que vous avez validé ou que vous avez tenté de valider, contactez-nous. (Vous devez d'abord signer avec un compte Google Business Messages. Pour créer un compte, rendez-vous sur S'inscrire à Business Messages).
Pour supprimer un établissement, exécutez la commande suivante : Remplacer BRAND_ID
et LOCATION_ID par les valeurs uniques issues de l'attribut name
de l'établissement.
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(); } } }Ce code est basé sur le Java Business Bibliothèque cliente de communication.
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)
Pour connaître les options de mise en forme et de valeur, consultez
brands.locations.delete
Étapes suivantes
Maintenant que vous avez un agent localisé, vous pouvez concevoir vos messages flux.