إذا كانت العلامة التجارية التي يمثّلها الوكيل لها مواقع جغرافية، يمكنك ربط المواقع الجغرافية بالوكيل ليتمكّن المستخدمون من مراسلة مواقع جغرافية معيّنة باستخدام ميزة "الرسائل التجارية". تحدّد ميزة "الرسائل التجارية" المواقع الجغرافية باستخدام رقم تعريف المكان.
يمكنك باستخدام معرفات الأماكن تحديد الموقع الجغرافي الحقيقي الذي يراسلك المستخدم منه وتحديد أفضل إجراء يمكن اتخاذه من أجل الرد على المستخدم.
يجب المطالبة بملكية المواقع الجغرافية من خلال "الملف التجاري" قبل أن تتمكّن من ربط المواقع الجغرافية بموظّف دعم على ميزة "الرسائل التجارية".
إدارة مواقع جغرافية متعددة
إذا كانت العلامة التجارية جزءًا من سلسلة، عليك إضافة جميع المواقع الجغرافية لتلك السلسلة التي لديك الإذن بتفعيل المراسلات لها. لتأكيد جميع المواقع الجغرافية في السلسلة، عليك تقديم طلب تأكيد واحد لموقع جغرافي واحد. بعد تأكيد ذلك الموقع الجغرافي، سنؤكّد تلقائيًا المواقع الجغرافية الأخرى التي أضفتها.
بعد التأكيد، إذا أضفت مواقع جغرافية إضافية، عليك طلب تأكيد الموقع الجغرافي مرة أخرى.
لعرض المواقع الجغرافية المرتبطة بموظّف الدعم، اطّلِع على List all locations for a
brand وفلتر النتائج حسب قيم agent.
إنشاء موقع جغرافي
لإضافة موقع جغرافي إلى موظّف الدعم، عليك تقديم طلب باستخدام Business
Communications
API
لإنشاء موقع العلامة التجارية وربط موظّف الدعم به عن طريق إضافة قيمة موظّف الدعم
name إلى الموقع الجغرافي.
المتطلبات الأساسية
قبل إنشاء موقع جغرافي، عليك جمع بعض العناصر:
- مسار مفتاح حساب الخدمة لمشروعك على Google Cloud Platform على جهاز التطوير
nameللعلامة التجارية، كما يظهر في Business Communications API (على سبيل المثال، "brands/12345")إذا كنت لا تعرف
nameللعلامة التجارية، اطّلِع علىbrands.list.nameلموظّف الدعم، كما يظهر في Business Communications API (على سبيل المثال، "brands/12345/agents/67890")إذا كنت لا تعرف
nameلموظّف الدعم، اطّلِع على List all agents for a brand.رقم تعريف المكان للموقع الجغرافي
يمكنك تحديد رقم تعريف المكان لموقع جغرافي باستخدام أداة البحث عن رقم تعريف المكان. إذا كان الموقع الجغرافي مؤسسة ضمن منطقة خدمة بدلاً من عنوان واحد، استخدِم أداة البحث عن رقم تعريف المكان بدلاً من ذلك.
اللغة التي يعمل بها الموقع الجغرافي عادةً، ويتم تحديدها برمز لغة مؤلف من حرفين بتنسيق ISO 639-1 code
إنشاء الموقع الجغرافي
بعد جمع المعلومات، يمكنك إنشاء الموقع الجغرافي. في الوحدة الطرفية، شغِّل الأمر التالي.
استبدِل المتغيّرات المميّزة بالقيم التي حدّدتها في
المتطلبات الأساسية. استبدِل BRAND_ID بالجزء من
قيمة العلامة التجارية name الذي يلي "brands/". على سبيل المثال، إذا كان name هو "brands/12345"، يكون رقم تعريف العلامة التجارية هو "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();
جافا
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(); } } }
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)
للاطّلاع على خيارات التنسيق والقيم، راجِع
brands.locations.create.
بعد إنشاء الموقع الجغرافي، تحدّد Business Communications API المواقع الجغرافية الأخرى المرتبطة به وتنشئ مواقع جغرافية للعلامة التجارية وموظّف الدعم نفسيهما.
معلومات المتجر
عند إنشاء موقع جغرافي، تعرض Business Communications API قيم الموقع الجغرافي، بما في ذلك name وtestUrls.
احفظ name في مكان يمكنك الوصول إليه. تحتاج إلى name لتعديل الموقع الجغرافي.
اختبار موقع جغرافي
يتضمّن كل موظّف دعم عناوين URL تجريبية تتيح لك الاطّلاع على شكل المحادثة مع هذا الموظّف للمستخدمين وتمنحك فرصة التحقّق من البنية الأساسية للمراسلة.
يتضمّن TestUrl
سمة url وسمة surface.
لاختبار عنوان URL لموقع جغرافي باستخدام جهاز iOS، استخدِم عنوان URL التجريبي بقيمة `surface` هي SURFACE_IOS_MAPS. يؤدي فتح عنوان URL على جهاز iOS مثبّت عليه تطبيق "خرائط Google" إلى فتح محادثة كاملة الميزات مع موظّف الدعم المرتبط.
تتضمّن أجهزة Android عنوانَي URL تجريبيَين. تفتح عناوين URL التي تكون قيمة surface فيها SURFACE_ANDROID_MAPS المحادثات في "خرائط Google" وتمثّل نقاط الدخول إلى المحادثات التي تظهر في "خرائط Google".
تفتح عناوين URL التي تكون قيمة surface فيها SURFACE_ANDROID_WEB المحادثات في عرض محادثة متراكب وتمثّل جميع نقاط الدخول الأخرى.
بعد فتح واجهة المحادثة، تتضمّن المحادثة جميع معلومات العلامة التجارية التي يراها المستخدمون، وعند إرسال رسالة إلى موظّف الدعم، يتلقّى تطبيق الويب هوك الرسالة، بما في ذلك حمولة JSON الكاملة التي يمكنك توقّعها عند التواصل مع المستخدمين.
تظهر معلومات الموقع الجغرافي في حقل context.
لفتح عنوان URL التجريبي لموقع جغرافي، انقر على أحد الروابط أو استخدِم Business Messages Agent Launcher. لا ينجح نسخ عنوان URL التجريبي ولصقه أو الانتقال إليه يدويًا بسبب إجراءات الأمان في المتصفّح.
الحصول على معلومات الموقع الجغرافي
للحصول على معلومات عن موقع جغرافي، مثل locationTestUrl، يمكنك الحصول على المعلومات من Business Communications API، طالما أنّ لديك قيمة name للموقع الجغرافي.
الحصول على معلومات لموقع جغرافي واحد
للحصول على معلومات الموقع الجغرافي، شغِّل الأمر التالي. استبدِل
BRAND_ID وLOCATION_ID بالقيم الفريدة من
name للموقع الجغرافي.
cURL
# This code gets the location where a brand is available. # Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/get # Replace the __BRAND_ID__ and __LOCATION_ID__ # Make sure a service account key file exists at ./service_account_key.json curl -X GET \ "https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/locations/__LOCATION_ID__" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-communications" \ -H "$(oauth2l header --json ./service_account_key.json businesscommunications)"
Node.js
/** * This code snippet gets the location of a brand. * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/get * * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js * Business Communications client library. */ /** * Edit the values below: */ const BRAND_ID = 'EDIT_HERE'; const LOCATION_ID = 'EDIT_HERE'; const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const businesscommunications = require('businesscommunications'); const {google} = require('googleapis'); // Initialize the Business Communications API const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}); // Set the scope that we need for the Business Communications API const scopes = [ 'https://www.googleapis.com/auth/businesscommunications', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); async function main() { const authClient = await initCredentials(); if (authClient) { const apiParams = { auth: authClient, name: 'brands/' + BRAND_ID + '/locations/' + LOCATION_ID, }; bcApi.brands.locations.get(apiParams, {}, (err, response) => { if (err !== undefined && err !== null) { console.dir(err); } else { // Location found console.log(response.data); } }); } else { console.log('Authentication failure.'); } } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // Configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // Authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } main();
جافا
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(); } } }
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)
للاطّلاع على خيارات التنسيق والقيم، راجِع
brands.locations.get.
سرد جميع المواقع الجغرافية لعلامة تجارية
إذا كنت لا تعرف name للمواقع الجغرافية، يمكنك الحصول على معلومات عن جميع موظّفي الدعم
المرتبطين بعلامة تجارية عن طريق حذف قيمة LOCATION_ID من عنوان URL لطلب GET.
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();
جافا
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"); Listlocations = 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)
للاطّلاع على خيارات التنسيق والقيم، راجِع
brands.locations.list.
تعديل موقع جغرافي
لتعديل موقع جغرافي، عليك تنفيذ طلب PATCH باستخدام Business Communications API. عند إجراء طلب بيانات من واجهة برمجة التطبيقات، عليك تضمين أسماء الحقول التي تعدّلها كقيم لمعلَمة عنوان URL "updateMask".
على سبيل المثال، إذا عدّلت الحقلَين defaultLocale وagent، تكون معلَمة عنوان URL "updateMask" هي "updateMask=defaultLocale,agent".
للاطّلاع على خيارات التنسيق والقيم، راجِع
brands.locations.patch.
إذا كنت لا تعرف name للموقع الجغرافي، اطّلِع على List all locations for a
brand.
مثال: تعديل اللغة التلقائية
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();
جافا
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(); } } }
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)
حذف موقع جغرافي
عند حذف موظّف دعم، تحذف ميزة "الرسائل التجارية" جميع بيانات الموقع الجغرافي. لا تحذف ميزة "الرسائل التجارية" الرسائل التي أرسلها موظّف الدعم والمرتبطة بالموقع الجغرافي والتي تكون قيد النقل إلى جهاز المستخدم أو مخزّنة عليه. الرسائل المرسَلة إلى المستخدمين ليست بيانات الموقع الجغرافي.
تفشل طلبات الحذف إذا حاولت تأكيد الموقع الجغرافي مرة واحدة أو أكثر. لحذف موقع جغرافي أكّدته أو حاولت تأكيده، يُرجى التواصل معنا.
لحذف موقع جغرافي، شغِّل الأمر التالي. استبدِل BRAND_ID
و LOCATION_IDبالقيم الفريدة من nameللموقع الجغرافي.
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();
جافا
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(); } } }
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)
للاطّلاع على خيارات التنسيق والقيم، راجِع
brands.locations.delete.
الخطوات التالية
الآن بعد أن أصبح لديك موظّف دعم يتضمّن مواقع جغرافية، يمكنك تصميم مسارات المراسلة.