การสร้างการประชุมของบุคคลที่สาม

วันที่

โซลูชันการประชุมแต่ละอย่าง ที่คุณกำหนดไว้ในโปรเจ็กต์สคริปต์ ไฟล์ Manifest มี onCreateFunction ที่เชื่อมโยงอยู่ ส่วนเสริมเรียกใช้ฟังก์ชันนี้เพื่อสร้าง การประชุมเมื่อใดก็ตามที่ผู้ใช้พยายามเลือกโซลูชันการประชุมนั้น กิจกรรม

คุณต้องใช้ onCreateFunction แต่ละรายการที่อธิบายไว้ในไฟล์ Manifest ของส่วนเสริม โดยทั่วไปแล้ว ฟังก์ชันเหล่านี้ต้องมีลักษณะดังต่อไปนี้

  1. ดึงข้อมูลกิจกรรมใน Google ปฏิทิน เช่น รหัสกิจกรรมหรือ ที่ระบบการประชุมของบุคคลที่สามอาจต้องใช้ เพื่อสร้างการประชุม
  2. เชื่อมต่อกับบริการการประชุมของบุคคลที่สามและสร้างการประชุมใหม่ โดยใช้ข้อมูลกิจกรรมของ Google ปฏิทิน
  3. หากคำขอสร้างการประชุมล้มเหลวด้วยเหตุผลบางอย่าง ให้ใช้ข้อผิดพลาด ในการสร้างและส่งคืน ConferenceData ที่มีแอตทริบิวต์ ConferenceError หรือทำตามขั้นตอนถัดไปให้เรียบร้อย
    1. เริ่มต้นการซิงค์การประชุม
    2. ใช้ข้อมูลที่ได้จากบริการการประชุมของบุคคลที่สามเพื่อ สร้างและส่งคืน ConferenceData ออบเจ็กต์

กำลังดึงข้อมูลกิจกรรม

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

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

Google ปฏิทินสามารถเพิ่มรายละเอียดการประชุมในกิจกรรมก่อน มีอยู่จริงๆ ในกรณีเช่นนี้ Google ปฏิทินจะส่งหมายเลข onCreateFunction ที่ถูกต้อง eventId แต่การโทรไปยัง Calendar.Events.get() ในภายหลังจะส่งผลให้เกิด การตอบกลับข้อผิดพลาดที่แจ้งว่าไม่มีเหตุการณ์อยู่ ในกรณีเหล่านี้ เป็นการดีที่สุดที่จะ สร้างการประชุมบุคคลที่สามโดยใช้ข้อมูลตัวยึดตำแหน่ง ข้อมูลนี้จะถูกแทนที่ ครั้งถัดไปที่กิจกรรม ซิงค์

กำลังสร้างการประชุมของบุคคลที่สาม

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

ใน Apps Script วิธีที่ง่ายที่สุดในการจัดการกับการสร้างคำขอ API ภายนอกคือ โดยใช้ OAuth2 สำหรับ Apps Script หรือ OAuth1 สำหรับ Apps Script ไลบรารีแบบโอเพนซอร์ส นอกจากนี้คุณยัง เชื่อมต่อกับ API ภายนอกโดยใช้บริการ UrlFetch แต่คุณต้องจัดการรายละเอียดการให้สิทธิ์อย่างชัดเจน

หลังจากขอสร้างการประชุมแล้ว คุณอาจต้อง คำขอเรียกดูรายละเอียดการประชุมใหม่

เริ่มต้นการซิงค์การประชุม

เมื่อสร้างการประชุมในระบบของบุคคลที่สามเรียบร้อยแล้ว ก็น่าจะมีขั้นตอน 2-3 ขั้นตอนเพื่อเปิดใช้ กำลังซิงค์ เพื่อให้เปลี่ยนเป็น กิจกรรมใน Google ปฏิทินจะปรากฏในการประชุม

ดูการซิงค์การเปลี่ยนแปลงในปฏิทิน เพื่อดูรายละเอียดการตั้งค่าการซิงค์หลังจากสร้างการประชุม

การสร้างการตอบกลับข้อมูลการประชุม

ใช้ข้อมูลการประชุมที่ได้จากบริการของบุคคลที่สาม onCreateFunction จะต้องสร้างและแสดงผล ConferenceData object; เวลา ข้อมูลการประชุม จะอธิบายเนื้อหาของออบเจ็กต์นี้ Google ปฏิทินจะใช้ข้อมูลนี้ ใช้ข้อมูลนี้เพื่อนำผู้ใช้ไปยังการประชุมเมื่อเริ่มการประชุม

เมื่อสร้าง ConferenceData โปรดทราบว่ามีข้อจำกัดบางอย่างเกี่ยวกับความยาวฟิลด์ รูปแบบของ URI จุดแรกเข้า และชุดค่าผสมของจุดแรกเข้าที่อนุญาต ตัวอย่างเช่น สามารถมีจุดเข้า VIDEO ได้สูงสุด 1 จุดใน ConferenceData ข้อจำกัดเหล่านี้เหมือนกับข้อจำกัดที่อธิบายไว้ ในกิจกรรม API ของปฏิทินสำหรับ conferenceData แม้ว่าจะไม่ใช่ช่องเหตุการณ์ API ทั้งหมดที่อธิบายไว้ ได้ใน Apps Script

การจัดการข้อผิดพลาด

ในบางกรณี อาจสร้างการประชุมไม่สำเร็จเนื่องจาก ข้อผิดพลาดที่แสดงผลโดยระบบการประชุมของบุคคลที่สาม ในกรณีเหล่านี้ ส่วนเสริมของคุณควรจัดการกับเงื่อนไขข้อผิดพลาดได้อย่างมีประสิทธิภาพด้วยการสร้างและ ส่งคืน ConferenceData ออบเจ็กต์ที่มี ConferenceError รายละเอียดเพื่อให้ Google ปฏิทินสามารถดำเนินการตามความเหมาะสม

เมื่อสร้างออบเจ็กต์ ConferenceData เพื่อรายงานข้อผิดพลาด คุณ ต้องรวมคอมโพเนนต์ ConferenceData นอกเหนือจาก ConferenceError ออบเจ็กต์ ConferenceErrors สามารถมี ConferenceErrorType, ข้อความแสดงข้อผิดพลาด และในกรณีของการตรวจสอบสิทธิ์จะออก URL ที่อนุญาตให้ ลงชื่อเข้าใช้ระบบการประชุมของบุคคลที่สามได้

ตัวอย่าง

รายการต่อไปนี้แสดงตัวอย่างของ onCreateFunction (โปรดทราบว่าชื่อของ ฟังก์ชันจะเป็นอะไรก็ได้ คุณเพียงแค่ต้องกำหนดในโปรเจ็กต์ส่วนเสริมเท่านั้น ไฟล์ Manifest)

ฟังก์ชัน create3rdPartyConference() จะติดต่อกับระบบของบุคคลที่สาม เพื่อสร้างการประชุมที่นั่นและฟังก์ชัน getAuthenticationUrl() สร้าง URL การตรวจสอบสิทธิ์ระบบของบุคคลที่สาม ไม่ได้ติดตั้งใช้งาน อย่างสมบูรณ์ที่นี่ เนื่องจากขึ้นอยู่กับรายละเอียดของระบบของบุคคลที่สามอย่างมาก

ฟังก์ชัน initializeSyncing() ไม่ปรากฏที่นี่ จะจัดการขั้นตอนเบื้องต้น ที่จำเป็นสำหรับการซิงค์ ดูซิงค์การเปลี่ยนแปลงปฏิทิน เพื่อดูรายละเอียด

/**
 *  Creates a conference, then builds and returns a ConferenceData object
 *  with the corresponding conference information. This method is called
 *  when a user selects a conference solution defined by the add-on that
 *  uses this function as its 'onCreateFunction' in the add-on manifest.
 *
 *  @param {Object} arg The default argument passed to a 'onCreateFunction';
 *      it carries information about the Google Calendar event.
 *  @return {ConferenceData}
 */
function createConference(arg) {
  const eventData = arg.eventData;
  const calendarId = eventData.calendarId;
  const eventId = eventData.eventId;

  // Retrieve the Calendar event information using the Calendar
  // Advanced service.
  var calendarEvent;
  try {
    calendarEvent = Calendar.Events.get(calendarId, eventId);
  } catch (err) {
    // The calendar event does not exist just yet; just proceed with the
    // given event ID and allow the event details to sync later.
    console.log(err);
    calendarEvent = {
      id: eventId,
    };
  }

  // Create a conference on the third-party service and return the
  // conference data or errors in a custom JSON object.
  var conferenceInfo = create3rdPartyConference(calendarEvent);

  // Build and return a ConferenceData object, either with conference or
  // error information.
  var dataBuilder = ConferenceDataService.newConferenceDataBuilder();

  if (!conferenceInfo.error) {
    // No error, so build the ConferenceData object from the
    // returned conference info.

    var phoneEntryPoint = ConferenceDataService.newEntryPoint()
        .setEntryPointType(ConferenceDataService.EntryPointType.PHONE)
        .setUri('tel:+' + conferenceInfo.phoneNumber)
        .setPin(conferenceInfo.phonePin);

    var adminEmailParameter = ConferenceDataService.newConferenceParameter()
        .setKey('adminEmail')
        .setValue(conferenceInfo.adminEmail);

    dataBuilder.setConferenceId(conferenceInfo.id)
        .addEntryPoint(phoneEntryPoint)
        .addConferenceParameter(adminEmailParameter)
        .setNotes(conferenceInfo.conferenceLegalNotice);

    if (conferenceInfo.videoUri) {
      var videoEntryPoint = ConferenceDataService.newEntryPoint()
          .setEntryPointType(ConferenceDataService.EntryPointType.VIDEO)
          .setUri(conferenceInfo.videoUri)
          .setPasscode(conferenceInfo.videoPasscode);
      dataBuilder.addEntryPoint(videoEntryPoint);
    }

    // Since the conference creation request succeeded, make sure that
    // syncing has been enabled.
    initializeSyncing(calendarId, eventId, conferenceInfo.id);

  } else if (conferenceInfo.error === 'AUTH') {
    // Authenentication error. Implement a function to build the correct
    // authenication URL for the third-party conferencing system.
    var authenticationUrl = getAuthenticationUrl();
    var error = ConferenceDataService.newConferenceError()
        .setConferenceErrorType(
            ConferenceDataService.ConferenceErrorType.AUTHENTICATION)
        .setAuthenticationUrl(authenticationUrl);
    dataBuilder.setError(error);

  } else {
    // Other error type;
    var error = ConferenceDataService.newConferenceError()
        .setConferenceErrorType(
            ConferenceDataService.ConferenceErrorType.TEMPORARY);
    dataBuilder.setError(error);
  }

  // Don't forget to build the ConferenceData object.
  return dataBuilder.build();
}


/**
 *  Contact the third-party conferencing system to create a conference there,
 *  using the provided calendar event information. Collects and retuns the
 *  conference data returned by the third-party system in a custom JSON object
 *  with the following fields:
 *
 *    data.adminEmail - the conference administrator's email
 *    data.conferenceLegalNotice - the conference legal notice text
 *    data.error - Only present if there was an error during
 *         conference creation. Equal to 'AUTH' if the add-on user needs to
 *         authorize on the third-party system.
 *    data.id - the conference ID
 *    data.phoneNumber - the conference phone entry point phone number
 *    data.phonePin - the conference phone entry point PIN
 *    data.videoPasscode - the conference video entry point passcode
 *    data.videoUri - the conference video entry point URI
 *
 *  The above fields are specific to this example; which conference information
 *  your add-on needs is dependent on the third-party conferencing system
 *  requirements.
 *
 * @param {Object} calendarEvent A Calendar Event resource object returned by
 *     the Google Calendar API.
 * @return {Object}
 */
function create3rdPartyConference(calendarEvent) {
  var data = {};

  // Implementation details dependent on the third-party system API.
  // Typically one or more API calls are made to create the conference and
  // acquire its relevant data, which is then put in to the returned JSON
  // object.

  return data;
}

/**
 *  Return the URL used to authenticate the user with the third-party
 *  conferencing system.
 *
 *  @return {String}
 */
function getAuthenticationUrl() {
  var url;
  // Implementation details dependent on the third-party system.

  return url;
}