サードパーティ会議の作成

<ph type="x-smartling-placeholder"> </ph>

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

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

  1. サードパーティ製の会議システムで会議を作成する際に必要となる Google カレンダーの予定の情報(予定の ID や参加者のリストなど)を取得します。
  2. サードパーティ製の会議サービスに接続し、Google カレンダーの予定情報を使用して新しい会議を作成します。
  3. なんらかの理由で会議の作成リクエストが失敗した場合は、エラー情報を使用して ConferenceError を含む ConferenceData オブジェクトを作成し、返します。それ以外の場合は、次の手順を行います。
    1. 会議の同期を初期化します。
    2. サードパーティ製の会議サービスから返された情報を使用して、新しい ConferenceData オブジェクトを構築して返します。

イベント情報の取得

サードパーティの会議を作成するには、対応する Google カレンダーの予定に関する特定の情報が必要です。必要なイベント情報は、サードパーティ製の会議システムで異なりますが、多くの場合、予定の開始時間、終了時間、概要、参加者リスト、ID が含まれます。

定義した各 onCreateFunction には、カレンダー ID とイベント ID を含む引数が渡されます。これらの ID を使用すると、Google カレンダーの高度なサービスを使用して完全な予定情報を取得できます。

Google カレンダーから予定に会議の詳細情報が追加される可能性があります。この場合、Google カレンダーは onCreateFunction を有効な eventId に渡しますが、その後の Calendar.Events.get() の呼び出しを行うと、イベントが存在しないことを示すエラー レスポンスが返されることがあります。この場合は、プレースホルダ データを使用してサードパーティの会議を作成することをおすすめします。このデータは、次にイベントが同期されるときに置き換えられます。

サードパーティ製会議の作成

onCreateFunction が必要なイベントデータを取得したら、サードパーティの会議システムに接続して会議を作成する必要があります。通常は、サードパーティ製の会議システムでサポートされている API リクエストを作成することで、これを実現します。サードパーティの会議ソリューションのドキュメントを参照して、会議の作成に使用できる API リクエストをご確認ください。

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

会議の作成をリクエストした後に、新しい会議の詳細情報を取得するための追加のリクエストが必要になる場合があります。

会議の同期を初期化する

アドオンによってサードパーティ製システムで正常に会議が作成されたら、同期を有効にして、Google カレンダーの予定の変更が会議に反映されるようにする必要があります。

会議作成後の同期の設定について詳しくは、カレンダーの変更の同期をご覧ください。

会議のデータ レスポンスを作成する

サードパーティ サービスから返された会議情報を使用して、onCreateFunctionConferenceData オブジェクトを構築して返す必要があります。会議データ セクションには、このオブジェクトのコンテンツを記述します。Google カレンダーはこの情報を使用して、開始時にユーザーを会議にリダイレクトします。

ConferenceData オブジェクトを作成する際は、フィールドの長さ、エントリ ポイント URI の形式、エントリ ポイントの許可される組み合わせにいくつかの制限があることに注意してください。たとえば、1 つの ConferenceData に指定できる VIDEO エントリ ポイントは 1 つだけです。この制限は、対応する conferenceData フィールドの Calendar API イベントに記載されている制限と同じですが、ここに記載されているすべての API イベント フィールドが Apps Script で使用できるわけではありません。

エラー処理

場合によっては、サードパーティ製の会議システムから返されたエラーが原因で、会議の作成を完了できないことがあります。そのような場合、アドオンは、ConferenceError の詳細情報を含む ConferenceData オブジェクトを構築して返すことで、エラー状態を確実に処理し、Google カレンダーが適切に動作できるようにします。

ConferenceData オブジェクトを作成してエラーを報告する際に、ConferenceError オブジェクト以外の ConferenceData コンポーネントを含める必要はありません。ConferenceErrors には ConferenceErrorType、エラー メッセージが含まれます。認証の場合は、ユーザーがサードパーティの会議システムにログインできる URL を発行します。

以下に例を示します(関数名には任意の名前を付けることができます)。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;
}