เพิ่มสถานที่ตั้ง

หากแบรนด์ที่ตัวแทนเป็นตัวแทนมีสถานที่ตั้งจริง คุณก็เชื่อมโยงสถานที่ตั้งกับตัวแทนได้ เพื่อให้ผู้ใช้ส่งข้อความสถานที่ตั้งแบบเจาะจงไปยัง Business Messages ได้ Business Messages จะระบุสถานที่ตั้งตามรหัสสถานที่

รหัสตําแหน่งจะช่วยให้คุณระบุได้ว่าผู้ใช้ส่งข้อความมาจากสถานที่ตั้งใดและกําหนดเส้นทางที่ดีที่สุดสําหรับการตอบสนองต่อผู้ใช้

คุณต้องอ้างสิทธิ์การเป็นเจ้าของสถานที่ตั้งจริงผ่าน Business Profile ก่อนจึงจะเชื่อมโยงสถานที่ตั้งกับตัวแทน Business Messages ได้

การจัดการสถานที่หลายแห่ง

หากแบรนด์นั้นอยู่ในเครือธุรกิจ คุณต้องเพิ่มสถานที่ตั้งทั้งหมดของเครือธุรกิจนั้นด้วย คุณมีสิทธิ์เปิดใช้การรับส่งข้อความ ในการยืนยันสถานที่ทั้งหมดในเชน คุณจะต้องทําการยืนยันคําขอเดียวสําหรับสถานที่ 1 แห่ง เมื่อยืนยันสถานที่ตั้งดังกล่าวแล้ว เราจะยืนยันสถานที่ตั้งอื่นๆ ที่เกี่ยวข้องซึ่งคุณได้เพิ่มไว้โดยอัตโนมัติ

หลังจากยืนยันแล้ว หากเพิ่มสถานที่ คุณจะต้องส่งคําขอการยืนยันสถานที่อีกครั้ง

หากต้องการดูสถานที่ตั้งที่เชื่อมโยงกับ Agent โปรดดูแสดงรายการสถานที่ตั้งทั้งหมดสําหรับแบรนด์ และกรองผลลัพธ์ตามค่า agent ของแบรนด์

สร้างสถานที่

หากต้องการเพิ่มสถานที่ตั้งไปยังตัวแทน ให้ส่งคําขอด้วย Business Communications API เพื่อสร้างสถานที่ตั้งของแบรนด์และเชื่อมโยงตัวแทนด้วยการเพิ่มค่า name ของตัวแทนลงในสถานที่

สิ่งที่ต้องดำเนินการก่อน

ก่อนสร้างสถานที่ คุณต้องรวบรวมสิ่งต่อไปนี้ 2-3 รายการ

สร้างสถานที่

เมื่อรวบรวมข้อมูลแล้ว ก็ถึงเวลาสร้างสถานที่ ในคําสั่งต่อไปนี้ ให้เรียกใช้คําสั่งต่อไปนี้

แทนที่ตัวแปรที่ไฮไลต์ด้วยค่าที่คุณระบุในข้อกําหนดเบื้องต้น แทนที่ BRAND_ID ด้วยส่วนค่า name ของแบรนด์ที่เป็นไปตาม "brands/" เช่น หาก name คือ "แบรนด์/12345" รหัสแบรนด์คือ "12345"

URL


# 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();
    }
  }
}
โค้ดนี้อิงตาม ไลบรารีของไคลเอ็นต์ Java Business Communications

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 เพื่ออัปเดตตําแหน่ง

ทดสอบสถานที่

แต่ละ Agent จะมี URL ทดสอบที่ช่วยให้คุณเห็นว่าการสนทนากับตัวแทนจะปรากฏต่อผู้ใช้อย่างไรและเปิดโอกาสให้คุณยืนยันโครงสร้างพื้นฐานของการรับส่งข้อความ

TestUrl มีแอตทริบิวต์ url และ surface หากต้องการทดสอบ URL ตําแหน่งด้วยอุปกรณ์ iOS ให้ใช้ URL ทดสอบที่มีค่าแพลตฟอร์ม SURFACE_IOS_MAPS การเปิด URL ในอุปกรณ์ iOS ที่ติดตั้งแอป Google Maps ไว้ จะเป็นการเปิดการสนทนาที่มีฟังก์ชันครบด้วย Agent ที่เชื่อมโยง

อุปกรณ์ Android มี URL ทดสอบ 2 รายการ ได้แก่ URL ที่มีค่า surface เป็น SURFACE_ANDROID_MAPS การสนทนาที่เปิดอยู่ใน Google Maps และแสดงถึงจุดเข้าการสนทนาที่ปรากฏใน Google Maps URL ที่มีค่า surface เป็น SURFACE_ANDROID_WEB การสนทนาที่เปิดอยู่ ในมุมมองการสนทนาแบบวางซ้อนและเป็นจุดเริ่มต้นอื่นๆ ทั้งหมด

เมื่อแพลตฟอร์มการสนทนาเปิดขึ้น การสนทนาจะมีข้อมูลการสร้างแบรนด์ทั้งหมดที่ผู้ใช้จะเห็น และเมื่อคุณส่งข้อความถึงตัวแทน เว็บฮุคจะได้รับข้อความ รวมถึงเพย์โหลด JSON แบบเต็มที่คุณจะพบเมื่อสื่อสารกับผู้ใช้ ข้อมูลตําแหน่งจะปรากฏในช่อง context

หากต้องการเปิด URL ทดสอบของสถานที่ ให้แตะลิงก์หรือใช้ Launcher Agent ของ Business Messages การคัดลอกและวางหรือการนําทางไปยัง URL ทดสอบด้วยตนเองไม่ทํางานเนื่องจากมาตรการด้านความปลอดภัยของเบราว์เซอร์

รับข้อมูลตําแหน่ง

หากต้องการดูข้อมูลเกี่ยวกับสถานที่ เช่น locationTestUrl คุณรับข้อมูลได้จาก Business Communications API ตราบใดที่มีค่า name ของสถานที่ตั้งนั้น

รับข้อมูลของสถานที่แห่งเดียว

หากต้องการรับข้อมูลตําแหน่ง ให้เรียกใช้คําสั่งต่อไปนี้ แทนที่ BRAND_ID และ LOCATION_ID ด้วยค่าที่ไม่ซ้ํากันจาก name ของสถานที่ตั้ง

URL


# 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();
    }
  }
}
โค้ดนี้อิงตาม ไลบรารีของไคลเอ็นต์ Java Business Communications

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

URL


# This code gets all locations where a brand is available.
# Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/list

# Replace the __BRAND_ID__
# Make sure a service account key file exists at ./service_account_key.json

curl -X GET \
"https://businesscommunications.googleapis.com/v1/brands/__BRAND_ID__/locations/" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/business-communications" \
-H "$(oauth2l header --json ./service_account_key.json businesscommunications)"

Node.js


/**
 * This code snippet lists the locations of a brand.
 * Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.locations/list
 *
 * This code is based on the https://github.com/google-business-communications/nodejs-businesscommunications Node.js
 * Business Communications client library.
 */

/**
 * Edit the values below:
 */
const BRAND_ID = 'EDIT_HERE';
const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json';

const businesscommunications = require('businesscommunications');
const {google} = require('googleapis');

// Initialize the Business Communications API
const bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({});

// Set the scope that we need for the Business Communications API
const scopes = [
  'https://www.googleapis.com/auth/businesscommunications',
];

// Set the private key to the service account file
const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY);

async function main() {
  const authClient = await initCredentials();

  if (authClient) {
    const apiParams = {
      auth: authClient,
      parent: 'brands/' + BRAND_ID,
    };

    bcApi.brands.locations.list(apiParams, {}, (err, response) => {
      if (err !== undefined && err !== null) {
        console.dir(err);
      } else {
        console.log(response.data);
      }
    });
  }
  else {
    console.log('Authentication failure.');
  }
}

/**
 * Initializes the Google credentials for calling the
 * Business Messages API.
 */
 async function initCredentials() {
  // Configure a JWT auth client
  const authClient = new google.auth.JWT(
    privatekey.client_email,
    null,
    privatekey.private_key,
    scopes,
  );

  return new Promise(function(resolve, reject) {
    // Authenticate request
    authClient.authorize(function(err, tokens) {
      if (err) {
        reject(false);
      } else {
        resolve(authClient);
      }
    });
  });
}

main();

Java

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.businesscommunications.v1.BusinessCommunications;
import com.google.api.services.businesscommunications.v1.model.Location;
import com.google.common.collect.ImmutableMap;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.UUID;

class Main {
  /**
   * Initializes credentials used by the Business Communications API.
   */
  private static BusinessCommunications.Builder getBusinessCommunicationsBuilder() {
    BusinessCommunications.Builder builder = null;
    try {
      GoogleCredential credential = GoogleCredential
            .fromStream(new FileInputStream("PATH_TO_SERVICE_ACCOUNT_KEY"));

      credential = credential.createScoped(Arrays.asList(
          "https://www.googleapis.com/auth/businesscommunications"));

      credential.refreshToken();

      HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
      JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();

      // Create instance of the Business Communications API
      builder = new BusinessCommunications
          .Builder(httpTransport, jsonFactory, null)
          .setApplicationName(credential.getServiceAccountProjectId());

      // Set the API credentials and endpoint
      builder.setHttpRequestInitializer(credential);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return builder;
  }

  public static void main(String args[]) {
    try {
      // Create client library reference
      BusinessCommunications.Builder builder = getBusinessCommunicationsBuilder();

      BusinessCommunications.Brands.Locations.List request
          = builder.build().brands().locations().list("brands/BRAND_ID");

      List locations = request.execute().getLocations();
      locations.stream().forEach(location -> {
        try {
          System.out.println(location.toPrettyString());
        } catch (IOException e) {
          e.printStackTrace();
        }
      });
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
โค้ดนี้อิงตาม ไลบรารีของไคลเอ็นต์ Java Business Communications

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 เมื่อเรียก API คุณจะรวมชื่อช่องที่จะแก้ไขเป็นค่าสําหรับพารามิเตอร์ URL "updateMask"

เช่น หากคุณอัปเดตช่อง defaultLocale และ Agent พารามิเตอร์ของ URL "updateMask" คือ "updateMask=defaultLocale,agent"

โปรดดูตัวเลือกการจัดรูปแบบและค่า ใน brands.locations.patch

หากไม่ทราบnameของสถานที่ตั้ง โปรดดูระบุสถานที่ตั้งทั้งหมดสําหรับแบรนด์

ตัวอย่าง: อัปเดตภาษาเริ่มต้น

URL


# 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();
    }
  }
}
โค้ดนี้อิงตาม ไลบรารีของไคลเอ็นต์ Java Business Communications

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)

ลบสถานที่

เมื่อคุณลบตัวแทน Business Messages จะลบข้อมูลตําแหน่งทั้งหมด Business Messages จะไม่ลบข้อความที่ Agent ส่ง ซึ่งเกี่ยวข้องกับสถานที่ที่อยู่ระหว่างการส่งหรือจัดเก็บในอุปกรณ์ของผู้ใช้ ข้อความที่ส่งไปยังผู้ใช้ไม่ใช่ ข้อมูลตําแหน่ง

การลบคําขอล้มเหลวหากคุณพยายามยืนยันตําแหน่งอย่างน้อย 1 ครั้ง หากต้องการลบสถานที่ที่ยืนยันแล้วหรือพยายามยืนยัน โปรดติดต่อเรา (ก่อนอื่น คุณต้องลงชื่อเข้าใช้ด้วยบัญชี Google ของ Business Messages หากต้องการลงทะเบียนบัญชี โปรดดูที่ลงทะเบียนกับ Business Messages)

หากต้องการลบสถานที่ตั้ง ให้เรียกใช้คําสั่งต่อไปนี้ แทนที่ BRAND_ID และ LOCATION_ID ด้วยค่าที่ไม่ซ้ํากันจาก name ของสถานที่ตั้ง

URL


# 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();
    }
  }
}
โค้ดนี้อิงตาม ไลบรารีของไคลเอ็นต์ Java Business Communications

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

ขั้นตอนถัดไป

เมื่อมีตัวแทนพร้อมสถานที่ตั้งแล้ว คุณจะออกแบบขั้นตอนการรับส่งข้อความได้