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

โซลูชันการประชุมแต่ละรายการที่คุณกำหนดไว้ในไฟล์ 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 ที่คุณสามารถใช้สร้างการประชุม

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

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

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

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

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

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

การใช้ข้อมูลการประชุมที่แสดงผลโดยบริการของบุคคลที่สามทำให้ onCreateFunction ต้องสร้างและแสดงผลออบเจ็กต์ ConferenceData ส่วน ข้อมูลการประชุม จะอธิบายเนื้อหาของออบเจ็กต์นี้ 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;
}