正在建立第三方會議

每項會議解決方案 您在指令碼專案中定義的 資訊清單 具有關聯的 onCreateFunction。外掛程式會呼叫這個函式 則每次使用者嘗試選取會議解決方案時, 活動。

您必須實作外掛程式資訊清單中所述的每個 onCreateFunction。 一般來說,這些函式必須執行以下操作:

  1. 擷取任何 Google 日曆活動資訊,例如活動 ID 或 以及第三方會議系統 建立會議。
  2. 連線至第三方會議服務並建立新會議 使用 Google 日曆活動資訊。
  3. 如果因為某些原因導致會議建立要求失敗,請使用這則錯誤訊息 建構並傳回 ConferenceData敬上 內含 ConferenceError。 如果沒有,請完成後續步驟。
    1. 初始化會議的同步處理功能
    2. 將第三方會議服務傳回的資訊用於以下目的: 建構並傳回新的 ConferenceData敬上 物件。

擷取活動資訊

如要建立第三方會議,以便建立第三方會議的相應資訊, 必須選取 Google 日曆活動。所需的確切活動資訊各不相同 但通常這也包含 活動開始時間、結束時間、摘要、參與者清單和 ID。

呼叫時,您定義的每個 onCreateFunction 都會傳遞引數 包含日曆和活動 ID。您可以使用這些 ID 來擷取 查看完整的事件資訊 Google 日曆進階服務

Google 日曆可以在活動日期之前將會議詳細資料加入活動 存在。在這種情況下,Google 日曆會將有效的 onCreateFunction 傳遞給 eventId,但之後呼叫 Calendar.Events.get() 時, 錯誤回應,指出活動不存在。在這種情況下 使用預留位置資料建立第三方會議;這些資料會替換 下次活動時 同步處理

正在建立第三方會議

onCreateFunction 擷取必要的事件資料後,必須 連線至第三方會議系統來建立會議。 用途通常是透過提出 以及第三方會議系統查看第三方的說明文件 用來決定可以使用哪些 API 要求 建立會議。

在 Apps Script 中,如要處理外部 API 要求,最簡單的做法是 使用 Apps Script 的 OAuth2Apps Script 的 OAuth1 開放原始碼程式庫你也可以 使用 UrlFetch 服務連線至外部 API, 但您必須明確處理授權詳細資料。

要求建立會議後,你可能需要建立額外的 擷取新會議詳細資料的要求。

初始化會議同步處理作業

一旦外掛程式成功在第三方系統中建立會議 可能需要執行幾個步驟 Google 日曆活動就會反映在會議中。

請參閱同步處理日曆變更

建立會議資料回應

使用第三方服務傳回的會議資訊, onCreateFunction 必須建構並傳回 ConferenceData 物件;這個 會議資料 部分會說明此物件的內容。Google 日曆會使用這項資訊 並在會議開始後使用這些資訊引導使用者前往會議。

建立 ConferenceData 時 物件,請注意,欄位長度、格式 進入點 URI 和允許使用的進入點組合。例如: 一次最多只能有一個 VIDEO 進入點 ConferenceData。這些限制與說明中的限制相同 日曆 API 事件 (相應事件的相應事件) conferenceData 欄位 (但其中說明並未描述的所有 API 事件欄位) 均支援 Apps Script。

處理錯誤

在某些情況下,無法完成會議建立作業,原因如下: 。適用於以下情況 您的外掛程式應該建立並 傳回 ConferenceData敬上 包含 ConferenceError 以便 Google 日曆採取相應措施

建構 ConferenceData 物件來回報錯誤時, ,則除了提供ConferenceData ConferenceError 物件。ConferenceErrors 可以 ConferenceErrorType, 如果發生驗證問題,則網址 使用者登入第三方會議系統。

範例

以下範例為 onCreateFunction (請注意, 函式可以是任何內容您只需在外掛程式專案中 資訊清單)。

函式 create3rdPartyConference() 與第三方系統聯絡 建立會議,並使用 getAuthenticationUrl() 函式 建立第三方系統驗證網址。系統不會在 不過,它們高度依賴第三方系統的詳細資料。

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;
}