サードパーティの会議を作成する

会議ソリューション スクリプト プロジェクトで定義されている マニフェスト 関連付けられている onCreateFunction があります。アドオンはこの関数を呼び出して、 ユーザーがその会議ソリューションを選択しようとすると、 イベントです。

アドオン マニフェストに記述されている各 onCreateFunction を実装する必要があります。 一般に、これらの関数は次の処理を行う必要があります。

  1. Google カレンダーの予定に関する情報(予定 ID や Chronicle など)を 追加することもできます。 会議を作成します。
  2. サードパーティの会議サービスに接続して新しい会議を作成する Google カレンダーの予定情報を使用してアクセスできます。
  3. なんらかの理由で会議作成リクエストが失敗した場合は、エラーを使用する 返すことができます。 ConferenceData 含まれる ConferenceError。 それ以外の場合は、次の手順を行います。
    1. 会議の同期を初期化します。
    2. サードパーティの会議サービスから返された情報を使用して、 新しい Pod をビルドし、 ConferenceData 渡されます。

イベント情報の取得

サードパーティの会議を作成するには、対応する Google カレンダーの予定が必要です。必要となる正確なイベント情報は、 共有することもできますが、多くの場合、これには イベント開始時刻、終了時刻、概要、参加者リスト、ID。

呼び出すと、定義した各 onCreateFunction に、 には、カレンダーとイベント ID が含まれています。これらの ID を使用して 完全なイベント情報を表示するには、 Google カレンダー拡張サービス

Google カレンダーでは、会議の詳細を予定に追加してから 存在する必要があります。このような場合、Google カレンダーは onCreateFunction に有効な eventId ですが、その後の Calendar.Events.get() の呼び出しは イベントが存在しないことを示すエラー レスポンスが返されます。そのような場合は、 プレースホルダ データを使用して第三者の会議を作成するこのデータは 次回のイベントで 同期されます。

サードパーティの会議を作成する

onCreateFunction は、必要なイベントデータを取得したら、 サードパーティ製会議システムに接続して、会議を作成します。 通常、これを実現するには、 サードパーティ製会議システムです。サードパーティのドキュメントを確認する 作成に使用できる API リクエストを決定するため、 可能です。

Apps Script で外部 API リクエストを行う最も簡単な方法は、 OAuth2 for Apps Script を使用する または Apps Script 用 OAuth1 オープンソース ライブラリです。また、 UrlFetch サービスを使用して外部 API に接続する 承認の詳細を明示的に処理する必要があります。

会議の作成をリクエストした後に、追加の リクエストを使用して新しい会議の詳細を取得できます。

会議の同期を初期化する

アドオンによってサードパーティ製システムで会議が作成されると、 数ステップで有効になります。 同期を実行して、 Google カレンダーの予定が会議に反映されます。

カレンダーの変更内容を同期するをご覧ください。 をご覧ください。

会議データ応答の作成

サードパーティ サービスから返された会議情報を使用して、 次に、onCreateFunction は、 ConferenceData object; 会議データ セクションで、このオブジェクトのコンテンツを記述します。Google カレンダーでは 会議が始まると、この情報を使用してユーザーを会議に誘導します。

ConferenceData のビルド時 使用できる場合、フィールドの長さ、 エントリ ポイントの URI、許可されるエントリ ポイントの組み合わせなどです。たとえば 1 つに VIDEO エントリ ポイントを 1 つだけ含めることができます ConferenceData。これらの制限は、Terraform 構成の 対応する Calendar API の予定conferenceData フィールド(ただし、ここに記載されている一部の API イベント フィールドではありません) Apps Script で使用できます。

エラー処理

次の理由で、会議の作成を完了できないことがあります。 エラーのメッセージが表示されます。次のような場合 エラー状態に対して堅牢に処理する必要があります 返す ConferenceData 含まれる ConferenceError Google カレンダーがそれに応じた動作をするようになります。

エラーを報告するために ConferenceData オブジェクトを作成する場合は、 マニフェスト ファイルとは別に、ConferenceData コンポーネントを ConferenceError オブジェクト。ConferenceErrorsConferenceErrorType, エラー メッセージが表示され、認証の場合は サードパーティ製会議システムにログインできます。

以下は、onCreateFunction の例です( 関数にはどのようなものでもかまいません。アドオン プロジェクトで定義するだけで済みます。 定義できます。

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